anoig

Need help debugging _arrayadd function

2 posts in this topic

#1 ·  Posted

Hi all, 

First, I want to give a huge shout-out to the community. I'm completely self-taught, and have never had to actually ask a question before because the forum is that good at answering questions and explaining things. However, I'm kind of stumped here, and I've been stuck on this problem for almost a full day.

I'm working on a script to populate drafts of deeds at work. I have the main GUI and  a function (ctrl($n) and read()) for adding fields to find and data to replace it with to an array for later use with _word_docfindreplace. All of that works. However, due to the way I have the forms set up, I need to create additional fields and info based on the data that's there. Specifically, if there's only one buyer, I need to add the field [Buyer1&2] and the data in $aArray_Base for [Buyer 1]. I also need to add a field [Buyer 2] and have a blank data set in the next column over in the array, and I need to do the same for the Seller. To this end, the function parties() sets boolean variables $2buyers and $2sellers accordingly. Then, I have buyers() and sellers() to populate the data. 

The problem that I'm running into is that each function works... when ONLY the buyer 1 name field is filled, and when ONLY the seller 1 field is filled.

So if I fill Buyer 1 Name and save it, the data is populated correctly. But when I fill Buyer 1 and Seller 1 name, only the buyer 1 data populates correctly. Worse, when I fill several fields, neither populate correctly. I have no idea why this happens. I've added messageboxes to debug throughout the entire process and can't pinpoint what's causing the issue. The entire script is below. The function(s) in question are buyers() and sellers(). Only Sellers() has messageboxes throughout.

Can someone help walk me through what might be causing this and help me find a solution? Thanks a ton in advance, and sorry for the wall of text.

-Anoig

Spoiler
#include <ButtonConstants.au3> ;AutoIT plugins
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <Word.au3>
#include <ComboConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\Randy\Downloads\koda_1.7.3.0\Forms\KNDS.kxf
$KNDS = GUICreate("KNDS DocPrep Wizard", 727, 507, 540, 193)
$MainPage = GUICtrlCreateTab(8, 40, 708, 424)
$TabSheet1 = GUICtrlCreateTabItem("Property")
$Property = GUICtrlCreateGroup("Legal Description", 32, 80, 657, 153)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$InputLegal = GUICtrlCreateEdit("", 40, 96, 641, 129, $ES_WANTRETURN, 0)
GUICtrlSetTip(-1, "Full legal description from Schedule A of Title Commitment")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Buyer = GUICtrlCreateTabItem("Buyer")
$Buyer1Group = GUICtrlCreateGroup("Buyer 1", 24, 72, 329, 185)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$inputbuyer1 = GUICtrlCreateInput("", 120, 104, 217, 22)
GUICtrlSetTip(-1, "Bob Buyer, LLC")
$Buyersingle = GUICtrlCreateRadio("Single", 32, 136, 57, 17)
$BuyerMarried = GUICtrlCreateRadio("Married", 32, 160, 65, 17)
$BuyerLLC = GUICtrlCreateRadio("LLC", 32, 184, 57, 17)
$BuyerInc = GUICtrlCreateRadio("Inc.", 32, 208, 49, 17)
$inputbuyerentitystate = GUICtrlCreateInput("", 272, 208, 73, 22)
GUICtrlSetTip(-1, "Write out state name, e.g. Texas")
$Buyer1label = GUICtrlCreateLabel("Buyer 1 Name:", 32, 104, 75, 18)
$labelbuyerentitystate = GUICtrlCreateLabel("State (only if LLC or Inc.):", 136, 208, 127, 18)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Buyer2Group = GUICtrlCreateGroup("Buyer 2", 368, 72, 321, 185)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Buyer2label = GUICtrlCreateLabel("Buyer 2 Name:", 376, 104, 75, 18)
$InputBuyer2 = GUICtrlCreateInput("", 464, 104, 209, 22)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$GroupBuyAdd = GUICtrlCreateGroup("Buyer's Address", 24, 264, 673, 185)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$labelbuyadd1 = GUICtrlCreateLabel("Address:", 32, 304, 49, 18)
$labelbuyadd2 = GUICtrlCreateLabel("City, State, Zip:", 32, 336, 81, 18)
$labelbuycounty = GUICtrlCreateLabel("County:", 32, 368, 41, 18)
$InputBuyerAdd1 = GUICtrlCreateInput("", 120, 304, 561, 22)
GUICtrlSetTip(-1, "123 Main Street")
$InputBuyerAdd2 = GUICtrlCreateInput("", 120, 336, 561, 22)
GUICtrlSetTip(-1, "City, State Zip")
$InputBuyerAdd3 = GUICtrlCreateInput("", 120, 368, 561, 22)
GUICtrlSetTip(-1, "County")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Seller = GUICtrlCreateTabItem("Seller")
$Group1 = GUICtrlCreateGroup("Seller 1", 26, 73, 329, 185)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$InputSeller1 = GUICtrlCreateInput("", 122, 105, 217, 22)
GUICtrlSetTip(-1, "Sally the Seller, LLC")
$Labelseller1 = GUICtrlCreateLabel("Seller 1 Name:", 34, 105, 73, 18)
$SellerMarried = GUICtrlCreateRadio("Married", 34, 161, 65, 17)
$SellerSingle = GUICtrlCreateRadio("Single", 34, 137, 57, 17)
$SellerLLC = GUICtrlCreateRadio("LLC", 34, 185, 57, 17)
$SellerInc = GUICtrlCreateRadio("Inc.", 34, 209, 49, 17)
$Label2 = GUICtrlCreateLabel("State (only if LLC or Inc.):", 138, 209, 127, 18)
$InputSellerEntityState = GUICtrlCreateInput("", 274, 209, 73, 22)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Seller 2", 372, 73, 321, 185)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label3 = GUICtrlCreateLabel("Seller 2 Name:", 380, 105, 73, 18)
$InputSeller2 = GUICtrlCreateInput("", 468, 105, 209, 22)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Seller's Address", 26, 265, 673, 185)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label4 = GUICtrlCreateLabel("Address:", 34, 305, 49, 18)
$Label5 = GUICtrlCreateLabel("City, State Zip:", 34, 337, 81, 18)
$Label6 = GUICtrlCreateLabel("County:", 34, 369, 41, 18)
$InputSellerAdd1 = GUICtrlCreateInput("", 122, 305, 561, 22)
GUICtrlSetTip(-1, "123 Main Street")
$InputSellerAdd2 = GUICtrlCreateInput("", 122, 337, 561, 22)
GUICtrlSetTip(-1, "City, State Zip")
$InputSellerAdd3 = GUICtrlCreateInput("", 122, 369, 561, 22)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Lender = GUICtrlCreateTabItem("Lender")
GUICtrlSetState(-1,$GUI_SHOW)
$Group5 = GUICtrlCreateGroup("Lender Info", 19, 73, 393, 161)
$Label7 = GUICtrlCreateLabel("Address:", 27, 129, 45, 17)
$Label8 = GUICtrlCreateLabel("City, State, Zip:", 27, 161, 81, 18)
$Label9 = GUICtrlCreateLabel("County:", 27, 193, 40, 17)
$InputLenderAdd1 = GUICtrlCreateInput("", 115, 129, 281, 21)
GUICtrlSetTip(-1, "123 Main Street")
$InputLenderAdd2 = GUICtrlCreateInput("", 115, 161, 281, 21)
GUICtrlSetTip(-1, "City, State, Zip")
$InputLenderAdd3 = GUICtrlCreateInput("", 115, 193, 281, 21)
GUICtrlSetTip(-1, "e.g. Tarrant County")
$Label1 = GUICtrlCreateLabel("Lender Name:", 27, 97, 71, 17)
$InputLender = GUICtrlCreateInput("", 115, 97, 281, 21)
GUICtrlSetTip(-1, "We Lend Things, Inc.")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("Loan Info:", 16, 248, 681, 201)
$Label10 = GUICtrlCreateLabel("Principal:", 27, 272, 47, 17)
$Label11 = GUICtrlCreateLabel("Write Out:", 27, 305, 52, 17)
$Label14 = GUICtrlCreateLabel("", 27, 337, 4, 4)
$InputPrincipal = GUICtrlCreateInput("", 88, 272, 153, 21)
GUICtrlSetTip(-1, "$xx,xxx.xx")
$InputWriteOut = GUICtrlCreateEdit("", 88, 304, 593, 129, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))
GUICtrlSetTip(-1, "THIS MANY AND NO/100 DOLLARS (NO LINE BREAKS)")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group6 = GUICtrlCreateGroup("Trustee Info", 418, 73, 281, 161)
$Label18 = GUICtrlCreateLabel("Trustee Name:", 426, 97, 74, 17)
$InputTrustee = GUICtrlCreateInput("", 506, 97, 185, 21)
GUICtrlSetTip(-1, "I.M. Trustworthy, Jr.")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateTabItem("")
$GFLabel = GUICtrlCreateLabel("GF No:", 8, 8, 38, 17)
$CommonLabel = GUICtrlCreateLabel("Property Address:", 128, 8, 87, 17)
$CloseDateLabel = GUICtrlCreateLabel("Closing Date:", 544, 8, 67, 17)
$InputGF = GUICtrlCreateInput("", 48, 8, 73, 21)
GUICtrlSetTip(-1, "123456-RN-X")
$InputCommon = GUICtrlCreateInput("", 216, 8, 321, 21)
GUICtrlSetTip(-1, "Common address from front of file")
$InputInvoiceNo = GUICtrlCreateInput("", 72, 472, 129, 21)
$HelpButton = GUICtrlCreateButton("Help", 632, 32, 81, 25)
$LabelInvoiceNo = GUICtrlCreateLabel("Invoice No.", 8, 472, 59, 17)
$InputClosingDate = GUICtrlCreateInput("", 616, 8, 97, 21)
GUICtrlSetTip(-1, "Close date from contract")
$SaveButton = GUICtrlCreateButton("Save", 640, 472, 73, 25)
GUICtrlSetTip(-1, "Click this when you're ready to prep docs")
$InputType = GUICtrlCreateCombo("", 304, 472, 129, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "GWD|WDVL|WDMR|WDVLMR|SWD|SWDVL|SWDMR|SWDVLMR|Note & DoT|Wraparound Package")
$Label12 = GUICtrlCreateLabel("Doc Type:", 248, 472, 54, 17)
$Label13 = GUICtrlCreateLabel("Doc Cost:", 440, 472, 51, 17)
$InputCost = GUICtrlCreateInput("", 496, 472, 73, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $GF, $type, $fail[0][2], $addfail[1][2], $n = "", $invoice = 4, $sleep = 50, $aArray_invoice[12][2] = [["Field","Data"]], $buyerentitystate, $sellerentitystate, $buyerstatus, $sellerstatus, $buyer2, $seller2, $Cid, $arrayadd[1][2], $Fields[] = ["[Legal]","[Common]","[GF]","[CloseDate]","[Buyer 1]","[Buyer 2]","[Buyeradd1]","[Buyeradd2]","[Buyeradd3]","[Seller 1]","[Seller 2]","[Selleradd1]","[Selleradd2]","[Selleradd3]","[Lender]","[Lenderadd1]","[Lenderadd2]","[Lenderadd3]","[Principal]","[Write Out]","[Trustee]","[Invoice No.]","[Type]"]
hotkeyset("`", "prep")

While 1 ; What to do when buttons are pressed/forms are filled
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $HelpButton
            msgbox(-1, "Help", "Under construction!")
         Case $SaveButton
            Read()
            Parties()
            Buyers()
            Sellers()
            _arraydisplay($aArray_Base, "Saved Data")
    EndSwitch
 WEnd

 Func Read() ; Function for getting all data from input boxes
    global $aArray_Base[0][2] ; Start with clean array each time function is run
    For $n = 1 to 23 ; Make sure upper boundary is highest number in ctrl()!!
       If Guictrlread(Ctrl($n)) = NOT ("" OR 0)  Then ; Skip blank data
            $arrayadd[0][0] = $Fields[$n-1]         ; Define temporary array with data from $fields and Ctrl($n)
            $arrayadd[0][1] = Guictrlread(Ctrl($n)) ;
         If _arraysearch($aArray_Base, $arrayadd[0][0]) = NOT (-1) Then ; If [Field] is already in main array, replace data from input box, leave [Field] same
            $aArray_Base[_arraysearch($aArray_Base, $arrayadd[0][0])][1] = GuiCtrlRead(Ctrl($n))
         ElseIf @error = (6 OR 3) Then ; If Data not found or main array is empty, append new index to main array
         _arrayadd($aArray_Base, $arrayadd)
         EndIf
      EndIf
   Next
 EndFunc

 Func Ctrl($n) ; Function for passing control handles to for loops
    Select
    Case $n = 1
       $cid = $inputlegal
    Case $n = 2
       $cid = $inputcommon
    Case $n = 3
       $cid = $inputGF
    Case $n = 4
       $cid = $inputClosingDate
    Case $n = 5
       $cid = $inputBuyer1
    Case $n = 6
       $cid = $inputBuyer2
    Case $n = 7
       $cid = $inputBuyeradd1
    Case $n = 8
       $cid = $inputBuyeradd2
    Case $n = 9
       $cid = $inputBuyeradd3
    Case $n = 10
       $cid = $inputSeller1
    Case $n = 11
       $cid = $inputSeller2
    Case $n = 12
       $cid = $inputSelleradd1
    Case $n = 13
       $cid = $inputSelleradd2
    Case $n = 14
       $cid = $inputSelleradd3
    Case $n = 15
       $cid = $inputLender
    Case $n = 16
       $cid = $inputLenderadd1
    Case $n = 17
       $cid = $inputLenderadd2
    Case $n = 18
       $cid = $inputLenderadd3
    Case $n = 19
       $cid = $inputPrincipal
    Case $n = 20
       $cid = $inputWriteOut
    Case $n = 21
       $cid = $inputTrustee
    Case $n = 22
       $cid = $inputInvoiceNo
    Case $n = 23
       $cid = $inputType
    EndSelect
    Return $Cid
 EndFunc

Func Parties() ; Determine how many buyers and sellers
   local $row = _arraysearch($aArray_Base, "[Seller 2]")
  If  $row = -1 Then ; If no seller 2, seller 2 false
     global $2sellers = False
  ElseIf $aArray_Base[$row][1] = "" Then ; If seller 2 label, but not data, seller 2 false
     global $2sellers = False
  Else ; If seller 2 label and data, seller 2 true
     Global $2sellers = True
  EndIf
   local $row = _arraysearch($aArray_Base, "[Buyer 2]")
  If  $row = -1 Then
     global $2buyers = False
  ElseIf $aArray_Base[$row][1] = "" Then
     global $2buyers = False
  Else
     global $2buyers = True
  EndIf
  msgbox(-1, "", "2sellers " & $2sellers & "2buyers " & $2buyers)
EndFunc

Func Buyers()
If $2buyers = False Then ; [Buyer1&2] = [Buyer 1]
   local  $row = _arraysearch($aArray_Base, "[Buyer 1]")
   If $row = NOT -1 Then ; account for blank [Buyer 1]
   $arrayadd[0][0] = "[Buyer1&2]"
   $arrayadd[0][1] = $aArray_Base[$row][1]
   _arrayadd($aArray_Base, $arrayadd)

   $arrayadd[0][0] = "[Buyer 2]" ; Delete Buyer 2 if found
   $arrayadd[0][1] = ""
   _arrayadd($aArray_Base, $arrayadd)
   EndIf
ElseIf $2buyers = True Then ; [Buyer1&2] = [Buyer 1] and [Buyer 2]
   Local $1row = _arraysearch($aArray_Base, "[Buyer 1]")
   Local $2row = _arraysearch($aArray_Base, "[Buyer 2]")
    $arrayadd[0][0] = "[Buyer1&2]"
    $arrayadd[0][1] = "" & $aArray_Base[$1row][1] & " and " & $aArray_Base[$2row][1]
   _arrayadd($aArray_Base, $arrayadd)
EndIf
EndFunc

Func Sellers()
If $2sellers = False Then
   local $row = _arraysearch($aArray_Base, "[Seller 1]")
   msgbox(-1, "Sellers()","$row = " & $row)
   If $row = NOT -1 Then
      msgbox(-1, "Sellers()", "$row is not -1")
   $arrayadd[0][0] = "[Seller1&2]"
   msgbox(-1, "Sellers()", "$arrayadd[0][0] = " & $arrayadd[0][0])
   $arrayadd[0][1] = $aArray_Base[$row][1]
   msgbox(-1, "", "$arrayadd[0][1] = " & $arrayadd[0][1])
   _arrayadd($aArray_Base, $arrayadd)

   $arrayadd[0][0] = "[Seller 2]"
   $arrayadd[0][1] = ""
   _arrayadd($aArray_Base, $arrayadd)
   EndIf
ElseIf $2sellers = True Then
   Local $1row = _arraysearch($aArray_Base, "[Seller 1]")
   Local $2row = _arraysearch($aArray_Base, "[Seller 2]")
    $arrayadd[0][0] = "[Seller1&2]"
    $arrayadd[0][1] = "" & $aArray_Base[$1row][1] & " and " & $aArray_Base[$2row][1]
   _arrayadd($aArray_Base, $arrayadd)
   EndIf
EndFunc

Func Signatures() ; Create labels and data to fill buyer/seller fields with data entered already
EndFunc

Func Acknowledge() ; Format and fill acknowledgements based on number and type of buyers and sellers
EndFunc

Func prep()
  local $oWord = _Word_Create() ; Create Application Object
   If @error Then
      Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Error creating application object. Script terminated.")
   EndIf
  local $filepath = "C:\Users\Randy\Dropbox\Doc Prep\_KNDS Doc Prep Wizard (windows only)\GWD - Seller(s) People - Experiment.docx" ; Select Template to open
  local $oDoc = _word_docopen($oWord, $filepath) ; Open template
   If @error Then
      Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Error opening template. Script terminated.")
   EndIf
   For $i = 1 to Ubound($aArray_Base) ; Find and replace all [Fields] from main array with data
      _Word_DocFindReplace($oDoc, "" & $aArray_base[$i-1][0], "" & $aArray_Base[$i-1][1])
         If @error Then
            $addfail[0][0] = $aArray_Base[$i-1][0]
            $addfail[0][1] = $aArray_Base[$i-1][1]
            _arrayadd($fail, $addfail)
   EndIf
Next
   _ArrayDisplay($fail, "Items not replaced")
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Completed Find and replace. Iterations: "&$i)
   _word_docsaveas($oDoc, @HomeDrive & @HomePath & "\Dropbox\Doc Prep\_KNDS Doc Prep Wizard (windows only)\___Completed\" & guictrlread($inputgf) & " - " & guictrlread($inputtype)) ; Save working document with GF number
      If @error Then
      Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Error saving deed document. Script terminated." & @CRLF &  "Make sure Dropbox is installed on the PC." & @CRLF & @CRLF & "Also make sure that the following filepath exists:" & @CRLF & @CRLF & @HomeDrive & @HomePath & "\Dropbox\Doc Prep\_KNDS Doc Prep Wizard (windows only)\___Completed\")
   EndIf
   Shellexecute("" & @homedrive & @homepath & "\Dropbox\Doc Prep\_KNDS Doc Prep Wizard (windows only)\___Completed\")
   MsgBox($MB_SYSTEMMODAL, "KNDS Doc Prep Wizard", "Documents successfully prepared." & @CRLF & "Please inspect the document and the invoice for any errors, then drag and drop them to the appropriate location to save dropbox space.")
EndFunc

 

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi all,

I figured it out. Sorry for the inconvenience. I was doing this:

Func Buyers()
If $2buyers = False Then ; [Buyer1&2] = [Buyer 1]
   local  $row = _arraysearch($aArray_Base, "[Buyer 1]")
   If $row = NOT -1 Then ; account for blank [Buyer 1] ; <================= ERROR IS HERE
   $arrayadd[0][0] = "[Buyer1&2]"
   $arrayadd[0][1] = $aArray_Base[$row][1]
   _arrayadd($aArray_Base, $arrayadd)

   $arrayadd[0][0] = "[Buyer 2]" ; Delete Buyer 2 if found
   $arrayadd[0][1] = ""
   _arrayadd($aArray_Base, $arrayadd)
   EndIf
ElseIf $2buyers = True Then ; [Buyer1&2] = [Buyer 1] and [Buyer 2]
   Local $1row = _arraysearch($aArray_Base, "[Buyer 1]")
   Local $2row = _arraysearch($aArray_Base, "[Buyer 2]")
    $arrayadd[0][0] = "[Buyer1&2]"
    $arrayadd[0][1] = "" & $aArray_Base[$1row][1] & " and " & $aArray_Base[$2row][1]
   _arrayadd($aArray_Base, $arrayadd)
EndIf
EndFunc

Using $row = NOT -1 was causing problems, although I'm not sure why. Using $row <> -1 fixed everything. Thanks anyway!

-Anoig

Edited by anoig

Share this post


Link to post
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

  • Similar Content

    • Jibberish
      By Jibberish
      Hi,
      I am automating the testing of a video player. I search a file for ".mp4" and want to create a GUI with radio buttons to select what video to play. The number of videos can change based on the user's library so this must be created automatically.  I have searched for how to accomplish this and there are several posts out there that help a little but I can't figure out the solution. I pulled the offending code from my main script and created the file below to make this easier to read. I am sure one of our experts here can help!
      #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Local $sMediaFile = "D:\MediaFiles\MediaFiles.txt" Local $iStrReturn = 0 Local $aText Local $aArrayFile Local $iMax = 6 ;Default number of Videos - 1 for the array counter Local $aVideoName[$iMax] = [0] Local $sCheckBox1 Local $iT = 0, $iVideoCount = 0, $iCount Local $ix = 0 Local $iy = 0 Local $idClose1 Const $iL = 10 ; Count from Left for GUI so all buttons line up ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read a list of video file names and create a GUI with Radio Buttons to select a single video. ; Problem: We don't know how many video names will be in the text file, so we can't hard code Case Statements & their variables ; Put the Video File Names into an Array _FileReadToArray($sMediaFile, $aArrayFile) For $a = 1 To $aArrayFile[0] ; Step through the array looking for .mp4 If StringInStr($aArrayFile[$a], ".mp4") Then $iVideoCount = $iVideoCount + 1 $aText = StringSplit($aArrayFile[$a],"\\") ; This video player reads double backslashes For $a1 = 1 to $aText[0] ; Check that the array is big enough If StringInStr($aText[$a1], ".mp4") Then ;MsgBox(0,"","Video is " & $aText[$a1]) If UBound($aVideoName) = $iVideoCount Then ; Resize the array when $iCount is equal to the element count in the array to prevent subscript error ReDim $aVideoName[$aVideoName[0] + $iMax] EndIf $aVideoName[$iVideoCount] = $aText[$a1]; add data to new index element $aVideoName[0] = $a1 ; update the index count for future reference ; The idea is to create a GUI width to accommodate long video file names $it = StringLen($aVideoName[$iVideoCount]) If $iT > $ix Then $ix = $iT EndIf EndIf Next EndIf Next ; Move backwards through the array deleting blank rows For $iCount = UBound($aVideoName) - 1 To 0 Step -1 If $aVideoName[$iCount] = "" Then _ArrayDelete($aVideoName, $iCount) EndIf Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Create the GUI - Names and Radio Button counts will vary - How do I do this? ; ;_ArrayDisplay($aVideoName) ;Local $aVarName[$aVideoName[0]] Local $iRows = UBound($aVideoName, $UBOUND_ROWS) $iRows = $iRows -1 $aVideoName[0] = $iRows ; Prep the GUI to display the FileNames with Radio Buttons - Can only select one at a time. $a = 0 $ix = $ix + 200 $iy = ($aVideoName[0] * 30) + 60 $hGUI = GUICreate("Videos", $ix, $iy) ;$iT = $iT+30 ; Create the variable names for the Case statement - Video count may change so Video Names displayed and GUICtrlCreateRadio count may change. ;~ For $a = 1 to $aVarName[0] ;~ If UBound($aVarName) = $aVarName Then ;~ ; Resize the array when $iCount is equal to the element count in the array to prevent subscript error ;~ ReDim $aVarName[$aVarName[0] + $iMax] ;~ EndIf ;~ Assign("$bVideoName" & $a, $a) ;~ Local $aVarName[$a] = Eval($bVideoName[$a]) ;~ ; $aVarName[$a] = GUICtrlCreateRadio($aVarName[$a], $iL, $iT) ;~ Next $iCount = 1 ;MsgBox(0,"","VideoName[0] is "&$aVideoName[0]) ;_ArrayDisplay($aVideoName) Local $bVideoName1 If $iCount < $aVideoName[0] Then $bVideoName1 = GUICtrlCreateRadio($aVideoName[$iCount], $iL, $iT) GUICtrlSetState($bVideoName1, $GUI_CHECKED) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0]) Then Local $bVideoName2 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0]) Then Local $bVideoName3 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0]) Then Local $bVideoName4 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0] -1) Then Local $bVideoName5 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0] -1) Then Local $bVideoName6 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0] -1) Then Local $bVideoName7 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iT = $iT + 30 $idClose1 = GUICtrlCreateButton("Go!", $iL, $iT) GUISetState(@SW_SHOW) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Switch Statement ; ;Local $nMsg = "" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $bVideoName1 Case $bVideoName2 Case $bVideoName3 Case $bVideoName4 Case $bVideoName5 ;Case $bVideoName6 <- Fails because there are only 5 videos - Need variable $bVideoNames ;Case $bVideoName7 <- Fails because there are only 5 videos Case $idClose1 $bVideoName1 = GUICtrlRead($bVideoName1) $bVideoName2 = GUICtrlRead($bVideoName2) $bVideoName3 = GUICtrlRead($bVideoName3) $bVideoName4 = GUICtrlRead($bVideoName4) $bVideoName5 = GUICtrlRead($bVideoName5) ;$bVideoName6 = GUICtrlRead($bVideoName6) ;$bVideoName7 = GUICtrlRead($bVideoName7) ExitLoop EndSwitch WEnd GUIDelete($nMsg) MsgBox(0,"","Case " & $nMsg & " was selected.") ; Always returns 8. ??? This is the "MediaFiles.txt" file I am reading:
      D:\\MediaFiles\\BigBuckBunny.mp4 D:\\MediaFiles\\BigBuckBunny60fps.mp4 D:\\MediaFiles\\Sintel.mp4 D:\\MediaFiles\\sintel-2048-surround.mp4 D:\\MediaFiles\\TearsOfSteel.mp4 D:\\MediaFiles\\tearsofsteel_4K.mp4 I'm sure I have several mistakes (or poor coding methods) in my AutoIt file.
    • Jibberish
      By Jibberish
      I am trying to add data to an array and I keep getting the error "Subscript used on non-accessible variable ".
      #include <array.au3> ; Includes, etc ~ ~ ~ Local $aOptionsArray[3] $aOptionsArray = CheckboxesAndRadioButtons() _ArrayDisplay($aOptionsArray) Func CheckboxesAndRadioButtons() ; Create Checkboxes and Radio Buttons and read the results ~ ~ ~ ; Radio Buttons to Array ; $aOptions[0] = $bTestSelectForever ; $aOptions[1] = $bTestSelect3Times ; $aOptions[2] = $bTestSelectOnce If $bSelect1 = 1 Then $aOptions[0] = "True" Else $aOptions[0] = "False" <<< This is where the error occurs. EndIf If $bSelect2 = 1 Then $aOptions[1] = "True" Else $aOptions[1] = "False" EndIf If $bSelect3 = 1 Then $aOptions[2] = "True" Else $aOptions[2] = "False" EndIf Return $aOptions EndFunc Is putting data into an array while in a If - Then - Else illegal?
    • Skeletor
      By Skeletor
      Hi All,
      I know many newbies search for this feature.
      I decided to share this piece of code with everyone.
      Basically its a "splash screen" that has a transparent image.
      In a nutshell - Gui with a transparent gif.
      Enjoy...
      Download attachment....
       
      Splash Screen GUI.zip
    • Skeletor
      By Skeletor
      Hi Developers,
       
      While trying to find a way to actually style/skin the GUICtrlCreateTabItem, I read the help file and stated:
      My question to you guys is will this be updated? or am I hoping for something that will never come to pass?
      I've seen scripts between 2007 to 2009 allowing the tabs to be modified
      Reason for my question is I'm trying to make my GUI Tabs look more modern.
      Thanks in advance for reading my post.
       
    • Jibberish
      By Jibberish
      I am trying to get the results of a radio button selection. I have tried implementing sample scripts but to no avail.
      Can someone tell / show me what I am doing wrong?
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Local $bSelect1 Local $bSelect2 Local $bSelect3 SelectButton() ;The results of SelectButton is not being returned MsgBox(0,"","Select1 is "& $bSelect1 & ". Select2 is "& $bSelect2 & ". Select3 is "& $bSelect3 & ".") Func SelectButton() Local $hGUI = GUICreate("SGX4CP Tests", 300, 300) GUISetState() Local $bSelect1 = GUICtrlCreateRadio("Select 1", 10, 160) Local $bSelect2 = GUICtrlCreateRadio("Select 2", 10, 190) Local $bSelect3 = GUICtrlCreateRadio("Select 3", 10, 220) ; Set TestSelectForever as the default radio button GUICtrlSetState($bSelect1, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Start", 120,250) Local $idMsg While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE Or $idMsg = $idClose ExitLoop Case $idMsg = $bSelect1 And BitAND(GUICtrlRead($bSelect1), $GUI_CHECKED) = $GUI_CHECKED MsgBox(0,"","Select1") Case $idMsg = $bSelect2 And BitAND(GUICtrlRead($bSelect2), $GUI_CHECKED) = $GUI_CHECKED MsgBox(0,"","Select2") Case $idMsg = $bSelect3 And BitAND(GUICtrlRead($bSelect3), $GUI_CHECKED) = $GUI_CHECKED MsgBox(0,"","Select3") ; GUICtrlRead($hGUI) EndSelect WEnd MsgBox(0,"","Select1 is "& $bSelect1 & ". Select2 is "& $bSelect2 & ". Select3 is "& $bSelect3 & ".") ; Why is this returning numbers? EndFunc