...

View Full Version : Declare Integer



Mitsuki
04-16-2006, 08:18 AM
Hi

I know its silly but answer me





Dim strQuantity As Integer = txtQuantity.Text

^ Is this the right way to declare an integer

vinyl-junkie
04-16-2006, 08:57 AM
That works just fine. :thumbsup:

Mitsuki
04-16-2006, 09:05 AM
But when I click the button I get this :/

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:


Line 11: Dim strDescription As String = txtDesc.Text
Line 12: Dim strStatus As String = lstStatus.SelectedIndex
Line 13: Dim Quantity As Integer = intQuantity.Text
Line 14:
Line 15: If lstType.SelectedIndex = 0 and lstAssetTrack.SelectedIndex = 0 and txtName.Text = "" and txtDesc.Text = "" and lstStatus.SelectedIndex = 0 and intQuantity.Text = "" Then

vinyl-junkie
04-16-2006, 03:58 PM
Sorry, I wasn't thinking. Here's what that statement should look like.


Dim Quantity As Integer = cInt(intQuantity.Text)

Brandoe85
04-16-2006, 07:27 PM
Just a note, you should be doing some validation to ensure that you're actually getting numbers entered, obviously you couldn't convert "test string" into an int.
Alternatively:


Dim Quantity As Integer = CType(intQuantity.Text, Integer)
Dim Quantity As Integer = Integer.Parse(intQuantity.Text)

' or whatever type of int you're using int16...etc
Dim Quantity As Integer = Convert.ToInt32(intQuantity.Text)


Really, take your pick.

handshakeit
04-17-2006, 07:07 AM
use

Dim strQuantity As Integer = Convert.ToInt32(txtQuantity.Text)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum