Hi, everyone. I hope this is the right place to post for code help.
I recently have been trying to program a bit. I used to do it a lot in the 90s and 80s, but totally stopped. I've been programming mostly in C since the mid 90s when I do anything, but I recently decided to go back to my childhood and try Basic again. I found out about QB64 a few days ago on Twitter , tried it out and here I am.
I'm a text based sort of coder, I don't really like doing stuff with graphics. Remembering a fun project I did in C about 10 years ago where I wrote a parser for a text based game, I decided to try something similar in basic and immediately got stuck. The first step I did is isolate the command word (as I call it) and process that. But it's not working well. The program is super short at this point so I'm including the entire thing here:
res$ = "This is a test."
FOR solved
= 1 TO rescount
IF MID$(res$
, 1, solved
) = CHR$(32) THEN phrase$
= MID$(res$
, 1, solved
): solved
= rescount
- 1
PRINT phrase$;
" is the word."
The output of this program should be "This is the word." The only thing I ever get out of it is " is the word." The IF statement in the For loop doesn't work as best I can tell. I don't think my condition is bad, as if I replace the If statement with PRINT MID$(res$, 1, solved) it prints out res$ incremented by one character each loop, which is what should happen. As best I can tell after a surprisingly large amount of troubleshooting is that it never recognizes a space and the IF condition is never met, despite spaces being in the string.
Why the heck doesn't this work? I've been staring at that code for the past half hour and can't figure out the problem.
Also, as an aside, is there a way to set it to require variable declaration? This project will probably eventually be several hundred lines of code and I'd prefer to not be able to create new variables by accident.