Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string variable question
#1
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
Reply
#2
If I remember there is no way around this.

But try this
Code:
INPUT firstname$
INPUT lastname$
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
'Course there's a way around it.
Code:
LINE INPUT var$
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#4
Thanks Zack. I was looking up string variables instead of input trying to find the answer.
Reply
#5
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.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#6
DUH! I totally forgot about LINE INPUT.... *stabs random person*
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#7
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?
Reply
#8
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.
I'd knock on wood, but my desk is particle board.
Reply
#9
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.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#10
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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)