|
-
Jun 19th, 2005, 01:20 PM
#1
Thread Starter
Member
PictureBox1_Paint and declaring variables [RESOLVED]
Hi,
I would just like to create a list of points through some algorithm under Private Sub Form1_Load
and then have them displayed with drawellipse(pens.black,x(a),y(a),1,1) under
Private Sub PictureBox1_Paint.
I have the variables x(), y() and 'a' as public singles ontop in the class arena.
And declare them again in Private Sub Form1_Load when I calculate how many points needed x(a),y(a)....
But in the error analysis when the program runs, apparently the variables aren't public enough because they are listing as unfilled.
Am I declaring the variables correctly or is it that
Private Sub PictureBox1_Paint
tries to paint before the number of points are calculated?
Thanks for you's help..
Last edited by stephen weber; Jun 26th, 2005 at 02:29 PM.
Reason: solved
-
Jun 20th, 2005, 04:18 AM
#2
Re: PictureBox1_Paint and declaring variables
You say that you are declaring your variables at the class level and the method level. This means that the local variables in the method are shadowing the class-level variables, i.e. they are not the same variables. In your method, try tesing the values of the variable a and the variable Me.a to see whether this is the case. Sorry if I have misinterpreted the situation but that is what it sounds like. We might need to see some code otherwise.
-
Jun 20th, 2005, 03:41 PM
#3
Thread Starter
Member
Re: PictureBox1_Paint and declaring variables
Ok.. (You got me). That is clearer.. Me.a() as a global..
How about this. I can declare a() at the class level, but at that level I don't yet know the size of the dimension until a calculation in method. I thought I could then initiate my global a() as a(g) where g is my calculated size. I understand you are telling me that I am just creating a local variable a(g) not defining my global a().
So how do I send a list of points to a paint method?
-
Jun 20th, 2005, 07:03 PM
#4
Re: PictureBox1_Paint and declaring variables
You can declare an array variable at the class-level and then set it's length like this:
VB Code:
Private a() As Integer
Private Sub ResetArray()
ReDim Me.a(10)
End Sub
or, given that you haven't actually set a length in the declaration, simply assign a new array to it:
VB Code:
Private a() As Integer
Private Sub ResetArray()
Me.a = New Integer() {1, 2, 3, 4}
End Sub
Edit:
Note that, unless you need to access the array from more than one method, it doesn't need to be class-level and you can just declare a local variable when and where you need it.
-
Jun 26th, 2005, 02:20 PM
#5
Thread Starter
Member
Re: PictureBox1_Paint and declaring variables
Thank you,
I know it took me awhile to reply. I got busy and also read a few books on this. The program works now.
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
|