Results 1 to 4 of 4

Thread: Grid Problems

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Hi all,

    I'm writing a game in VB which uses a grid. I'm only a beginner at VB so none of my code is fancy.

    I have the grid written, it's 15 x 14 boxes (all Image boxes), so about 200 or more subs in total, all named "x1y1", "x1y2", etc.

    When you click on a box, the co-ord. of that box is saved as a data value called "UnitCoOrd". For example, the value may be x5y3, whatever. Then another sub is loaded, called Movement.

    I want Movement to do several things to that cube, but I don't want to copy and paste a lot of code into 200 or more subs. The first thing I'm trying to do is to get a picture to appear in the cube. I've got it set so it's like this :

    UnitCoOrd.Picture = LoadPicture("C:\ww3\1.bmp")

    Which is for eg., if the box clicked is 9,2:

    x9y2.Picture = LoadPicture("C:\ww3\1.bmp")

    What I want to do is substitute the value UnitCoOrd for that value to load a picture.

    I keep getting errors. How can I get around this ?

    I hope someone understands what I'm trying to do, it's hard to explain, at least as a beginner. =)

    Thanks, cya!

    -Git

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    200... *ARGH*!!!

    Well, ok, ... let's see.... erm,

    First let me tell you that you should not have that much controls on your form. That takes much resources and so slows down everything!
    Next is your names, it's a bad idea to use the name to get the position... Also you have to put the images on the form at design time, otherwise you can create the images when loading the form (only 2 loops, so much faster to do for you).

    well, a little example. Open a new project, add an image box (prolly load a small picture into it), search it's properties for "Index" and set it to 0. Then add this code to form_load:
    Code:
    Dim A as Long
    Dim B as Long
    Dim C as Long
    
    C = 0
    
    For A = 0 to 4
       For B = 0 to 5
         'Load new control
         if C > 0 Then: Load Image1(C)
    
         'Move it into the grid and make it visible
         With Image1(C)
            .Move A*Image1(0).Width, B*Image1(0).Height
            .Visible = True
         End With 
    
         'Increase index
         C = C + 1
       Next
    Next
    And this code to Form_Unload:
    Code:
    Dim A as Long
    
    'Release the memory
    For A = 1 to Image1.Count-1
       Unload Image1(A)
    Next
    Finally start the project

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Oh I forgot to tell you...

    If you add code to the Image1 you created on your Form, it's executed when you click on any image. For example add the following code to Image1_Click() and start it:
    Code:
    MsgBox "You clicked on image #" & CStr( Index ) & "."

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Ok, thanks for your help. =)

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