That didn't help I'm afraid... Thanks Any way.
Any more suggestions?
Thanks in Advance,
Tim
Printable View
That didn't help I'm afraid... Thanks Any way.
Any more suggestions?
Thanks in Advance,
Tim
Looking at the code carefully, I have seen that you are assigning values to the variables outside of any code block. Which is not a good practice and is not supported by VB.
Do not assign anything to any variables in the declaration part of your code. Change the following two linesToCode:Dim changeamount As Integer = amountbox.Text
Dim keypad As Boolean = True
This code is in Form1.Code:Dim changeamount As Integer
Dim keypad As Boolean
Make sure that you don't assign anything to the variables that are created outside of the functions/subs/properties.
I'm only in year 10 learning this. This assignment is due VERY Soon, i need help with the form1 error.
The previous suggestion didn't help
Thanks,
Tim
Did you try the suggestions mentioned in my previous post?Quote:
Originally Posted by PCgeek
aniskhan's and Shuja Ali's comments highlight and solve your problem.
When the program creates Form1, it goes into the Sub New, which is defined as:
Calling MyBase.New() makes it go through any variables that are declared with values.Code:Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Calling InitializeComponent() creates all the controls for the form.
The fact that they are called in that order means that MyBase.New() executes the line:But amountbox is not yet created. InitializeComponent() is what creates it.Code:Dim changeamount As Integer = amountbox.Text
That's why you're getting the error.
So, if you wanted changeamount to start with the value in that textbox, you'd have to change:
To:Code:Dim changeamount As Integer = amountbox.Text
Then put "changeamount = amountbox.Text" in Sub New, after the InitializeComponent() call. But since that textbox's text property is defaulted to a blank string, that would still give you an error, so just don't set changeamount.Code:Dim changeamount As Integer
Only changing that one line of code allowed it to run for me.