Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Declare Integer

  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Declare Integer

    Hi

    I know its silly but answer me




    Code:
    Dim strQuantity As Integer = txtQuantity.Text
    ^ Is this the right way to declare an integer

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,090
    Thanks
    2
    Thanked 23 Times in 23 Posts
    That works just fine.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    New Coder
    Join Date
    Apr 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,090
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Sorry, I wasn't thinking. Here's what that statement should look like.

    Code:
    Dim Quantity As Integer = cInt(intQuantity.Text)
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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:
    Code:
    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.
    Last edited by Brandoe85; 04-16-2006 at 07:37 PM.

  • #6
    New Coder
    Join Date
    Oct 2005
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts
    use

    Dim strQuantity As Integer = Convert.ToInt32(txtQuantity.Text)
    warm Regards
    Abhishek Goel
    Software Developer at Handdshakeit (Handshake Infotech Pvt. Ltd)
    --------------------------------------------------
    ActiveX HTML Editor control


  •  

    Posting Permissions

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