VB.NET - Converting from a Decimal in a Label's Value to an Integer

Discussion in 'Software' started by RogueSpear00, Mar 29, 2011.

  1. RogueSpear00

    RogueSpear00

    Joined:
    Mar 29, 2011
    Messages:
    1
    Currently using VS2008, VB.NET, SQL.

    I have a FormView from a Data Source that is getting some fields that are stored as Decimals in the SQL Database.

    I am grabbing the field from the FormView as such:

    Code:
    Dim AvgTicket As Label = CType(frmMerchantProfile.FindControl("AvgTicketLabel"), Label)
    I need to take this value, and convert it to an Integer, then send it along to an API. I have the API Calls done, tested and working, but I'm getting an error as when it is getting this value, the API is returning "Must be an Integer" error.

    What I have tried so far:

    Code:
    Dim AvgTicketL As Label = CType(frmMerchantProfile.FindControl("F10Label"), Label)   
    Dim AvgTicket1 As Integer       
    AvgTicket1 = Double.Parse(AvgTicket.Text)   
    Do something with AvgTicket1
    I have also attempted to Round the Value, then convert it and call it - no luck.

    Another user at another forum suggested the following:
    Code:
    Dim testInt as Integer = -1  
    If System.Int32.TryParse(AvgTicketL.Text, testInt) Then       
    ' Do something with testInt - call the API using the value
     Else    
     ' code to execute if the parse fails.    
    ' This could be whatever you need the code to do if the value of AvgTicketL.Text can't be properly parsed into an Int value. 
    End If
     
    Using the above method always results in a similar error.

    Checking the value of AvgTicket1 (Writing it out to a Label or Response.Write) shows "100", where the database value was 100.00. But the API is still getting 100.00, apparently. Any other conversion method that I've attempted states errors that the Label cannot be converted to Integer.

    What are some methods I can successfully convert this value to an integer from a label?
    RogueSpear00, Mar 29, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. anOLDun

    bninary to decimal????

    anOLDun, Mar 9, 2006, in forum: Computer Support
    Replies:
    2
    Views:
    359
    fred-bloggs
    Mar 9, 2006
  2. anOLDun

    binary to decimal

    anOLDun, Mar 9, 2006, in forum: Computer Support
    Replies:
    11
    Views:
    800
    Leythos
    Mar 11, 2006
  3. arianne75

    how to round off decimal point

    arianne75, Jun 8, 2007, in forum: General Computer Support
    Replies:
    0
    Views:
    1,027
    arianne75
    Jun 8, 2007
  4. Paul Ashworth

    Hexadecimal to Decimal

    Paul Ashworth, Jan 5, 2005, in forum: A+ Certification
    Replies:
    1
    Views:
    440
    the_angry_monkey
    Jan 5, 2005
  5. Neal
    Replies:
    0
    Views:
    1,452
Loading...

Share This Page