|
-
April 26th, 2007, 03:32 AM
#16
Re: Form1 Error
That didn't help I'm afraid... Thanks Any way.
Any more suggestions?
Thanks in Advance,
Tim
-
April 26th, 2007, 04:45 AM
#17
Re: Form1 Error
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 lines
Code:
Dim changeamount As Integer = amountbox.Text
Dim keypad As Boolean = True
To
Code:
Dim changeamount As Integer
Dim keypad As Boolean
This code is in Form1.
Make sure that you don't assign anything to the variables that are created outside of the functions/subs/properties.
-
April 26th, 2007, 06:02 AM
#18
Re: Form1 Error
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
-
April 26th, 2007, 06:31 AM
#19
Re: Form1 Error
 Originally Posted by PCgeek
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?
-
April 26th, 2007, 11:07 AM
#20
Re: Form1 Error
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:
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 MyBase.New() makes it go through any variables that are declared with values.
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:
Code:
Dim changeamount As Integer = amountbox.Text
But amountbox is not yet created. InitializeComponent() is what creates it.
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:
Code:
Dim changeamount As Integer = amountbox.Text
To:
Code:
Dim changeamount As Integer
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.
Only changing that one line of code allowed it to run for me.
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
|