Qbasicnews.com

Full Version: string variable question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
If you are inputting a string variable and it contains a "," I get the redo from start message. How do you get around this.

ex

input a$
-input tim,tom
then get the redo from start message
If I remember there is no way around this.

But try this
Code:
INPUT firstname$
INPUT lastname$
'Course there's a way around it.
Code:
LINE INPUT var$
Thanks Zack. I was looking up string variables instead of input trying to find the answer.
Further info:
INPUT allows more than one variable in the list.
Code:
INPUT Var1$,Var2$
To enter a value into Var1$, and then Var2$, you must do this (sample of a the above code):
Code:
? ValueOfVar1,ValueOfVar2[ENTER]



Press any key to continue...
See? The "Redo from start" message just means that you've entered more values than the INPUT statement asked for, or that you entered a string value into a numeric variable - hence the error. LINE INPUT allows only one variable in the list, so it can accept commas.
DUH! I totally forgot about LINE INPUT.... *stabs random person*
I may as well post aother question at the bottom here...

How do you get around having to define a length for a string variable in a type group?? its really annoying!

Example:
[syntax="qbasic"]TYPE thistype
a as integer
b as single
c as string
END TYPE[/syntax]
But this DOESNT work!! QB says you have to define a length for the string!

Code:
c as string * 100

But what if I dont want to? Normally you arent forced to define a string length... so what can I do to bypass this... if it is possible?
In QB4.5...you can't get around it. I'm not sure about later QB versions though...I've never even attempted to use variable length strings in a TYPE because that defeats TYPE's purpose.
Well, maybe it was because TYPEs were once really only used for record templates for random-access files? And of course, for that you need to specify a length.
Quote:I've never even attempted to use variable length strings in a TYPE because that defeats TYPE's purpose.

Why? TYPE is useful for so many things! for example - I have an array storing information about the NPCs in my RPG demo. I want to store the X and Y coords, some other data such as the skin type, and what the NPC will say when you talk to him/her. meaning I want to encompass this in a single array using TYPE. But I cant do this. instead I have to use a seperate array just for the NPCtalk$ string. Annoying. Dont you think?
Pages: 1 2