Results 1 to 18 of 18

Thread: Fast queston

  1. #1
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default Fast queston

    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;

  2. #2
    Join Date
    Nov 2012
    Posts
    2,351
    Mentioned
    55 Post(s)
    Quoted
    603 Post(s)

    Default

    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

  3. #3
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    You can convert the answer to integer with StrToIntDef().

  4. #4
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    You can convert the answer to integer with StrToIntDef().
    didn't work :9
    Code:
    [Error] C:\Simba\Scripts\Guessinggame.simba(10:50): Type mismatch at line 9
    Compiling failed.

  5. #5
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by rjj95 View Post
    didn't work :9
    Code:
    [Error] C:\Simba\Scripts\Guessinggame.simba(10:50): Type mismatch at line 9
    Compiling failed.
    What did you do with it? Post the code.

  6. #6
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    What did you do with it? Post the code.
    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.

  7. #7
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by rjj95 View Post
    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
      WriteIn(IntToStr('Guess));
      end;
    end;
    Procedure  PickNumber;
      begin
      Number := Random(RANDOM_PICK);
      Writeln('
    ' + IntToStr(Round(Number)))
      AskGuess;
    end;
    Begin
    PickNumber;
    end.
    lol...you read a post not by me and thought it's me..


    Quote Originally Posted by DannyRS View Post
    WriteIn(IntToStr(''Guess'));

    I'm not 100% sure i understand your problem though
    See? I didn't post that.
    It throws a type mismatch because Guess is already a string, and not an integer.

  8. #8
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    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.

  9. #9
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by rjj95 View Post
    Yeilds the same result

    Simba Code:
    Writeln(IntToStr(Guess));
    Because you still have this.
    Also if you read StrToIntDef have 2 parameters. Use StrToInt() if you do not want a default value. (which has its consequence as the result being ambiguous if input = 0)

  10. #10
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    Because you still have this.
    Also if you read StrToIntDef have 2 parameters. Use StrToInt() if you do not want a default value. (which has its consequence as the result being ambiguous if input = 0)
    got it thanks!

  11. #11
    Join Date
    Jul 2012
    Posts
    279
    Mentioned
    5 Post(s)
    Quoted
    46 Post(s)

    Default

    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.

  12. #12
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by Wardancer View Post
    you already specified Guess as a string so there is no need to transform it as writeln writes...strings.
    Writeln does not just write strings

  13. #13
    Join Date
    Jul 2012
    Posts
    279
    Mentioned
    5 Post(s)
    Quoted
    46 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    Writeln does not just write strings
    Kept it simple, but I wonder if we could argue that it only writes strings. Some variables just happen to be strings plus other things! =).

  14. #14
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by Wardancer View Post
    Kept it simple, but I wonder if we could argue that it only writes strings. Some variables just happen to be strings plus other things! =).
    Array of variants? It can write that directly as well.
    I'd consider writeln(1) simpler than writeln(IntToStr(1));

  15. #15
    Join Date
    Jul 2012
    Posts
    279
    Mentioned
    5 Post(s)
    Quoted
    46 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    'strings plus other things!'? array of variants? It can write that directly as well.
    I'd consider writeln(1) simpler than writeln(IntToStr(1));
    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.

  16. #16
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by Wardancer View Post
    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.
    huh...i still don't get why you say writeln writes only strings and why variant should be used...

  17. #17
    Join Date
    Jul 2012
    Posts
    279
    Mentioned
    5 Post(s)
    Quoted
    46 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    huh...i still don't get why you say writeln writes only strings and why variant should be used...
    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.

  18. #18
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    huh...i still don't get why you say writeln writes only strings and why variant should be used...

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •