Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > VB.NET - Converting from a Decimal in a Label's Value to an Integer

Reply
Thread Tools

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

 
 
RogueSpear00 RogueSpear00 is offline
Junior Member
Join Date: Mar 2011
Posts: 1
 
      03-29-2011
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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Value of type Decimal cannot be converted to 1 dimensional array of Decimal Neal Software 0 03-20-2011 03:08 AM
Error: Cannot convert Decimal("0.0000") to Decimal Vitaliy Python 1 05-29-2008 10:36 AM
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why? Gilbert Fine Python 8 08-01-2007 01:58 AM
Decimal to Packed Decimal Conversion in C++ Ven C++ 3 08-01-2006 03:56 PM
Converting a number to percentage or decimal value (Built-in Function) ltamisin ASP General 1 07-14-2005 10:25 AM



Advertisments