|
-
Nov 4th, 2007, 07:14 AM
#1
Thread Starter
New Member
Re: 50x50 grid problems!
thanks ill give it a shot now, any other suggestions are welcome
-
Nov 4th, 2007, 09:50 AM
#2
Thread Starter
New Member
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.
-
Nov 4th, 2007, 11:06 AM
#3
Hyperactive Member
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
-
Nov 4th, 2007, 01:13 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|