More Efficient and Fast Way to write this??

gmatriix

Registered User.
Local time
Today, 00:25
Joined
Mar 19, 2007
Messages
365
Hello All,

I have some code here that work pretty well however it is a bit slow. Is there a more efficient and more importantly "Faster" way to write this code.

Take a hit on some performance.

Code:
Dim GColor As Variant
Dim YColor As Variant
Dim RColor As Variant

    Dim BColor10 As Variant
    Dim BColor9 As Variant
    Dim BColor8 As Variant
    Dim BColor7 As Variant
    Dim BColor6 As Variant
    Dim BColor5 As Variant
    Dim BColor4 As Variant
    Dim BColor3 As Variant
    Dim BColor2 As Variant
    Dim BColor1 As Variant

Dim Bar1 As Variant
Dim Bar2 As Variant
Dim Bar3 As Variant
Dim Bar4 As Variant
Dim Bar5 As Variant
Dim Bar6 As Variant
Dim Bar7 As Variant
Dim Bar8 As Variant
Dim Bar9 As Variant
Dim Bar10 As Variant
Dim Bar11 As Variant
Dim Bar12 As Variant
Dim Bar13 As Variant
Dim Bar14 As Variant
Dim Bar15 As Variant

Me.Graph194.Visible = False
DoCmd.Echo False

Bar1 = DLookup("ColorCode", "Keyview", "KeyCounter = 1")
Bar2 = DLookup("ColorCode", "Keyview", "KeyCounter = 2")
Bar3 = DLookup("ColorCode", "Keyview", "KeyCounter = 3")
Bar4 = DLookup("ColorCode", "Keyview", "KeyCounter = 4")
Bar5 = DLookup("ColorCode", "Keyview", "KeyCounter = 5")
Bar6 = DLookup("ColorCode", "Keyview", "KeyCounter = 6")
Bar7 = DLookup("ColorCode", "Keyview", "KeyCounter = 7")
Bar8 = DLookup("ColorCode", "Keyview", "KeyCounter = 8")
Bar9 = DLookup("ColorCode", "Keyview", "KeyCounter = 9")
Bar10 = DLookup("ColorCode", "Keyview", "KeyCounter = 10")
Bar11 = DLookup("ColorCode", "Keyview", "KeyCounter = 11")
Bar12 = DLookup("ColorCode", "Keyview", "KeyCounter = 12")
Bar13 = DLookup("ColorCode", "Keyview", "KeyCounter = 13")
Bar14 = DLookup("ColorCode", "Keyview", "KeyCounter = 14")
Bar15 = DLookup("ColorCode", "Keyview", "KeyCounter = 15")

GColor = RGB(0, 255, 0)
YColor = RGB(255, 153, 51)
RColor = RGB(255, 0, 0)

On Error Resume Next
Me.Graph194.axes(2).MinimumScale = Me.LL - 0.0008
Me.Graph194.axes(2).MaximumScale = Me.UL + 0.0006

    If Bar15 = 1 Then Me.Graph194.SeriesCollection(1).Points(15).Interior.Color = GColor
    If Bar15 = 2 Then Me.Graph194.SeriesCollection(1).Points(15).Interior.Color = YColor
    If Bar15 = 3 Then Me.Graph194.SeriesCollection(1).Points(15).Interior.Color = RColor

If Bar14 = 1 Then Me.Graph194.SeriesCollection(1).Points(14).Interior.Color = GColor
If Bar14 = 2 Then Me.Graph194.SeriesCollection(1).Points(14).Interior.Color = YColor
If Bar14 = 3 Then Me.Graph194.SeriesCollection(1).Points(14).Interior.Color = RColor

    If Bar13 = 1 Then Me.Graph194.SeriesCollection(1).Points(13).Interior.Color = GColor
    If Bar13 = 2 Then Me.Graph194.SeriesCollection(1).Points(13).Interior.Color = YColor
    If Bar13 = 3 Then Me.Graph194.SeriesCollection(1).Points(13).Interior.Color = RColor

If Bar12 = 1 Then Me.Graph194.SeriesCollection(1).Points(12).Interior.Color = GColor
If Bar12 = 2 Then Me.Graph194.SeriesCollection(1).Points(12).Interior.Color = YColor
If Bar12 = 3 Then Me.Graph194.SeriesCollection(1).Points(12).Interior.Color = RColor

    If Bar11 = 1 Then Me.Graph194.SeriesCollection(1).Points(11).Interior.Color = GColor
    If Bar11 = 2 Then Me.Graph194.SeriesCollection(1).Points(11).Interior.Color = YColor
    If Bar11 = 3 Then Me.Graph194.SeriesCollection(1).Points(11).Interior.Color = RColor

If Bar10 = 1 Then Me.Graph194.SeriesCollection(1).Points(10).Interior.Color = GColor
If Bar10 = 2 Then Me.Graph194.SeriesCollection(1).Points(10).Interior.Color = YColor
If Bar10 = 3 Then Me.Graph194.SeriesCollection(1).Points(10).Interior.Color = RColor

    If Bar9 = 1 Then Me.Graph194.SeriesCollection(1).Points(9).Interior.Color = GColor
    If Bar9 = 2 Then Me.Graph194.SeriesCollection(1).Points(9).Interior.Color = YColor
    If Bar9 = 3 Then Me.Graph194.SeriesCollection(1).Points(9).Interior.Color = RColor
    
If Bar8 = 1 Then Me.Graph194.SeriesCollection(1).Points(8).Interior.Color = GColor
If Bar8 = 2 Then Me.Graph194.SeriesCollection(1).Points(8).Interior.Color = YColor
If Bar8 = 3 Then Me.Graph194.SeriesCollection(1).Points(8).Interior.Color = RColor

    If Bar7 = 1 Then Me.Graph194.SeriesCollection(1).Points(7).Interior.Color = GColor
    If Bar7 = 2 Then Me.Graph194.SeriesCollection(1).Points(7).Interior.Color = YColor
    If Bar7 = 3 Then Me.Graph194.SeriesCollection(1).Points(7).Interior.Color = RColor
    
If Bar6 = 1 Then Me.Graph194.SeriesCollection(1).Points(6).Interior.Color = GColor
If Bar6 = 2 Then Me.Graph194.SeriesCollection(1).Points(6).Interior.Color = YColor
If Bar6 = 3 Then Me.Graph194.SeriesCollection(1).Points(6).Interior.Color = RColor

    If Bar5 = 1 Then Me.Graph194.SeriesCollection(1).Points(5).Interior.Color = GColor
    If Bar5 = 2 Then Me.Graph194.SeriesCollection(1).Points(5).Interior.Color = YColor
    If Bar5 = 3 Then Me.Graph194.SeriesCollection(1).Points(5).Interior.Color = RColor
    
If Bar4 = 1 Then Me.Graph194.SeriesCollection(1).Points(4).Interior.Color = GColor
If Bar4 = 2 Then Me.Graph194.SeriesCollection(1).Points(4).Interior.Color = YColor
If Bar4 = 3 Then Me.Graph194.SeriesCollection(1).Points(4).Interior.Color = RColor

    If Bar3 = 1 Then Me.Graph194.SeriesCollection(1).Points(3).Interior.Color = GColor
    If Bar3 = 2 Then Me.Graph194.SeriesCollection(1).Points(3).Interior.Color = YColor
    If Bar3 = 3 Then Me.Graph194.SeriesCollection(1).Points(3).Interior.Color = RColor
    
If Bar2 = 1 Then Me.Graph194.SeriesCollection(1).Points(2).Interior.Color = GColor
If Bar2 = 2 Then Me.Graph194.SeriesCollection(1).Points(2).Interior.Color = YColor
If Bar2 = 3 Then Me.Graph194.SeriesCollection(1).Points(2).Interior.Color = RColor

    If Bar1 = 1 Then Me.Graph194.SeriesCollection(1).Points(1).Interior.Color = GColor
    If Bar1 = 2 Then Me.Graph194.SeriesCollection(1).Points(1).Interior.Color = YColor
    If Bar1 = 3 Then Me.Graph194.SeriesCollection(1).Points(1).Interior.Color = RColor
    
Me.Graph194.Visible = True
DoCmd.Echo True
 
QuitGraph:

Any Ideas?
 
gmatrix, Not sure if this is going to speed it up, but worth a try.. Several DLookUp's tend to be make the process a bit slow..
Code:
Dim GColor, YColor, RColor
Dim iCtr As Integer

GColor = RGB(0, 255, 0)
YColor = RGB(255, 153, 51)
RColor = RGB(255, 0, 0)

On Error Resume Next
Me.Graph194.axes(2).MinimumScale = Me.LL - 0.0008
Me.Graph194.axes(2).MaximumScale = Me.UL + 0.0006

For iCtr = 1 To 15
    Select Case Nz(DLookup("ColorCode", "Keyview", "KeyCounter = " & iCtr), 0)
        Case 1
            Me.Graph194.SeriesCollection(1).Points(iCtr).Interior.Color = GColor
        Case 2
            Me.Graph194.SeriesCollection(1).Points(iCtr).Interior.Color = YColor
        Case 3
            Me.Graph194.SeriesCollection(1).Points(iCtr).Interior.Color = RColor
        Case Else
    End Select
Next

Me.Graph194.Visible = True
DoCmd.Echo True
The above code is the essence of what you are trying to do.. (I guess !!)
 
Your right...those dlookups was doing it.....and it is faster....and doesn't blink quite as bad.....thanks again buddy...
 

Users who are viewing this thread

Back
Top Bottom