Global Variables

Gav White

Registered User.
Local time
Today, 19:17
Joined
Jul 16, 2003
Messages
12
Hi all,

Ive written a function which is supposed to remember a high value which is passed to it, and then to use it to compare certain states indicating whether a column is hidden or not. The problem is that the global variable which is supposed to store the value during the duration of the procedure loses its value for no reason what-so-ever...

Any suggestions on how i can store the value indefinatley would be crackin...

Cheers
 
What code do you have thus far?
 
Here you go...


Function colhide(state As Integer) 'state passed from procs when event occurs

'state = 1 : the code passed from sub form events - current, mousemove, click and dbl click
'state = 2: the code passed from leakform when check data button event is activated
'State = 3: the code passed from leakform when endcheck button event is activated
'CHECKMODE 1 = NO LONGER IN CHECK DATA MODE on the form
'CHECKMODE 2 = CURRENTLY IN CHECK DATA MODE on the form


If (state = 3) Then 'If the End Check Button is Clicked
checkmode = 1 'reset checkmode
state = 1 'reset state
Else
If (state = 2) Then 'When the Check Data Button is Clicked
checkmode = 2 'flag checkmaode as 2 - this indicates that the system is in _
check data mode
state = 1
Else
If (state = 1) And (checkmode < 2) Then 'the new input is 1 and the check _
button has not been clicked
checkmode = 1 ' reset
state = 1
End If

End If
End If

If (state = 1) And (checkmode = 2) Then 'when form events occur during _
check data mode...
Me![Problem].ColumnHidden = False '...show hidden columns
Me![Sign].ColumnHidden = False
Else
If (state = 1) And (checkmode = 1) Then 'when sub form events occur _
outside of check data mode...
Me![Problem].ColumnHidden = True '...hide columns
Me![Sign].ColumnHidden = True
End If
End If
Me![Updates].ColumnHidden = True 'always hidden

End Function
 
You do realise that a function should return a value?

Your function is called colhide and should therefore return, in this case, a variant value called colhide.

If you are just performing an operation, then consider changing it to a Sub.

What value is supposed to be remembered?

As a further consideration, rather than the IF state=1 else if state=2 etc, try using a SELECT CASE statement - it makes it moe legible.
 
When the checkmode (C) is set to 2, this indicates that the user is in check data mode on the form. The value is supposed to be remembered so that the function can compare it to the constant inputs (state) from events on the subform, which are passed as 1.

Therefore

S = 1 C = 1 = Hidden
S = 1 C = 2 = Visible

The thing is that it does work for the most part, but only after resetting the routine in checkdata mode...
 
Still, I can't actually look at your immediate code to see what's wrong but YOU can.

I've tidied it up, though.

Code:
Function colhide(State As Integer)
   
    Select Case State
        Case Is = 3
            CheckMode = 1
            State = 1
        Case Is = 2
            CheckMode = 2
            State = 1
        Case Is = 1
            If CheckMode < 2 Then CheckMode = 1
    End Select
    
    If State = 1 Then
        If CheckMode = 2 Then
            Me![Problem].ColumnHidden = False
            Me![Sign].ColumnHidden = False
        Else
            Me![Problem].ColumnHidden = True
            Me![Sign].ColumnHidden = True
        End If
    End If
    
    Me![Updates].ColumnHidden = True

End Function

Use the debug window, put checkpoints on each line and follow the code through to find where the result is going off-skew.
 
Thanks for the advice, and an A+ Thanks for the tidied up code, Ill trace it through and see where its going wrong.


Cheers...
 

Users who are viewing this thread

Back
Top Bottom