Results 1 to 5 of 5

Thread: PictureBox1_Paint and declaring variables [RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    palo alto california
    Posts
    45

    Resolved 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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    palo alto california
    Posts
    45

    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?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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:
    1. Private a() As Integer
    2.  
    3.     Private Sub ResetArray()
    4.         ReDim Me.a(10)
    5.     End Sub
    or, given that you haven't actually set a length in the declaration, simply assign a new array to it:
    VB Code:
    1. Private a() As Integer
    2.  
    3.     Private Sub ResetArray()
    4.         Me.a = New Integer() {1, 2, 3, 4}
    5.     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.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    palo alto california
    Posts
    45

    Resolved 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
  •  



Click Here to Expand Forum to Full Width