Results 1 to 6 of 6

Thread: Input string was not in a correct format

  1. #1

    Thread Starter
    Junior Member laven1's Avatar
    Join Date
    Mar 2006
    Location
    Georgia, USA
    Posts
    28

    Question Input string was not in a correct format

    Not sure of how to resolve this error... See below...

    VB Code:
    1. Dim btnZero As Integer = 0
    2.     Dim btnOne = 1
    3.     Dim btnTwo = 2
    4.     Dim btnThree = 3
    5.     Dim btnFour = 4
    6.     Dim btnFive = 5
    7.     Dim btnSix = 6
    8.     Dim btnSeven = 7
    9.     Dim btnEight = 8
    10.     Dim btnNine = 9
    11.     Dim intCounter As String = 0
    12.     Dim numberArray() As String
    13.     Dim comboString As String
    14.     Dim myDec As Decimal
    15.  
    16. Private Sub btnDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecimal.Click
    17.  
    18. 'The purpose of the code below is to store button clicks into an array as a
    19. 'string so they can be joined and viewed in a rich text box.  The below button
    20. 'is for the decimal.  I thought I could store it in the array and then convert
    21. 'the string number, including the decimal as a number... so I could do
    22. 'calculations.
    23.  
    24.         ReDim Preserve numberArray(intCounter)
    25.         Dim btnDecimal As String = "."
    26.         numberArray(intCounter) = btnDecimal
    27.         rtbScreen.Text = numberArray(intCounter)
    28.         intCounter = intCounter + 1
    29.         Console.WriteLine("The Decimal button was pressed")
    30.         Console.WriteLine("intCounter =" & intCounter)
    31.         comboString = String.Join("", numberArray)
    32.         Console.WriteLine("Value of comboString =" & comboString)
    33.         myDec = Convert.ToDecimal(comboString) 'Here is my error
    34.         rtbScreen.Text = comboString
    35.  
    36.     End Sub

    Thanks,

    Joe

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Input string was not in a correct format

    Once again, you have conflicting variable types. You declared your counter as a string, when it should be an integer....

    You would probably benefit from turning option explicit on, and option strict on, as these types of things should show in the IDE....

    For instance, When I try just the line "Dim intCounter as String = 0", it wont even let me, because 0 is an integer, and not a string, so the 0 is underlined in blue squigglies...
    Last edited by gigemboy; Mar 20th, 2006 at 01:28 PM.

  3. #3

    Thread Starter
    Junior Member laven1's Avatar
    Join Date
    Mar 2006
    Location
    Georgia, USA
    Posts
    28

    Resolved [Resolved] Re: Input string was not in a correct format

    Thanks, I really am trying here.

    OK, I will try it.

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Input string was not in a correct format

    hehe no problem... have to learn some way, right

  5. #5

    Thread Starter
    Junior Member laven1's Avatar
    Join Date
    Mar 2006
    Location
    Georgia, USA
    Posts
    28

    Resolved Re: Input string was not in a correct format

    Quote Originally Posted by gigemboy
    You would probably benefit from turning option explicit on, and option strict on, as these types of things should show in the IDE....

    For instance, When I try just the line "Dim intCounter as String = 0", it wont even let me, because 0 is an integer, and not a string, so the 0 is underlined in blue squigglies...
    Ah, there we go. That is what I needed. I read this somewhere, but thought it was a default option in the IDE. After looking back in my books I see that it is actually code.

    Thanks!

  6. #6
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Input string was not in a correct format

    You can actually change this in your environment settings to default both of them to "on". In 2003, this was done through Tools > Options > Projects (folder) > VB Defaults, then switching them there...

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