Results 1 to 12 of 12

Thread: 50x50 grid problems!

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    7

    Re: 50x50 grid problems!

    Ok it works well, but....its far too slow i need it to be alot faster and i just dont have the know how to make it so, is there some way i can generate the whole grid at once.

    The program i am making is running as a model over 50 - 100 - 150 years and updating the colours to show what is present in that grid square at that current time. At the moment it takes 3 minutes to generate the colours in the grid for just 1 year so you can imagine how long it will take for 50 years :S

    any tips? the code atm is...

    Code:
    For X = 1 To Sizer                          ' Populate the Grid
        For Y = 1 To Sizer
        
                If a(X, Y, 1) = 0 Then
                
                    MSFlexGrid1.Col = X
                    MSFlexGrid1.Row = Y
                    
                    MSFlexGrid1.CellBackColor = vbYellow
                End If
                
                If a(X, Y, 1) = 1 Then
                    
                    MSFlexGrid1.Col = X
                    MSFlexGrid1.Row = Y
                    
                    MSFlexGrid1.CellBackColor = vbGreen
                End If
                
                If a(X, Y, 1) = 2 Then
                    MSFlexGrid1.Col = X
                    MSFlexGrid1.Row = Y
                    MSFlexGrid1.CellBackColor = vbRed
                End If
                
        Next Y
    Next X
    thanks in advance.

    Johno

    p.s if anyone knows what it is im designing a Spatially Explicit Model.

  2. #2
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: 50x50 grid problems!

    Individually defining cell colors does take time. Although 3 minutes does seem awfully long.

    You might shorten the name of your FlexGrid and not use the default name. (EG name your control FG instead of MSFlexGrid1. You might also use Select Case instead of multiple If-then statements. Don't reset the column value every time. You only need to set it when X changes. You might also use color codes directly instead of having VB having to look up the value.

    Code:
    For X = 1 To Sizer                          ' Populate the Grid
       FG.Col=X 
       For Y = 1 To Sizer
          FG.Row=Y
          Select Case  a(X, Y, 1)
                  Case 0   
                       FG.CellBackColor = &HFFFF&   'yellow
                  Case 1
                       FG.CellBackColor = &HFF00&   'green
                  Case 2
                       FG.CellBackColor = &HFF&   'red
             End select
        Next Y
    Next X

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: 50x50 grid problems!

    See if this is appreciably faster

    Code:
    With MSFlexGrid1
    For X = 1 To Sizer                          ' Populate the Grid
        For Y = 1 To Sizer
        
                If a(X, Y, 1) = 0 Then
                
                    .Col = X
                    .Row = Y
                    
                    .CellBackColor = vbYellow
                End If
                
                If a(X, Y, 1) = 1 Then
                    
                    .Col = X
                    .Row = Y
                    
                    .CellBackColor = vbGreen
                End If
                
                If a(X, Y, 1) = 2 Then
                    .Col = X
                    .Row = Y
                    .CellBackColor = vbRed
                End If
                
        Next Y
    Next X
    And BTW

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