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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with timer code! 1

Status
Not open for further replies.

ctlin

Technical User
Apr 17, 2002
77
US
am i allowed to call public subs in other forms from a timer? it seems not to be able to call them...

Call Form2.mysub
--> it never enters form2.mysub() !!!argh!
-------

Private Sub Timer1_Timer()
Dim mFileSysObj As New FileSystemObject
Form11.Text2.Text = Str$(promptCurrent)

If mFileSysObj.FileExists(App.Path & "\prompt" & Trim$(Str$(promptCurrent)) & ".rdy") Then

For I = 1 To Len(promptArray(promptCurrent)) 'send string, one character at a time (convert one char to ascii at a time)
PostMessage lwnhandle, WM_CHAR, Asc(Mid$(promptArray(promptCurrent), I, 1)), 0
Next I
PostMessage lwnhandle, WM_CHAR, 13, 0

If promptCurrent = promptStop Then
'Timer1.Enabled = False
Screen.MousePointer = vbDefault
Select Case doAfter
Case "nothing" 'do nothing
'----------
Case "form1cleanup"
Form1.Hide
MDIForm1.cmdfltrsyn.Enabled = True 'enables filter syn menu
MDIForm1.cmdfltrsyn1.Enabled = True
'----------
Case "form2block2"
Call Form2.mysub
Form11.Text1.Text = "form2block2 called"
Case "form2block3"
Call Form2.form2block3
Case "form2block4"
Call Form2.form2block4
Case "form2cleanup"
Form2.Hide
MDIForm1.cmdfltrsyn2.Enabled = True
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID1, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture) 'add checkbox to menu item
'----------
Case "form3cleanup"
MDIForm1.cmdfltrsyn3.Enabled = True
Form3.Hide
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID2, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture)
Call MsgBox("Synthesis results are saved at ./data/syn.dim", vbOKOnly, "Data Saved")
'----------
Case "form5cleanup"
MDIForm1.cmdfltrsyn4.Enabled = True
Form5.Hide
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID3, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture)
Call MsgBox("Frequency response result saved at ./data/response and overall s parameters at ./data/rgflt_s", vbOKOnly, "Data Saved")
Call MsgBox("check response and return to Bandpass Prototype Filter Analysis", vbOKOnly, "Re-synthesis")
'---------
Case "form6cleanup"
MDIForm1.cmdfltrsyn5.Enabled = True
Call Form6.Hide
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID4, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture)
Call MsgBox("Done - Goto Filter Response Analysis to get final frequency response", vbOKOnly, "Done")
'---------
Case "form8block2"
Call Form8.form8block2
Case "form8cleanup"
Call Form8.Hide
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID5, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture)
Call MsgBox("Data saved at ./data/yield.res", vbOKOnly, "Data Saved")
'---------
Case "form9cleanup"
Call Form9.Hide
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID5, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture)
Call MsgBox("Data saved at ./data/sen.res", vbOKOnly, "Data Saved")
End Select
Timer1.Enabled = False
Form11.Text1.Text = "timer disabled"
pauseit 500
End If
promptCurrent = promptCurrent + 1

checkExit

End If

End Sub
 
never mind the messy coding- i just need to know if i can call public subs in other forms from inside a case statement inside a timer.

it runs the line immediately after the call form2.mysub() but form2.mysub is never run!
 

well it seems that you are able to set form11.text = to something withing the same part of the code. Have you put a break on that line and walked through?? if you have and it still does not call the sub you are looking for does the sub have any arguments??? does the form exist withing the project?? Does the sub exists within the form???


Now after asking all of these questions I see you do not have an error handler.

Try putting an error handler within your timer

private sub timer1_timer()

on error goto Timer1_TimerError

'place you code here

exit sub
Timer1_TimerError:

msgbox err.description

end sub


and see if you are generating an error.
 
Yes, you can call a public sub in another form, even if that form has not yet been loaded - but be sure to unload it when you're done.

As to why its not working - that's a different question. One which is apparently obvious. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
A couple of things do come to mind, although may not be applicable to the current problem.

I always think its a good idea to disable a timer, especially when there is a fair amount of code in the event handler, so that the event does not get triggered a second time, while you're handling the first event. I would disable the timer as the first line in the event, and then re-enable as the last line.

When in design mode, the intellisense should include in the drop down list, all of the public subs that are available for that form after you've typed the ".". I would verify that the name is in that list.

I would also step thru the code line by line, and see where it takes you. It should take you into form2.mysub Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I think Cajun hit it dead on, but just didn't say it so everyone could understand. The sub you are calling in the second form must be declared as Public. If it is declared as Private (as I know I am apt to do when cutting and pasting a similar sub) then the call will not work. This will however generate an error when you attempt the call. Also as Cajun said, the sub name should pop up on the intellisense (autocomplete) after you type in FormWhatever.beginsubname (example only). If it doesn't, your trying to call a sub that can't be "seen" in the current context.
 
if i add in a "promptcurrent = promptcurrent - 1" as shown, the codes works! i think there must have been some confusion as to me thinking the timer sub would exit when the timer was disabled. turns out it runs the rest of the code.... thanks for the help!

Private Sub Timer1_Timer()


Dim mFileSysObj As New FileSystemObject
Form11.Text2.Text = Str$(promptCurrent)

If mFileSysObj.FileExists(App.Path & "\prompt" & Trim$(Str$(promptCurrent)) & ".rdy") Then
'pauseit 500
For I = 1 To Len(promptArray(promptCurrent)) 'send string, one character at a time (convert one char to ascii at a time)
PostMessage lwnhandle, WM_CHAR, Asc(Mid$(promptArray(promptCurrent), I, 1)), 0
Next I
PostMessage lwnhandle, WM_CHAR, 13, 0

If promptCurrent = promptStop Then
Timer1.Enabled = False
Screen.MousePointer = vbDefault
Select Case doAfter
Case "nothing" 'do nothing
'----------
Case "form1cleanup"
Form1.Hide
MDIForm1.cmdfltrsyn.Enabled = True 'enables filter syn menu
MDIForm1.cmdfltrsyn1.Enabled = True
'----------
Case "form2block2"
Call Form2.form2Block2
Form11.Text1.Text = "form2block2 called"
promptCurrent = promptCurrent - 1
Case "form2block3"
Call Form2.form2block3
promptCurrent = promptCurrent - 1
Case "form2block4"
Call Form2.form2block4
promptCurrent = promptCurrent - 1
Case "form2cleanup"
Form2.Hide
MDIForm1.cmdfltrsyn2.Enabled = True
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID1, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture) 'add checkbox to menu item
'----------
Case "form3cleanup"
MDIForm1.cmdfltrsyn3.Enabled = True
Form3.Hide
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID2, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture)
Call MsgBox("Synthesis results are saved at ./data/syn.dim", vbOKOnly, "Data Saved")
'----------
Case "form5cleanup"
MDIForm1.cmdfltrsyn4.Enabled = True
Form5.Hide
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID3, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture)
Call MsgBox("Frequency response result saved at ./data/response and overall s parameters at ./data/rgflt_s", vbOKOnly, "Data Saved")
Call MsgBox("check response and return to Bandpass Prototype Filter Analysis", vbOKOnly, "Re-synthesis")
'---------
Case "form6cleanup"
MDIForm1.cmdfltrsyn5.Enabled = True
Call Form6.Hide
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID4, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture)
Call MsgBox("Done - Goto Filter Response Analysis to get final frequency response", vbOKOnly, "Done")
'---------
Case "form8block2"
Call Form8.form8block2
Case "form8cleanup"
Call Form8.Hide
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID5, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture)
Call MsgBox("Data saved at ./data/yield.res", vbOKOnly, "Data Saved")
'---------
Case "form9cleanup"
Call Form9.Hide
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID5, 0, pictureholder.Image1.Picture, pictureholder.Image1.Picture)
Call MsgBox("Data saved at ./data/sen.res", vbOKOnly, "Data Saved")
End Select
'Timer1.Enabled = False
'Form11.Text1.Text = "timer disabled"
'pauseit 500

End If

If promptCurrent <> promptStop Then


promptCurrent = promptCurrent + 1
End If

checkExit

End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top