OnClick event function question

InDeSkize

Registered User.
Local time
Today, 01:24
Joined
Jan 20, 2009
Messages
11
Hey Everyone,

I have a form for scoring where the user would click on a text box to make the value jump by 0.5 points. I have the code working from the Sub, but I'd like to know how to make this a function and how to call the function. Otherwise I'd need to repeat the code for each text box.

Here's the code I have working. [1X1] is the text box, FRM_AddSubtract is a frame with a + and - toggle.

----------------------------------------

Private Sub Ctl1x1_Click()
If IsNull([1x1]) Or [1x1] = "" Then
If FRM_AddSubtract.Value = 1 Then
[1x1] = "0.5"
ElseIf FRM_AddSubtract.Value = 2 Then
End If
Else
If FRM_AddSubtract.Value = 1 Then
[1x1] = [1x1] + 0.5
ElseIf FRM_AddSubtract.Value = 2 Then
If [1x1] = 0.5 Then
[1x1] = ""
Else
[1x1] = [1x1] - 0.5
End If
End If
End If
End Sub
 
In the sub, use a name as a standin for any textbox. In other words, stop using the name "1x1" in the code - just use "txt"

private sub processTextbox(txt as TextBox)
'all that code here

end sub

And then call it like this

Private Sub Ctl1x1_Click()
processTextbox [1x1]
end sub
 
That worked perfectly for me. Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom