I am using input querey to ask for a value, how do i made it ask for a integer rather then a string? The code I am using:
Simba Code:Procedure AskGuess;
begin
If (InputQuery('Guess number', 'Number', Guess)) Then
begin
writeln(Guess);
end;
end;
I am using input querey to ask for a value, how do i made it ask for a integer rather then a string? The code I am using:
Simba Code:Procedure AskGuess;
begin
If (InputQuery('Guess number', 'Number', Guess)) Then
begin
writeln(Guess);
end;
end;
WriteIn(IntToStr(''Guess'));
I'm not 100% sure i understand your problem though
Programming is like trying keep a wall of shifting sand up, you fix one thing but somewhere else starts crumbling
You can convert the answer to integer with StrToIntDef().
Simba Code:Program Game;
const
RANDOM_PICK = 100;
var
Number,Tries,GuessInt:Integer;
Response,Guess:String;
Procedure AskGuess;
begin
If (InputQuery('Guess number', 'Number', Guess)) Then
begin
Writeln(IntToStr(Guess));
end;
end;
Procedure PickNumber;
begin
Number := Random(RANDOM_PICK);
Writeln('' + IntToStr(Round(Number)))
AskGuess;
end;
Begin
PickNumber;
end.
Yeilds the same result
Simba Code:Program Game;
const
RANDOM_PICK = 100;
var
Number,Tries,GuessInt:Integer;
Response,Guess:String;
Procedure AskGuess;
begin
If (InputQuery('Guess number', 'Number', Guess)) Then
begin
Writeln(IntToStr(Guess));
end;
end;
Procedure PickNumber;
begin
Number := Random(RANDOM_PICK);
Writeln('' + StrToIntDef(Guess);
AskGuess;
end;
Begin
PickNumber;
end.
Erm... IntToStr stands for Integer to String. In other words, it converts an integer value into a string one. There is no need to (actually you can't) use IntToStr on a string. You'll get a type mismatch error. On this case, you already specified Guess as a string so there is no need to transform it as writeln writes...strings.
My point was much more rhetoric than technical, seeing variant as "integers + strings", therefore it isn't virtually incorrect to say that writeln only writes strings. Awful joke coming from a sleep deprived person.
That being said, you're totally right that the OP should use variant instead of string or integer.
The part about string is mostly rhetorical and brings nothing to this thread. Not worth trying to explain it as it was just a joke to start with and I'd rather not confuse anyone with an argument that, at the end of the day, doesn't help.
As for the suggestion regarding variant, my understanding is that it converts the variable to the type needed for the particular use. I might be wrong though as you suggested using an array of variant and I never played around with this type of variable before.
He's partially correct. Writeln uses implicit conversion to string I think?
Simba Code:writeln(int); //probably converts that int to a string first then prints.
I don't think there is any function out there, in any language, that can just print the string/literal equivalent of something without some sort of lexical casting somewhere along the lines.
It's probably why Implicit concatenation doesn't happen:
Simba Code:writeln("Foo: " + someint); //compile time error.
but explicit does:
Simba Code:writeln("Foo: " + ToStr(someint));
Some languages have explicit concat or aren't type strict.
Last edited by Brandon; 12-20-2012 at 05:03 AM.
I am Ggzz..
Hackintosher
There are currently 1 users browsing this thread. (0 members and 1 guests)