Input string was not in a correct format
Not sure of how to resolve this error... See below...
VB Code:
Dim btnZero As Integer = 0
Dim btnOne = 1
Dim btnTwo = 2
Dim btnThree = 3
Dim btnFour = 4
Dim btnFive = 5
Dim btnSix = 6
Dim btnSeven = 7
Dim btnEight = 8
Dim btnNine = 9
Dim intCounter As String = 0
Dim numberArray() As String
Dim comboString As String
Dim myDec As Decimal
Private Sub btnDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecimal.Click
'The purpose of the code below is to store button clicks into an array as a
'string so they can be joined and viewed in a rich text box. The below button
'is for the decimal. I thought I could store it in the array and then convert
'the string number, including the decimal as a number... so I could do
'calculations.
ReDim Preserve numberArray(intCounter)
Dim btnDecimal As String = "."
numberArray(intCounter) = btnDecimal
rtbScreen.Text = numberArray(intCounter)
intCounter = intCounter + 1
Console.WriteLine("The Decimal button was pressed")
Console.WriteLine("intCounter =" & intCounter)
comboString = String.Join("", numberArray)
Console.WriteLine("Value of comboString =" & comboString)
myDec = Convert.ToDecimal(comboString) 'Here is my error
rtbScreen.Text = comboString
End Sub
Thanks,
Joe
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...
[Resolved] Re: Input string was not in a correct format
Thanks, I really am trying here. :blush:
OK, I will try it.
Re: Input string was not in a correct format
hehe no problem... have to learn some way, right :)
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! :)
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...