Author Topic: Test this and chat with me  (Read 5164 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Test this and chat with me
« Reply #15 on: November 10, 2020, 06:30:00 pm »
Server back down again.  This version seemed to work as intended, except it ate one or two of our letters from folks names.  Go figure!  All I can say is it's probably an internet chat tax at work!  Dern overreaching government!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: Test this and chat with me
« Reply #16 on: November 11, 2020, 12:08:32 pm »
With me, the program finally hangs up at line 26.

Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Test this and chat with me
« Reply #17 on: November 11, 2020, 12:20:30 pm »
With me, the program finally hangs up at line 26.

The server is back down again.  It passed the tests I was wanting to run with it, so I’ve closed it for now, once again.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Test this and chat with me
« Reply #18 on: November 16, 2020, 02:03:47 am »
 

 IF LEN(k$) THEN
???

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Test this and chat with me
« Reply #19 on: November 16, 2020, 02:56:49 am »
 IF LEN(k$) THEN
        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
            mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        ELSE
            IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$
        END IF
    END IF
******************
'or try

 IF LEN(k$) = 1 THEN

        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
        mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        END IF

        IF ASC(k$) > 31 and  ASC(k$) < 127 THEN mymessage$ = mymessage$ + k$
       
END IF

****
« Last Edit: November 16, 2020, 03:58:27 am by NOVARSEG »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Test this and chat with me
« Reply #20 on: November 16, 2020, 03:03:47 am »
IF LEN(k$) THEN...

The above line is a boolean logic statement.  It’s basically equivalent to:  IF LEN(k$) <> 0 THEN...
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Test this and chat with me
« Reply #21 on: November 16, 2020, 03:05:39 am »
OK

check my other post  there was an END IF out of place.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Test this and chat with me
« Reply #22 on: November 16, 2020, 04:24:11 pm »
If code was
****
IF LEN(k$) THEN
        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
            mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
       
            IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$
        END IF
    END IF
****
'then the condition in line ****IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$****
can't ever be true

'however:
****
 IF LEN(k$) THEN
        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
            mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        ELSE
            IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$
        END IF
    END IF
****

The ELSE keyword seems to make the code work?? but the following code
****
 IF LEN(k$) = 1 THEN

        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
        mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        END IF

        IF ASC(k$) > 31 and  ASC(k$) < 127 THEN mymessage$ = mymessage$ + k$
       
END IF
****

eliminates the ELSE with a simple rearrangement of an  END IF

The ASC  value is less than 127. Don't know what might happen if characters 127 to 255 are sent.

INKEY$ return a single character so **** IF LEN(k$) = 1 THEN****  should be OK
« Last Edit: November 16, 2020, 04:51:20 pm by NOVARSEG »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Test this and chat with me
« Reply #23 on: November 16, 2020, 06:04:16 pm »
Let me break the snippet down so you can understand what it’s doing.

 IF LEN(k$) THEN   <— This checks to see if we have a keypress

IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN.  <— This checks to see if the key pressed was the BACKSPACE key, and if we have a string of any size

mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1). <— Here, if we have a string, and hit backspace, we erase the last character in that string.

ELSE. <— else we have a key pressed, and it’s not the backspace key, or we don’t have a existing string for mymessage$

IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$ <— This basically says if the key is CHR$(32) or higher, add it to our string, as long as it’s not a control key like the 2-digit arrow keys.
       
END IF. <— To end the IF...ELSE...block to check for backspace
   
END IF.  <— To end the check for key presses.



So basically, we check for a keypress.  If backspace is pressed, we erase the last character from our string.  Otherwise, as long as it’s not a control key, we add it to our string.

That’s what the above does for us.
« Last Edit: November 16, 2020, 06:07:21 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Test this and chat with me
« Reply #24 on: November 16, 2020, 06:51:52 pm »
Thankyou SMcNeill

OK the following code should do the same thing, without the ELSE

*****
IF LEN(k$) =1 THEN   

        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
        mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        END IF

        IF ASC(k$) > 31 and  ASC(k$) < 127 THEN mymessage$ = mymessage$ + k$
       
END IF
****

What is the maximum string length that can be sent with your code so far?

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Test this and chat with me
« Reply #25 on: November 16, 2020, 07:16:07 pm »
  .
« Last Edit: November 16, 2020, 07:22:13 pm by NOVARSEG »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Test this and chat with me
« Reply #26 on: November 16, 2020, 08:27:30 pm »
Thankyou SMcNeill

OK the following code should do the same thing, without the ELSE

*****
IF LEN(k$) =1 THEN   

        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
        mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        END IF

        IF ASC(k$) > 31 and  ASC(k$) < 127 THEN mymessage$ = mymessage$ + k$
       
END IF
****

What is the maximum string length that can be sent with your code so far?

String limit at the moment is 255 bytes at a time, but you can send and append multiple strings together, if needed.  The program here was really nothing more than a brief test to check my port forwarding and firewall exceptions, to make certain that data would flow both in and out to my PC from the external networks (such as the internet, or someone else's remote connection).

What you have should basically do the same thing, with one minor exception:

IF ASC(k$) > 31 and  ASC(k$) < 127 THEN mymessage$ = mymessage$ + k$  <-- With this line here, you eliminate extended ASCII characters such as the accented letters.  The original basically just checked for ASC(32) and higher; without the restriction on the extended-ASCII codes.

But, that's the beauty of programming -- there's a million different ways to produce the same effect.  You just need to sort out which one suits your style and is the easiest for you to follow.

Another, even simpler solution, is this one:

   
SELECT CASE k$
    CASE CHR$(8): mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
    CASE CHR$(32) TO CHR$(255): mymessage$ = mymessage$ + k$       
END IF
       
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Test this and chat with me
« Reply #27 on: November 16, 2020, 08:50:45 pm »
OK   did the*** ASC(k$) < 127*** for simple keyboard input.

Is it possible to use all the characters  to send a file?

What happens if characters <32 are sent?
« Last Edit: November 16, 2020, 08:57:02 pm by NOVARSEG »