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

Code runs too long, causes problem 4

Status
Not open for further replies.

oakleaf8

IS-IT--Management
May 16, 2002
57
0
0
US
I have a pushbutton that sends data to the serial port. The problem is that the code takes 10-20 seconds to run depending on which PC it is run on. This causes the user to think it's not working and press the pushbutton several more times, which adds to the problem, often causing the PC to hang up.

I'm thinking two things:

(1) Is there code that causes the pushbutton to be inoperable after first pushed, and then operable after the code completes?

(2) Is the "Wait" code the best way to do this or even necessary?

Here's the code for reference:

Code:
    CutterPort = DLookup("[CutterPort]", "tblCutterData", "[Cutter] = " & CutterNumber)
    SerComm.CommPort = CutterPort
    SerComm.Settings = "9600,N,8,1"
    SerComm.InBufferCount = 0       ' clear ports
    SerComm.OutBufferCount = 0
    SerComm.InputLen = 1            ' set InputData to 1 character
    If SerComm.PortOpen = False Then SerComm.PortOpen = True
    SerComm.Output = "W0F63" + strQtyOrdered + Chr$(&HD): DTRWait
    SerComm.Output = "W0F93" + strQtyCut + Chr$(&HD): DTRWait
    SerComm.Output = "W1043" + Hex(Me![LengthCalc]) + Chr$(&HD): DTRWait
    SerComm.Output = "W1002" + Hex(0) + Chr$(&HD): DTRWait
    SerComm.Output = "W1022" + Hex(0) + Chr$(&HD): DTRWait
    SerComm.Output = "W1092" + Hex(0) + Chr$(&HD): DTRWait
    SerComm.Output = "W1072" + Hex(0) + Chr$(&HD): DTRWait
    SerComm.Output = "W0ED2" + Hex(Me![BF]) + Chr$(&HD): DTRWait
    SerComm.Output = "W0BE2" + Hex(Me![Y]) + Chr$(&HD): DTRWait
    SerComm.Output = "W0F01" + Hex(Me![FSpd]) + Chr$(&HD): DTRWait
    SerComm.Output = "W0F11" + Hex(Me![CSpd]) + Chr$(&HD): DTRWait
    SerComm.Output = "W0F21" + Hex(Me![FCorr]) + Chr$(&HD): DTRWait
    SerComm.Output = "W0F41" + Hex(2) + Chr$(&HD): DTRWait
    SerComm.Output = "W0E01" + Hex(Me![MarkerMode]) + Chr$(&HD): DTRWait
    SerComm.Output = "W1822" + Hex(Me![MarkDistance]) + Chr$(&HD): DTRWait
    SerComm.Output = "W1841" + Hex(Me![RetentionTime]) + Chr$(&HD): DTRWait
    SerComm.Output = "W1851" + Hex(Me![WaitTime]) + Chr$(&HD): DTRWait
    SerComm.Output = "G0001" + Chr$(&HD): DTRWait
    SerComm.PortOpen = False


Sub DTRWait()
    waitcount = 0
    Do
    waitcount = waitcount + 1
    Loop Until (waitcount = 10000)
End Sub

Thanks!
 
Try calling
DoCmd.HourGlass true
at the start of the process to indicate that something is happening. You can also show some text in the status bar for good measure.

Call DoCmd.HourGlass false when it's finished.


Bob Boffin
 
Your code for the button should should move focus to neutral control then set the buttons enabled property to false. At the end of the process, set the enabled property back to true. You have to move focus because you can't disable an object that has focus.
 
And add a DoEvents call in the DTRWait's loop

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I have incorporated all four recommendations you have sent and have learned something from each of them. Thank you very much! Here's the updated code (updates bolded):

Code:
   [b] DoCmd.Hourglass True
    NumberOfWaits = 18
    i = 0
    ReturnValue = SysCmd(acSysCmdInitMeter, "Cutting Wire", NumberOfWaits)
    Me!Comments.SetFocus
    CutWire.Enabled = False [/b]

    CutterPort = DLookup("[CutterPort]", "tblCutterData", "[Cutter] = " & CutterNumber)
    SerComm.CommPort = CutterPort
    SerComm.Settings = "9600,N,8,1"
    SerComm.InBufferCount = 0       ' clear ports
    SerComm.OutBufferCount = 0
    SerComm.InputLen = 1            ' set InputData to 1 character
    If SerComm.PortOpen = False Then SerComm.PortOpen = True
    SerComm.Output = "W0F63" + strQtyOrdered + Chr$(&HD): DTRWait
    SerComm.Output = "W0F93" + strQtyCut + Chr$(&HD): DTRWait
    SerComm.Output = "W1043" + Hex(Me![LengthCalc]) + Chr$(&HD): DTRWait
    SerComm.Output = "W1002" + Hex(0) + Chr$(&HD): DTRWait
    SerComm.Output = "W1022" + Hex(0) + Chr$(&HD): DTRWait
    SerComm.Output = "W1092" + Hex(0) + Chr$(&HD): DTRWait
    SerComm.Output = "W1072" + Hex(0) + Chr$(&HD): DTRWait
    SerComm.Output = "W0ED2" + Hex(Me![BF]) + Chr$(&HD): DTRWait
    SerComm.Output = "W0BE2" + Hex(Me![Y]) + Chr$(&HD): DTRWait
    SerComm.Output = "W0F01" + Hex(Me![FSpd]) + Chr$(&HD): DTRWait
    SerComm.Output = "W0F11" + Hex(Me![CSpd]) + Chr$(&HD): DTRWait
    SerComm.Output = "W0F21" + Hex(Me![FCorr]) + Chr$(&HD): DTRWait
    SerComm.Output = "W0F41" + Hex(2) + Chr$(&HD): DTRWait
    SerComm.Output = "W0E01" + Hex(Me![MarkerMode]) + Chr$(&HD): DTRWait
    SerComm.Output = "W1822" + Hex(Me![MarkDistance]) + Chr$(&HD): DTRWait
    SerComm.Output = "W1841" + Hex(Me![RetentionTime]) + Chr$(&HD): DTRWait
    SerComm.Output = "W1851" + Hex(Me![WaitTime]) + Chr$(&HD): DTRWait
    SerComm.Output = "G0001" + Chr$(&HD): DTRWait
    SerComm.PortOpen = False 
    [b]CutWire.Enabled = True
    ReturnValue = SysCmd(acSysCmdRemoveMeter)
    DoCmd.Hourglass False[/b]


Sub DTRWait()
    waitcount = 0
    [b]i=i+1[/b]
    Do
        [b]DoEvents[/b]
        waitcount = waitcount + 1
    Loop Until (waitcount = 10000)
    [b]ReturnValue = SysCmd(acSysCmdUpdateMeter, i)[/b]
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top