Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

split code between events?

Status
Not open for further replies.

knownote

Technical User
Feb 29, 2004
98
US
How do you split code between events?
Specifically, activate InputBox before the on timer event fires. Should timer interval initially be set at 0 or 250? Also, which events work in conjunction with On Timer? Double-clicking on a label doesn't seem to activate the on timer (although, not being a programmer, my attempt was wrong). Thanks.
John

----Code

Private Sub lblScroll_DblClick(Cancel As Integer)
Static strMsg As String, intLet As Integer, intLen As Integer
Dim strTmp As String
Dim strChng As Variant
Const TXTLEN = 90

If Len(strMsg) = 0 Then
strChng = InputBox("Create scrolling message.", "Create scrolling message")
strMsg = Space(TXTLEN) & strChng ' & vbCrLf _
' & "www. .com/ " & Space(TXTLEN)
intLen = Len(strMsg)
End If
intLet = intLet + 1
If intLet > intLen Then intLet = 1
strTmp = Mid(strMsg, intLet, TXTLEN)
Me.lblScroll.Caption = strTmp
Me.lblScroll.ForeColor = (IIf(.ForeColor = vbBlue, vbBlack, vbBlue))
If Me.TimerInterval = 0 Then
Me.TimerInterval = 200
End If

End Sub

 
The only timer is the form timer. If you have the interval initially set to 0, the timer is off. You can set the interval in the dblclick event like you are doing, but the timer code runs in the form_timer() event. See example in microsoft help files or search this forum for timer.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Do you maybe want the sleep function that causes your code to pause for a specific period of time?

Sleep(500)

The above will pause for half a second (500 ms)
 
Thanks for both responses, traingamer and lameid (form timer interval; sleep function). I finally synchronized the initial Timer Interval, lblScroll_DblClick, and Form_Timer.

----Code
Timer Interval = 0 (properties)

Private Sub lblScroll_DblClick(Cancel As Integer)
If Me.TimerInterval = 0 Then
Me.TimerInterval = 200
End If
End Sub

ControlTip Text: Double-click to (Shift-Enter) create scrolling text

----

Private Sub Form_Timer()
Static strMsg As String, intLet As Integer, intLen As Integer
Dim strTmp As String
Dim strChng As Variant
Const TXTLEN = 90

If Len(strMsg) = 0 Then
strChng = InputBox("Create scrolling message.", "Create scrolling message")
strMsg = Space(TXTLEN) & strChng ' & vbCrLf _
' & "www. .com/ " & Space(TXTLEN)
intLen = Len(strMsg)
End If
intLet = intLet + 1
If intLet > intLen Then intLet = 1
strTmp = Mid(strMsg, intLet, TXTLEN)
lblScroll.Caption = strTmp
With Me.lblScroll
.ForeColor = (IIf(.ForeColor = vbBlue, vbBlack, vbBlue))
End With

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top