none
TextWindow.ReadNumber Function RRS feed

  • Question

  •  When I enter the below code and just hit enter the routine comes back and says that the value entered is the number 0.  I would think that if all you do is hit enter that the value that would be put into (a) would just be an Enter character which would be a 14 decimal value.  That way if you had a list of numbers of which 0 would be a legitimate value that you could enter it and if you needed to enter an empty value which would just be an enter that you could do too.  Currently this can't be done because just hitting enter returns the number 0.  My question is:  "Is this a bug or not"?

    TextWindow.WriteLine("Enter Number")
    a=TextWindow.ReadNumber()
    If Text.GetCharacter(48)= text.GetSubText(a,0,1) then
      TextWindow.writeline("It Does")
    endif
    TextWindow.WriteLine("This is a "+a)
    Monday, February 23, 2009 9:40 PM
    Answerer

Answers

  • In your program, you're trying to compare two strings.  Try this instead:

    a=0

    If 47 < Text.GetCharacterCode(Text.GetSubText(a,0,1)) Then
      TextWindow.WriteLine("It is")
    Else
      TextWindow.WriteLine("This is wrong: ")
    EndIf

    In this case, I'm converting the text to its actual code and then comparing the numbers.

    • Proposed as answer by Davey-Wavey Thursday, November 12, 2009 12:25 AM
    • Marked as answer by gungan37Editor Sunday, October 21, 2012 7:18 PM
    Tuesday, February 24, 2009 2:08 AM
    Moderator

All replies

  • jricestk,

    This is the way the operation was designed to work.  The API is expected to return when the user hits ENTER, signalling completion of typing. 
    Monday, February 23, 2009 11:21 PM
    Moderator
  • Vijaye,

    Maybe I didn't explain this very well.  Let's say I have a list of numbers that I just want to enter using the readnumber function and output them.  In that list I have some 0 entries and some blank entries.  Like this:

    0
    1
    2

    3
    4
    5
    0

    6
    7
    8
    9

    I need to output this with the blanks being in their current position.  I can't do that with the ReadNumber function.  It turns a blank into the number 0.  That just doesn't seem right to me.  Your thoughts?

    Thanks,

    JR
    Tuesday, February 24, 2009 1:12 AM
    Answerer
  • Aha... I see. 

    Your scenario is you want to allow people to either type a number or an empty string.  This is a little different from what the ReadNumber operation is.  Have you tried the TextWindow.Read operation?  That will do what you expect, although it allows users to type more than just numbers.

    Tuesday, February 24, 2009 1:20 AM
    Moderator
  • Vijaye,

    Yes, I did try that and I was going to manipulate the text around to ensue I had numbers, but I got into this other issue.

    a=0

    If Text.GetCharacter(47) < text.GetSubText(a,0,1) Then
      TextWindow.WriteLine("It is")
    Else
      TextWindow.WriteLine("This is wrong: ")
    EndIf

    The variable a should evaluate to 48 decimal or 30 hex.  The above code doesn't give the right answer as (47) is less than (48).  So, it should say It is, but it doesn't do it right.  Here again I don't why, but to me it doesn't seem right.

    Tuesday, February 24, 2009 1:47 AM
    Answerer
  • In your program, you're trying to compare two strings.  Try this instead:

    a=0

    If 47 < Text.GetCharacterCode(Text.GetSubText(a,0,1)) Then
      TextWindow.WriteLine("It is")
    Else
      TextWindow.WriteLine("This is wrong: ")
    EndIf

    In this case, I'm converting the text to its actual code and then comparing the numbers.

    • Proposed as answer by Davey-Wavey Thursday, November 12, 2009 12:25 AM
    • Marked as answer by gungan37Editor Sunday, October 21, 2012 7:18 PM
    Tuesday, February 24, 2009 2:08 AM
    Moderator