|
-
Mar 20th, 2006, 01:07 PM
#1
Thread Starter
Junior Member
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
-
Mar 20th, 2006, 01:24 PM
#2
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.
-
Mar 20th, 2006, 01:29 PM
#3
Thread Starter
Junior Member
[Resolved] Re: Input string was not in a correct format
Thanks, I really am trying here. 
OK, I will try it.
-
Mar 20th, 2006, 01:31 PM
#4
Re: Input string was not in a correct format
hehe no problem... have to learn some way, right
-
Mar 20th, 2006, 01:43 PM
#5
Thread Starter
Junior Member
Re: Input string was not in a correct format
 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!
-
Mar 20th, 2006, 03:52 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|