Jump to content

Code Not Working on other workstations


Recommended Posts

Hey All,

I have wasted so much time trying to get this chunk of code running on other workstations.

The listbox has a tab separated list of values. I was using arrays with StringSplit, but it didn't work on the other workstations in compiled form, or after installing autoit. I changed to StringMid and StringInStr the @TAB now.

This code opens the child window, it selects a batch. I record the batch.

If the batch has an error, or another problem dialog pops up I unselect the batch and select the next one.

If it finds a batch that it can post a warning dialog should pop up.

Then it sets the bAllBatchesPosted flag to 0 because it found a batch to post.

Then the pharmacy program closes the child window automatically.

I check to see if a batch was posted.

If it posted a batch then I open the child window again and select the next batch after it left off.

This works fine on my workstation. On other workstations after it posts the first batch it can it exits.

Is there anything I need to install on the workstation? I'm frustrated.

Thanks, Doug

#include <GUIConstants.au3>
#include <GuiList.au3>
#include <Date.au3>
#include <file.au3>

AutoItSetOption("SendKeyDelay", 50)
AutoItSetOption("WinTitleMatchMode", 1)

;The title and text have been changed to hide the real names from net searches.
$bAllBatchesPosted = 1
While 1
    Send("!cpp{ENTER}")
    WinWaitActive("Pharmacy", "ChildWindowText", 5)
    Sleep(2000)
    $h_listBatches = ControlGetHandle ("Pharmacy","ChildWindowText","VPListBoxClass321")
    If  $h_listBatches = "" Then
        MsgBox(16, "Error", "Cannot get control handle for ChildWindowText ListBox")
        Exit 99
    EndIf
    $nBatchCount = _GUICtrlListCount($h_listBatches)
    If ($nBatchCount = $LB_ERR) Then
        MsgBox(16, "Error", "Unknown error from _GUICtrlListCount")
        Exit 99
    EndIf
    ControlFocus("Pharmacy", "ChildWindowText", "VPListBoxClass321")
    $nItemNum = 0
    while $nItemNum < $nBatchCount
        $sListItemText = _GUICtrlListGetText($h_listBatches, $nItemNum)
        $sFacID = StringMid($sListItemText, 1, StringInStr($sListItemText, @TAB)-1)
        $sBatch = StringStripWS(StringMid($sListItemText, StringInStr($sListItemText, @TAB)+1,  StringInStr($sListItemText, @TAB, 0, 2) - StringInStr($sListItemText, @TAB)-1), 1)
        If StringInStr($sBatchList, $sFacID & $sBatch) > 0 Then
            $nItemNum = $nItemNum + 1
            ContinueLoop
        EndIf
; Add this batch to the list
        $sBatchList = $sBatchList & $sFacID & $sBatch & ","
        $ret = _GUICtrlListSetSel($h_listBatches,1,$nItemNum)
        If($ret = $LB_ERR) Then
            MsgBox(16,"Error","Unknown error from _GUICtrlListSetSel")
        EndIf
        
; Post Selected Batch
        ControlFocus("Pharmacy","ChildWindowText","ThunderRT6CommandButton3")
        TrayTip("Info", "Posting Batch", 10)
        Send("{ENTER}")
        If WinWaitActive("Error", "", 3) Then
            Send("{ENTER}")
            Sleep(1000)
    ; Unselect 
            $ret = _GUICtrlListSetSel($h_listBatches,0,$nItemNum)
            If($ret = $LB_ERR) Then
                MsgBox(16,"Error","Unknown error from _GUICtrlListSetSel")
            EndIf
            $nItemNum = $nItemNum + 1
            ContinueLoop
        EndIf
        If WinExists("RXs") Then
            Send("{ENTER}")
            Sleep(1000)
    ; Unselect 
            $ret = _GUICtrlListSetSel($h_listBatches,0,$nItemNum)
            If($ret = $LB_ERR) Then
                MsgBox(16,"Error","Unknown error from _GUICtrlListSetSel")
            EndIf
            $nItemNum = $nItemNum + 1
            ContinueLoop
        EndIf
        If WinExists("Missing") Then
            Send("{ENTER}")
            Sleep(1000)
    ; Unselect 
            $ret = _GUICtrlListSetSel($h_listBatches,0,$nItemNum)
            If($ret = $LB_ERR) Then
                MsgBox(16,"Error","Unknown error from _GUICtrlListSetSel")
            EndIf
            $nItemNum = $nItemNum + 1
            ContinueLoop
        EndIf
        If WinWaitActive("Warning", "", 3) Then
            while WinExists("Warning")
                WinActivate("Warning")
                Send("{ENTER}")
                Sleep(1000)
            WEnd
        Else
            while WinExists("Warning")
                WinActivate("Warning")
                Send("{ENTER}")
                Sleep(1000)
            WEnd
        EndIf
        While WinExists("Pharmacy", "ChildWindowText") Or WinExists("Working")
            Sleep(1000)
        Wend
        Sleep(3000)
        $bAllBatchesPosted = 0
        ExitLoop
    WEnd    
    If 1 = $bAllBatchesPosted Then
        ExitLoop
    EndIf
WEnd
Edited by PrgSkidmark
Link to comment
Share on other sites

Just some ideas:

1) Get rid of the Sleep statements if you can. Differences in the speed of machines will hang you up almost every time.

2) Put a logging function in your code and log the values of interest to a file as you go through the loop. That way, you can tell why the loop terminates.

3) Be sure you've appeased the code gods. Sacrificing a small animal while dancing naked around your monitor usually works...

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

The code you have posted is not possible to test or verify on anny system without hunting down includs and such. Some might do that I don't :lmao:

CODE
C:\temp\slettes.au3(14,31) : WARNING: $LB_ERR: possibly used before declaration.

If ($nBatchCount = $LB_ERR)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\temp\slettes.au3(24,35) : WARNING: $sBatchList: possibly used before declaration.

If StringInStr($sBatchList,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\temp\slettes.au3(14,31) : ERROR: $LB_ERR: undeclared global variable.

If ($nBatchCount = $LB_ERR)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\temp\slettes.au3(13,52) : ERROR: _GUICtrlListCount(): undefined function.

$nBatchCount = _GUICtrlListCount($h_listBatches)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\temp\slettes.au3(21,71) : ERROR: _GUICtrlListGetText(): undefined function.

$sListItemText = _GUICtrlListGetText($h_listBatches, $nItemNum)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\temp\slettes.au3(30,61) : ERROR: _GUICtrlListSetSel(): undefined function.

$ret = _GUICtrlListSetSel($h_listBatches,1,$nItemNum)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\temp\slettes.au3 - 4 error(s), 2 warning(s)

Try to provide the smallest sample that do not work.

Ex: You have problems with StringSplit in a standalone on the workstation. Could you provide a simple sample of it?

This part of your code does not look good as it does not check for a timeout but continues and try to get a handel to control that might not be there

WinWaitActive("Pharmacy", "ChildWindowText", 5)
    Sleep(2000)
    $h_listBatches = ControlGetHandle ("Pharmacy","ChildWindowText","VPListBoxClass321")
    ConsoleWrite("Check 1" & @LF)
    If  $h_listBatches = "" Then
        MsgBox(16, "Error", "Cannot get control handle for ChildWindowText ListBox")
        Exit 99
    EndIfoÝ÷ Ù(hºWkjØ^­·¬¢kax%GºÚ"µÍYÕÚ[ØZ]XÝ]J    ][ÝÔXXÞI][ÝË   ][ÝÐÚ[Ú[ÝÕ^   ][ÝË
JH[ÙÐÞ
M   ][ÝÑÜ][ÝË  ][ÝÐØ[Ý[XXÞHÚ[ÝËZ[][ÉÌÌÎÉ][ÝÊB^]NB[ÙB   ÌÍÚÛÝ]ÚÈHÛÛÛÙ][H
    ][ÝÔXXÞI][ÝË   ][ÝÐÚ[Ú[ÝÕ^   ][ÝË  ][ÝÕÝÞÛÜÌÌI][ÝÊBPÛÛÛÛUÜ]J    ][ÝÐÚXÚÈI][ÝÈ    [ÈBY   ÌÍÚÛÝ]ÚÈH    ][ÝÉ][ÝÈ[ÙÐÞ
M   ][ÝÑÜ][ÝË  ][ÝÐÔTØ[ÝÙ]ÛÛÛ[HÜÚ[Ú[ÝÕ^ÝÞ[ÝYÚHÚ[ÝÈÈKZ[][É][ÝÊB^]NB[Y[YoÝ÷ Ù.r¥u©l¡È^rJ.µ«­¢+Ù=ÁÐ ÅÕ½ÐíIÕ¹ÉɽÉÍÑ°ÅÕ½Ðì°À¤
But then you have to (should) check @error after critical function calls.

Add dbg and assert statements as sugested in this thread to hunt down bugs.

Hope this cna help you on the way. Unless the workstation in question is a realy special installation I doubt AutoIt is the culprit to your problems.

Wich you good bug hunting luck :ph34r:

Link to comment
Share on other sites

Should rather be somthing like:

If NOT WinWaitActive("Pharmacy", "ChildWindowText", 5) Then
        MsgBox(16, "Error", "Cannot find Pharmacy window. Terminating!")
        Exit 99
Else
    $h_listBatches = ControlGetHandle ("Pharmacy","ChildWindowText","VPListBoxClass321")
    ConsoleWrite("Check 1" & @LF)
    If  $h_listBatches = "" Then
        MsgBox(16, "Error", "CRAP: Cannot get control handle for ChildWindowText ListBox althought the window is there. Terminating")
        Exit 99
    EndIf
    EndIfoÝ÷ Ûú®¢×©äÊ¢»aÈ^ë.jYr²Z)§&¥k

After {ENTER} is sent to the Warning Dialog none of the other MsgBox's are executed. It will continue and NOT exit the loop. That is very confusing to me. I wonder if the application on the other workstation is not responding to the messages WinExists or WinWaitClose. Is there another way to check the app when it's not responding to messages?

Thank you for your responses. You have helped so much already.

Doug

Link to comment
Share on other sites

I am usually sloppy, a lazy coder, at error checking. You know, I do some, but not all.

This is the first thing you need to fix. :lmao: You'll probably not get many people to help you here if you're not willing to help yourself first.

Get rid of the MsgBox statements and log to a file. By logging to a file, you won't be stealing focus or putting extra delays in your code that may be causing the problem.

Get rid of the Sleep statements. You're using them as a crutch instead of writing the correct code to detect if the window/control is enabled.

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Use ControlSend and ControlClick to target your actions better. Also check the return value of saide functions.

The dbg function I pointed you to is a killer tip in this kind of situation. Use FileInstall to embed dgview in your application (a debug version!) and launche it as yuo start your application.

Does your workstation and the offending workstation have the samme localization settings?

Witch control has focus when you send ENTER in this case? Use ControlSend (it does not always work especially if there are non native buttons) or maybe ALT+O (OK? or CANCEL?)

If WinExists("Warning") Then
    MsgBox(4096, "Check Warning", "There's the warning")
    WinActivate("Warning")
    Send("{ENTER}")
    Sleep(1000)
EndIf
Link to comment
Share on other sites

Hey All,

Thank you for all your help!

Everything is running great after the rewrite. On the main operations I check the return value and exit if there's a failure.

The login dialog needs to have the text cleared before setting new text for some reason. It would fail everytime if I left out the ControlSetText to blank.

ControlFocus ( "Login", "", "ThunderRT6TextBox3") ; 8
ControlSetText("Login", "", "ThunderRT6TextBox3", "", 1)
$ret = ControlSetText("Login", "", "ThunderRT6TextBox3", "SERVER", 1)
If $ret = 0 Then ; 8
    _FileWriteLog($ErrorLogFilename, "Login: Cannot set Server Name")
    Exit 99
EndIf
oÝ÷ Øw«zËazw°r^Â+ax-ì!W¥¢H|­ kzÛ«Çë¢kayh§Y¨­
Z,x¦r)à~íç±ËZǨ}j+)àÂ)Ý£-v'g¢×ÚWn®)àµë-xºÚ"µÍYÚ[^ÝÊ   ][ÝÕØ[É][ÝÊH[WÑ[UÜ]SÙÊ    ÌÍÑÜÙÑ[[[YK   ][ÝÔÜÝØÜ[ÛÎ]ÚÈØ[É][ÝÊBUÚ[XÝ]]J  ][ÝÕØ[É][ÝÊBTÙ[
    ][ÝÞI][ÝÊHÈYÂRYÝÚ[ØZ]XÝ]J ][ÝÕÛÜÚ[É][ÝË   ][ÝÉ][ÝË
JH[BWÑ[UÜ]SÙÊ   ÌÍÑÜÙÑ[[[YK   ][ÝÕÛÜÚ[ÎØ[Ý[Ú[ÝÉ][ÝÊBBQ^]NBBBQ[YRYÚ[ØZ]ÛÜÙJ  ][ÝÕÛÜÚ[É][ÝÊHHH[BRYÚ[^ÝÊ    ][ÝÕÛÜÚ[É][ÝÊH[BBWÑ[UÜ]SÙÊ  ÌÍÑÜÙÑ[[[YK   ][ÝÕÛÜÚ[ÎÚ[ÝÈÝ[^ÝÈ][ÝYÚH[È]ÈÛÜÙY ][ÝÊBBBQ^]NBBBBQ[YQ[YIÌÍØ[]ÚÔÜÝYHQ^]ÛÜ[Y
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...