Jump to content

Stuck Function?


BatMan22
 Share

Recommended Posts

So I am trying to separate test codes into known and unknown test codes, and write the unknowns to a specific test file based on users selection. It works GREAT for the first unknown test code, but then it seems to get stuck? And the program also doesn't stop running? I appreciate the help guys

 

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $TCArray[5] ; Dummy data for now
Global $SampIDArray[5]
$TCArray[0] = "300.1"
$TCArray[1] = "300.0"
$TCArray[2] = "poop"
$TCArray[3] = "zomgnewtestcode"
$TCArray[4] = "fet"
$SampIDArray[0] = "Sample1"
$SampIDArray[1] = "Sample2"
$SampIDArray[2] = "Sample3"
$SampIDArray[3] = "Sample4"
$SampIDArray[4] = "Sample4"
;---------- Function Calls here
AddAllTestCodes()
Knownornot()
;~ Addtolistifknownfunction()


;--------- Functions Below here

Func AddAllTestCodes()
    Global $testcodeIC1[3] = ["300.1", "300.0", "Poop"]
    Global $testcodeIC2[3] = ["218.6", "7199_LL", "Testing"]
    Global $testcodeIC3[3] = ["blah", "blah2", "blah3"]
    Global $totaltestcodes = UBound($testcodeIC1) + UBound($testcodeIC2) + UBound($testcodeIC3)
    Global $knowntestcode[0]
    _ArrayAdd($knowntestcode, $testcodeIC1)
    _ArrayAdd($knowntestcode, $testcodeIC2)
    _ArrayAdd($knowntestcode, $testcodeIC3)
;~ _ArrayDisplay($knowntestcode)
EndFunc   ;==>AddAllTestCodes


Func Knownornot()
    For $i = 0 To UBound($TCArray) - 1 ;should write zomgnewtestcode to the unknown file, eventually this will prompt me to assign it to IC1, 2, or 3. But for now I just want to debug why the IF statement isn't working.
        Local $found = _ArraySearch($knowntestcode, $TCArray[$i])
        If $found = -1 Then

            #Region ### START Koda GUI section ### Form=D:\GodModeAccount\Desktop\ArraydataClientIDHidden\ICSelectGUI.kxf
            $Form1 = GUICreate("Form1", 434, 146, 192, 200)
            $IC1 = GUICtrlCreateButton("IC 1", 24, 112, 89, 25)
            $IC2 = GUICtrlCreateButton("IC 2", 120, 112, 105, 25)
            $IC3 = GUICtrlCreateButton("IC3/4", 232, 112, 81, 25)
            $IC5 = GUICtrlCreateButton("IC5 or Unknown", 320, 112, 105, 25)
            $Label1 = GUICtrlCreateLabel("This test code was not found: Please select a IC to assign it to! " & $TCArray[$i], 8, 8, 412, 89)
            GUISetState(@SW_SHOW)
            #EndRegion ### END Koda GUI section ###


            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $IC1
                        FileWrite(@ScriptDir & "\IC1testcodes.txt", $TCArray[$i] & " " & @CRLF)
                        GUISetState(@SW_HIDE)
                    Case $IC2
                        FileWrite(@ScriptDir & "\IC2testcodes.txt", $TCArray[$i] & " " & @CRLF)
                        GUISetState(@SW_HIDE)
                    Case $IC3
                        FileWrite(@ScriptDir & "\IC3testcodes.txt", $TCArray[$i] & " " & @CRLF)
                        GUISetState(@SW_HIDE)
                    Case $IC5
                        FileWrite(@ScriptDir & "\IC5testcodes.txt", $TCArray[$i] & " " & @CRLF)
                        GUISetState(@SW_HIDE)
                EndSwitch
            WEnd

        EndIf



    Next

EndFunc   ;==>Knownornot

 

Link to comment
Share on other sites

Batman22,

You are stuck in your message loop.  That can be fixed like this...

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $TCArray[5] ; Dummy data for now
Global $SampIDArray[5]
$TCArray[0] = "300.1"
$TCArray[1] = "300.0"
$TCArray[2] = "poop"
$TCArray[3] = "zomgnewtestcode"
$TCArray[4] = "fet"
$SampIDArray[0] = "Sample1"
$SampIDArray[1] = "Sample2"
$SampIDArray[2] = "Sample3"
$SampIDArray[3] = "Sample4"
$SampIDArray[4] = "Sample4"
;---------- Function Calls here
AddAllTestCodes()
Knownornot()
;~ Addtolistifknownfunction()


;--------- Functions Below here

Func AddAllTestCodes()
    Global $testcodeIC1[3] = ["300.1", "300.0", "Poop"]
    Global $testcodeIC2[3] = ["218.6", "7199_LL", "Testing"]
    Global $testcodeIC3[3] = ["blah", "blah2", "blah3"]
    Global $totaltestcodes = UBound($testcodeIC1) + UBound($testcodeIC2) + UBound($testcodeIC3)
    Global $knowntestcode[0]
    _ArrayAdd($knowntestcode, $testcodeIC1)
    _ArrayAdd($knowntestcode, $testcodeIC2)
    _ArrayAdd($knowntestcode, $testcodeIC3)
;~ _ArrayDisplay($knowntestcode)
EndFunc   ;==>AddAllTestCodes


Func Knownornot()
    For $i = 0 To UBound($TCArray) - 1 ;should write zomgnewtestcode to the unknown file, eventually this will prompt me to assign it to IC1, 2, or 3. But for now I just want to debug why the IF statement isn't working.
        Local $found = _ArraySearch($knowntestcode, $TCArray[$i])
        If $found = -1 Then

            #Region ### START Koda GUI section ### Form=D:\GodModeAccount\Desktop\ArraydataClientIDHidden\ICSelectGUI.kxf
            $Form1 = GUICreate("Form1", 434, 146, 192, 200)
            $IC1 = GUICtrlCreateButton("IC 1", 24, 112, 89, 25)
            $IC2 = GUICtrlCreateButton("IC 2", 120, 112, 105, 25)
            $IC3 = GUICtrlCreateButton("IC3/4", 232, 112, 81, 25)
            $IC5 = GUICtrlCreateButton("IC5 or Unknown", 320, 112, 105, 25)
            $Label1 = GUICtrlCreateLabel("This test code [" & $TCArray[$i] & "] was not found: Please select a IC to assign it to! " & $TCArray[$i], 8, 8, 412, 89)
            GUISetState(@SW_SHOW)
            #EndRegion ### END Koda GUI section ###


            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $IC1
                        FileWrite(@ScriptDir & "\IC1testcodes.txt", $TCArray[$i] & " " & @CRLF)
                        ;GUISetState(@SW_HIDE)
                        GUIdelete($form1)
                        exitloop
                    Case $IC2
                        FileWrite(@ScriptDir & "\IC2testcodes.txt", $TCArray[$i] & " " & @CRLF)
                        ;GUISetState(@SW_HIDE)
                        GUIdelete($form1)
                        exitloop
                    Case $IC3
                        FileWrite(@ScriptDir & "\IC3testcodes.txt", $TCArray[$i] & " " & @CRLF)
                        ;GUISetState(@SW_HIDE)
                        GUIdelete($form1)
                        exitloop
                    Case $IC5
                        FileWrite(@ScriptDir & "\IC5testcodes.txt", $TCArray[$i] & " " & @CRLF)
                        ;GUISetState(@SW_HIDE)
                        GUIdelete($form1)
                        exitloop
                EndSwitch
            WEnd

        EndIf



    Next

EndFunc   ;==>Knownornot

However, there are a couple of things that I find unusual:

  1.  Is the purpose of AddAllTestCodes() to get all test codes into 1 array for _ArraySearch?
  2. Creating a gui in a loop is poor design.

If you can explain what you want to do I'm sure that we can help you with various alternatives.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Ok so the REAL code is posted below.. But to answer your questions..

 

1) Yes, for each testcode that I will pull from a .txt file, I want to check to see if it's assigned to a $testcodeIC1, or IC2 or IC3 or blah blah.. If it is, then write that to a file called blah.. if it's not then prompt the user for a $testcodeIC1 and save each to a file

2) I don't disagree, but a normal messagebox doesn't have enough options for the user to choose, I need 4 options (at least). And I'm a shitty programmer so.. :)

 

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $TCArray[0] ; Dummy data for now
Global $SampIDArray[0]
_FileReadToArray(@ScriptDir & "\testcodesforclientIDs.txt", $TCArray, @CRLF)
;~ _ArrayDisplay($TCArray)
_FileReadToArray(@ScriptDir & "\clientIDs.txt", $SampIDArray, @CRLF)
;~ _ArrayDisplay($SampIDArray)


;---------- Function Calls here
AddAllTestCodes()
Knownornot()
Addtolistifknownfunction()


;--------- Functions Below here

Func AddAllTestCodes()
    Global $testcodeIC1[0]
    Global $testcodeIC2[0]
    Global $testcodeIC3[0]
    Global $testcodeIC5[0]

    _FileReadToArray(@ScriptDir & "\IC1testcodes.txt", $testcodeIC1, @CRLF)
    _FileReadToArray(@ScriptDir & "\IC2testcodes.txt", $testcodeIC2, @CRLF)
    _FileReadToArray(@ScriptDir & "\IC3testcodes.txt", $testcodeIC3, @CRLF)
    _FileReadToArray(@ScriptDir & "\IC5testcodes.txt", $testcodeIC5, @CRLF)

    Global $totaltestcodes = UBound($testcodeIC1) + UBound($testcodeIC2) + UBound($testcodeIC3) + UBound($testcodeIC5)
    Global $knowntestcode[0]
    _ArrayAdd($knowntestcode, $testcodeIC1)
    _ArrayAdd($knowntestcode, $testcodeIC2)
    _ArrayAdd($knowntestcode, $testcodeIC3)
    _ArrayAdd($knowntestcode, $testcodeIC5)
    _ArrayDisplay($knowntestcode)
EndFunc   ;==>AddAllTestCodes


Func Knownornot()
    For $i = 0 To UBound($TCArray) - 1 ;should write zomgnewtestcode to the unknown file, eventually this will prompt me to assign it to IC1, 2, or 3. But for now I just want to debug why the IF statement isn't working.
        Local $found = _ArraySearch($knowntestcode, $TCArray[$i])
        If $found = -1 Then

            #Region ### START Koda GUI section ### Form=D:\GodModeAccount\Desktop\ArraydataClientIDHidden\ICSelectGUI.kxf
            $Form1 = GUICreate("Form1", 434, 146, 192, 200)
            $IC1 = GUICtrlCreateButton("IC 1", 24, 112, 89, 25)
            $IC2 = GUICtrlCreateButton("IC 2", 120, 112, 105, 25)
            $IC3 = GUICtrlCreateButton("IC3/4", 232, 112, 81, 25)
            $IC5 = GUICtrlCreateButton("IC5 or Unknown", 320, 112, 105, 25)
            $Label1 = GUICtrlCreateLabel("This test code was not found: Please select a IC to assign it to! " & $TCArray[$i], 8, 8, 412, 89)
            GUISetState(@SW_SHOW)
            #EndRegion ### END Koda GUI section ###


            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $IC1
                        FileWrite(@ScriptDir & "\IC1testcodes.txt", $TCArray[$i] & @CRLF)
                        Exit
                    Case $IC2
                        FileWrite(@ScriptDir & "\IC2testcodes.txt", $TCArray[$i] & @CRLF)
                        Exit
                    Case $IC3
                        FileWrite(@ScriptDir & "\IC3testcodes.txt", $TCArray[$i] & @CRLF)
                        Exit
                    Case $IC5
                        FileWrite(@ScriptDir & "\IC5testcodes.txt", $TCArray[$i] & @CRLF)
                        Exit
                EndSwitch
            WEnd

        EndIf



    Next

EndFunc   ;==>Knownornot

Func Addtolistifknownfunction()

    For $i = 0 To UBound($TCArray) - 1
        If $TCArray[$i] = $testcodeIC1 Then
            FileWrite(@ScriptDir & "\IC1.txt", $SampIDArray[$i] & " " & $TCArray[$i] & @CRLF)
        EndIf
    Next

    For $i = 0 To UBound($TCArray) - 1
        If $TCArray[$i] = $testcodeIC2 Then
            FileWrite(@ScriptDir & "\IC2.txt", $SampIDArray[$i] & " " & $TCArray[$i] & @CRLF)
        EndIf
    Next


    For $i = 0 To UBound($TCArray) - 1
        If $TCArray[$i] = $testcodeIC3 Then
            FileWrite(@ScriptDir & "\IC3.txt", $SampIDArray[$i] & " " & $TCArray[$i] & @CRLF)
        EndIf
    Next

    For $i = 0 To UBound($TCArray) - 1
        If $TCArray[$i] = $testcodeIC5 Then
            FileWrite(@ScriptDir & "\IC5.txt", $SampIDArray[$i] & " " & $TCArray[$i] & @CRLF)
        EndIf
    Next

EndFunc   ;==>Addtolistifknownfunction

 

Link to comment
Share on other sites

Ok.. So the FINAL WORKING code is DONE! You guys ROCK! I've attached the program if anyone wants to try it/see what I was trying to do..

It opens an excel file, reads all the sample ID's and corresponding test codes, and assigns it to a machine if the test code is new, or generates the sampleid/testcode for each device if it's not new or after you select the device that hte test code corresponds to!

 

You guys genuinely rock...! Note: Some functions that are network dependent and how the excel is generated were deleted :)

ExcelLoaderFinished.au3

MC_SampleDueRpt.xls

Edited by BatMan22
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...