String to Int ???

Discussion in 'Questions' started by jnbarban, May 19, 2011.

  1. jnbarban

    jnbarban Member Licensed User

    Do you Know how to do that :

    Code:
    if MyTextBox.text > 0  then
    ...
    end if
    ( MyTextBox.text = "1234")

    i've got this error : " NumberFormatException"

    It is not possible to do somthing like cint(MyTextBox.text) in order to get me a Integer of my text value ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Your code should work, assuming that the string is indeed a number. Make sure that there are no extra spaces in the string.

    You can use IsNumber to check if the string can be parsed as a number.
     
  3. jnbarban

    jnbarban Member Licensed User

    ok...thanks
     
  4. vangogh

    vangogh Member Licensed User

    to "bypass" a null string, I always use

    "0" & MyTextBox.text > 0

    so it the textbox is empty, this gives

    "0" & "" = 0

    if it is "1234" -> "01234" > 0

    it works :sign0137:
     
  5. fabero

    fabero Member Licensed User

    Can someone explain more a bit? I've the same problem.. :BangHead::BangHead:
     
  6. vangogh

    vangogh Member Licensed User

    simply use the debugger and try my suggestion step by step... it works :cool:

    my post isn't a problem but a workaround :sign0060:
     
  7. NeoTechni

    NeoTechni Well-Known Member Licensed User

    Let's say the user enters nothing in the text box

    Since you're checking 0 & textbox.text, it will read "0" which is a number, instead of crashing.

    You can also just use IsNumber () to check if it's valid first
     
    Last edited: May 22, 2011

Share This Page

Loading...