How do I convert a string to an integer

Discussion in 'Questions (Windows Mobile)' started by dahljam, Oct 12, 2008.

  1. dahljam

    dahljam New Member Licensed User

    I am sure this is about the simplest question possible for b4ppc. I can't find in math or strings help, how to do this (string to number). I want to convert a string eg. "21.6" to an array integer (216).

    Qbasic had a command val().

    Jim Dahlquist
    Delete this thread
  2. ceaser

    ceaser Active Member Licensed User


    NSBasic also had a "val()" command. But how about the following:

    Dim A

    End Sub

    Does your string actually have the inverted commas? If so get rid of them and format it.

  3. dahljam

    dahljam New Member Licensed User

    Hi Ceaser

    I don't think the sub does it. I have a string, and I want an int16.
    The string "21.6" then becomes the int16 216. I don't thin I can put
    string types into an integer array.

    The decimal point can easily be eliminated from the string but I put it
    there in case a command may also handles that.

  4. Erel

    Erel Administrator Staff Member Licensed User

    Basic4ppc automatically converts strings and numbers (floating point numbers) as needed.
    If you want to convert a value to an integer you can use the Round keyword.
    If you just want to remove the decimal point:
    x = StrReplace(x,".","")
  5. dahljam

    dahljam New Member Licensed User

    Ok. Now I get it

    It seems that the compiler handles it.

    If I assign int16 matrix(0,0)=20.6 and then place matrix(0,0) in a text box, I get "20".

    Whereas if I assign int16 matrix(0,0)=20.6*10, and place matrix(0,0) in a text box, I get "206", and if I place matrix(0,0)/10 in the text box, I get "20.6".

    I haven't seen that before. I would expect errors. So I just needed the nerve to try it.

    Very nice.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice