Results 1 to 5 of 5

Thread: How to convert String to Long or Int??

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    6

    How to convert String to Long or Int??

    Hi,
    Can't really convert string to long.. or int.. Pls enlighten me?
    thanks...

    'Serial Number is number value in access database
    Dim StockVerification As New OleDbCommand("SELECT serial_number from stock where serial_number = '" + txbRentalSerial.Text + "'", cnnRental)

    'will prompt 'data mismatch' when executing the program
    Tried using below and cant also...

    Dim mylong As Long
    Dim s As String
    'mylongl = CLng(txbRentalSerial.Text)
    'mylong = System.Convert.ToInt64(txbRentalSerial.Text())

  2. #2
    Junior Member
    Join Date
    Jul 2004
    Location
    Port Huron, Michigan
    Posts
    20
    Dim mylong As Long
    mylong = CLng(txtRentalSerial.Text)
    MsgBox(mylong.ToString())

    That works.... you had some typos in the code you posted. I don't know if that was copied and pasted from your project, if so, that could be your problem. This worked fine for numeric values I entered into the textbox txtRentalSerial.

    Chris

  3. #3
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Exclamation

    Although valid, your code will produce an error balmerch if the user has typed a non-numeric character in the text box.

    You will need to either wrap the code in a TryCatch, or use th Val function on the contents of the text box.
    ~Peter


  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    6
    Thanks Chris...
    What is the difference between msgbox() and messagebox.show()
    i used messagebox.show() will encounter this error...
    "Option string On disallow implicit conversion from long to string"

    Now tat i can conver to mylong... how do i pass it into the txbrentalserial.text..?

    Dim StockVerification As New OleDbCommand("SELECT serial_number from stock where serial_number = '" + txbRentalSerial.Text + "'", cnnRental)

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Use either :
    1-The static method [ Convert.ToXXX )

    or

    2-Long.Parse (xxxx)

Posting Permissions

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



Click Here to Expand Forum to Full Width