Jump to content
kartune

array variable has incorrect number of subscripts

Recommended Posts

kartune

Hello, I am getting this error message when running my script:

Case $aButiD[0] To $aButiD[$iTotButtons - 1]

Case ^ ERROR

Error:  Array variable has incorrect number of subscripts or subscript dimension range exceeded.

 

The script's purpose is to read my ini file and create buttons for the sections and section contents.

The first part of the script creates buttons for the sections of the ini, once you click on the section button it should open another set of buttons of all the contents under the section

In this case, the section in the .ini file is called "TPA"

on the Func flavorco()

It opens the contents of "TPA" into buttons.

Right now, the section it is reading is determined by $sSection.

It is only when I try to change $sSection = "TPA"

to

$sSection = $flavorco

that the error starts to appear

 

Here is the script

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




$optbar = IniReadSectionNames("test.ini")
If Not IsArray($optbar) Then Exit
Local $Button[UBound($optbar) - 1]

$mGUI = GUICreate('Restock Flavor Ingredients', 10 + (130 * UBound($optbar)), 100)

For $x = 1 To UBound($optbar) - 1
    $var = IniReadSection("test.ini", $optbar[$x])
    If @error Then ContinueLoop
    $X_Coord = 10 + (($x - 1) * 100)
    $Button[$x - 1] = GUICtrlCreateButton($optbar[$x], $X_Coord, 30, 70, 30)
Next
GUISetState()

While 1
    $mMsg = GUIGetMsg()
    If $mMsg = $GUI_EVENT_CLOSE Then
       GUIDelete($mGUI)
       ExitLoop
       EndIf
    For $i = 0 To UBound($Button) - 1
        If $mMsg = $Button[$i] Then
            MsgBox(0, '$Msg = ' & $mMsg, GuiCtrlRead($Button[$i]) & ' Pressed', 2)
            Global $flavorco = $Button ; sets the flavor company's variable
            Call('flavorco')
         EndIf
    Next
 WEnd



Func flavorco() ;opened flavor company's flavors
   MsgBox(0, '$Msg = ' & $mMsg, GuiCtrlRead($Button[$i]) & $flavorco, 0)
Local $sFilePath = @ScriptDir & "\Test.ini"
Local $sSection = $Button
Local $aArray = IniReadSection($sFilePath, $sSection)
_ArrayDelete($aArray, 0)
;_ArrayDisplay($aArray)

Local $iIndex
Local $iTotButtons = UBound($aArray)
Local $iNumPerRow = 5
Local $iButWidth = 100
Local $iButDepth = 30
Local $aButiD[$iTotButtons]
Local $hGUI = GUICreate('Ingredients Stock "' & $sFilePath & '"', 10 + ($iButWidth + 10) * $iNumPerRow, _
                                                             10 + Ceiling($iTotButtons / $iNumPerRow) * ($iButDepth + 10), -1, $WS_EX_TOPMOST)
For $i = 0 To $iTotButtons - 1
    ; $x = $iXBorder + (($iRectWidth + $iSpacing) * Mod($i, $iNumCols))
    $x = 10 + (($iButWidth + 10) * Mod($i, $iNumPerRow))

    ; $y = $iYBorder + (($iRectDepth + $iSpacing) * Int($i / $iNumCols))
    $y = 10 + (($iButDepth + 10) * Int($i / $iNumPerRow))

    $aButiD[$i] = GUICtrlCreateButton($aArray[$i][0], $x, $y, $iButWidth, $iButDepth) ;, $BS_NOTIFY)
Next

GUISetState(@SW_SHOW)

While 1
   $msg = GUIGetMsg()
    Switch $msg
       Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            ExitLoop

         Case $aButiD[0] To $aButiD[$iTotButtons - 1] ;clicking on a flavor name
            $iIndex = ($msg - $aButiD[0])
            $RSINGRflavor = $aArray[$iIndex][0] ;flavor name
            $RSINGRml = $aArray[$iIndex][1] ; ml
            $RSINGRgal = $aArray[$iIndex][1]*0.000264172 ;converts ml to gal
            Call('openflavor')
      EndSwitch
WEnd
EndFunc


Func openflavor()
                #Region ### START Koda GUI section ### Form=F:\Karl\AutoIt\FJ-Stock JP\GUI Forms\RSINGRSUBFORM.kxf ;opens flavor to view stock and restock submit
                $RSINGRSUBFORM = GUICreate($sSection & " " & $RSINGRflavor, 242, 213, 530, 269)
                $RSINGRFlavorTitle = GUICtrlCreateLabel($sSection & " " & $RSINGRflavor, 32, 8, 200, 28)
                GUICtrlSetFont(-1, 16, 800, 0, "MS Sans Serif")
                $RSINGRstockcaption = GUICtrlCreateLabel("Current Stock in ml:", 16, 48, 96, 17)
                $RSINGRstockml = GUICtrlCreateLabel($RSINGRml, 120, 48, 114, 25)
                GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
                $RSINGRInput = GUICtrlCreateInput("ml", 40, 112, 153, 21)
                $RSINGRSUBMIT = GUICtrlCreateButton("SUBMIT", 16, 152, 81, 33)
                $RSINGRCLOSE = GUICtrlCreateButton("CLOSE", 145, 151, 81, 33)
                $RSINGRgalcaption = GUICtrlCreateLabel("Current Stock in gal:", 16, 80, 97, 17)
                $RSINGRstockgal = GUICtrlCreateLabel($RSINGRGAL, 120, 80, 114, 25)
                GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
                GUISetState(@SW_SHOW)
                #EndRegion ### END Koda GUI section ###
         ;   $msg = ""

While 1

$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete($RSINGRSUBFORM)
            ExitLoop

         Case $RSINGRCLOSE
            GUIDelete($RSINGRSUBFORM)
            ExitLoop

    EndSwitch
WEnd
EndFunc

 

Any help is much appreciated!  Thanks.

My guess is that $Button isn't an actual string??  Whenever I use msgbox it shows up the string exactly, no numbers attached.  So i'm not sure whats going on here.

Share this post


Link to post
Share on other sites
Earthshine

it does not even compile.

>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\root\Desktop\test.au3
"C:\Users\root\Desktop\test.au3"(90,54) : warning: $sSection: possibly used before declaration.
                $RSINGRSUBFORM = GUICreate($sSection &
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\root\Desktop\test.au3"(90,75) : warning: $RSINGRflavor: possibly used before declaration.
                $RSINGRSUBFORM = GUICreate($sSection & " " & $RSINGRflavor,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\root\Desktop\test.au3"(94,62) : warning: $RSINGRml: possibly used before declaration.
                $RSINGRstockml = GUICtrlCreateLabel($RSINGRml,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\root\Desktop\test.au3"(100,64) : warning: $RSINGRGAL: possibly used before declaration.
                $RSINGRstockgal = GUICtrlCreateLabel($RSINGRGAL,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\root\Desktop\test.au3"(90,54) : error: $sSection: undeclared global variable.
                $RSINGRSUBFORM = GUICreate($sSection &
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\root\Desktop\test.au3"(90,75) : error: $RSINGRflavor: undeclared global variable.
                $RSINGRSUBFORM = GUICreate($sSection & " " & $RSINGRflavor,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\root\Desktop\test.au3"(94,62) : error: $RSINGRml: undeclared global variable.
                $RSINGRstockml = GUICtrlCreateLabel($RSINGRml,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\root\Desktop\test.au3"(100,64) : error: $RSINGRGAL: undeclared global variable.
                $RSINGRstockgal = GUICtrlCreateLabel($RSINGRGAL,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\root\Desktop\test.au3 - 4 error(s), 4 warning(s)
!>14:52:09 AU3Check ended. Press F4 to jump to next error.rc:2
+>14:52:09 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.647

I am not updating autoit until the teething pains are gone for good.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
JLogan3o13

@kartune before you work on the buttons, I would look at some of the other issues. You're declaring local variables in one function, which are then not available in another. Are you using the full version of SciTE with AU3Check?

Edit: see example above

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
kartune

Sorry, i just noticed that and corrected it, I am using:
SciTE-Lite  
Version 3.5.4 
    Sep 18 2015 15:04:36

I will check out the full version and au3check now.
Here is the revised code:

 

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




$optbar = IniReadSectionNames("test.ini")
If Not IsArray($optbar) Then Exit
Local $Button[UBound($optbar) - 1]

$mGUI = GUICreate('Restock Flavor Ingredients', 10 + (130 * UBound($optbar)), 100)

For $x = 1 To UBound($optbar) - 1
    $var = IniReadSection("test.ini", $optbar[$x])
    If @error Then ContinueLoop
    $X_Coord = 10 + (($x - 1) * 100)
    $Button[$x - 1] = GUICtrlCreateButton($optbar[$x], $X_Coord, 30, 70, 30)
Next
GUISetState()

While 1
    $mMsg = GUIGetMsg()
    If $mMsg = $GUI_EVENT_CLOSE Then
       GUIDelete($mGUI)
       ExitLoop
       EndIf
    For $i = 0 To UBound($Button) - 1
        If $mMsg = $Button[$i] Then
            MsgBox(0, '$Msg = ' & $mMsg, GuiCtrlRead($Button[$i]) & ' Pressed', 2)
            Global $flavorco = $Button ; flavor company
            Call('flavorco')
         EndIf
    Next
 WEnd



Func flavorco() ;opened flavor companys flavors
   MsgBox(0, '$Msg = ' & $mMsg, GuiCtrlRead($Button[$i]) & $flavorco, 0)
Global $sFilePath = @ScriptDir & "\Test.ini"
Global $sSection = "TPA"
Global $aArray = IniReadSection($sFilePath, $sSection)
_ArrayDelete($aArray, 0)
;_ArrayDisplay($aArray)

Global $iIndex
Global $iTotButtons = UBound($aArray)
Global $iNumPerRow = 5
Global $iButWidth = 100
Global $iButDepth = 30
Global $aButiD[$iTotButtons]
Global $hGUI = GUICreate('Ingredients Stock "' & $sFilePath & '"', 10 + ($iButWidth + 10) * $iNumPerRow, _
                                                             10 + Ceiling($iTotButtons / $iNumPerRow) * ($iButDepth + 10), -1, $WS_EX_TOPMOST)
For $i = 0 To $iTotButtons - 1
    ; $x = $iXBorder + (($iRectWidth + $iSpacing) * Mod($i, $iNumCols))
    $x = 10 + (($iButWidth + 10) * Mod($i, $iNumPerRow))

    ; $y = $iYBorder + (($iRectDepth + $iSpacing) * Int($i / $iNumCols))
    $y = 10 + (($iButDepth + 10) * Int($i / $iNumPerRow))

    $aButiD[$i] = GUICtrlCreateButton($aArray[$i][0], $x, $y, $iButWidth, $iButDepth) ;, $BS_NOTIFY)
Next

GUISetState(@SW_SHOW)

While 1
   $msg = GUIGetMsg()
    Switch $msg
       Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            ExitLoop

         Case $aButiD[0] To $aButiD[$iTotButtons - 1] ;clicking on a flavor name
            $iIndex = ($msg - $aButiD[0])
            Global $RSINGRflavor = $aArray[$iIndex][0] ;flavor name
            Global $RSINGRml = $aArray[$iIndex][1] ; ml
            Global $RSINGRgal = $aArray[$iIndex][1]*0.000264172 ;converts ml to gal
            Call('openflavor')
      EndSwitch
WEnd
EndFunc








Func openflavor()
                #Region ### START Koda GUI section ### Form=F:\Karl\AutoIt\FJ-Stock JP\GUI Forms\RSINGRSUBFORM.kxf ;opens flavor to view stock and restock submit
                $RSINGRSUBFORM = GUICreate($sSection & " " & $RSINGRflavor, 242, 213, 530, 269)
                $RSINGRFlavorTitle = GUICtrlCreateLabel($sSection & " " & $RSINGRflavor, 32, 8, 200, 28)
                GUICtrlSetFont(-1, 16, 800, 0, "MS Sans Serif")
                $RSINGRstockcaption = GUICtrlCreateLabel("Current Stock in ml:", 16, 48, 96, 17)
                $RSINGRstockml = GUICtrlCreateLabel($RSINGRml, 120, 48, 114, 25)
                GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
                $RSINGRInput = GUICtrlCreateInput("ml", 40, 112, 153, 21)
                $RSINGRSUBMIT = GUICtrlCreateButton("SUBMIT", 16, 152, 81, 33)
                $RSINGRCLOSE = GUICtrlCreateButton("CLOSE", 145, 151, 81, 33)
                $RSINGRgalcaption = GUICtrlCreateLabel("Current Stock in gal:", 16, 80, 97, 17)
                $RSINGRstockgal = GUICtrlCreateLabel($RSINGRGAL, 120, 80, 114, 25)
                GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
                GUISetState(@SW_SHOW)
                #EndRegion ### END Koda GUI section ###
         ;   $msg = ""

While 1

$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete($RSINGRSUBFORM)
            ExitLoop

         Case $RSINGRCLOSE
            GUIDelete($RSINGRSUBFORM)
            ExitLoop

    EndSwitch
WEnd
EndFunc

 

Edited by kartune

Share this post


Link to post
Share on other sites
kartune
2 minutes ago, JLogan3o13 said:

Can you please provide an example of your test.ini?

sure thing, here it is:

 

[VG]
ml=0

[PG]
ml=0

[TPA]
Apple Candy=100
Bavarian Cream=0
Berry Cereal=0
Blueberry=0
Citrus Punch=0
Clove=0
Coconut Extra=0
Energy Drink=0
Fruit Circles=0
Ginger Ale=0
Graham Cracker Clear=0
Hawaiian Drink=0
Honey Dew=0
Kiwi=0
Menthol=0
MType=0
Papaya=0
Peach=0
Peppermint=0
Ry4=0
Tiramisu=0
Toasted Almond=0
Tobacco=0
Vanilla Bean Ice Cream=0
Vanilla Swirl=0
Watermelon=0
Western=0


[JP]
Condensed Milk=0
Garikun=0
Honey Dew=0
Kiwi=0
Matcha=0
Melon Cream Soda=0
Peach=0
Pineapple=0
Strawberry=0
Umeshu=0
Yogurt=0
MType=-0


[CAP]
Honey Dew=0
Vanilla Custard=0


[FA]
Fresh Cream=0
Meringue=0
Seven Leaves=0
Bavarian Cream=0

[INA]
Biscuit=0


(Scroll Up)

Share this post


Link to post
Share on other sites
JLogan3o13

Thanks, will take a look.

In the future you could just attach a file, a lot easier than making someone save it off :) 


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
kartune
Just now, JLogan3o13 said:

Thanks, will take a look.

In the future you could just attach a file, a lot easier than making someone save it off :) 

Thanks, i will remember that :), new to this forum and also coding.  Most of my code is copy pasted and then edited.

Share this post


Link to post
Share on other sites
Subz

To read the button text you need to use:

Global $flavorco = GUICtrlRead($Button[$i])

Then you can use $sSection = $Flavorco

Share this post


Link to post
Share on other sites
kartune

It works!!! Thanks a lot guys!

I'm so grateful for this forum and the members :D

Share this post


Link to post
Share on other sites
Subz

No problem, overall code is quite good, Just a couple of pointers, regarding best practice for variables:

  • You shouldn't declare Global variables within functions.
  • Global variables should only be declared if being used between multiple functions (as JLogan pointed out above)
  • Prefixing your variables helps with identifying the variable type see https://www.autoitscript.com/wiki/Best_coding_practices

Quick Example:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $sSection
Global $sFilePath = @ScriptDir & "\Test.ini"

MainGui()

Func MainGui()
    Local $aOptionBar = IniReadSectionNames($sFilePath)
        If @error Then Exit
    Local $aButton[$aOptionBar[0]]
    Local $hMainGui = GUICreate('Restock Flavor Ingredients', 10 + (130 * UBound($aOptionBar)), 100)

    For $i = 1 To $aOptionBar[0]
        IniReadSection("test.ini", $aOptionBar[$i])
            If @error Then ContinueLoop
        $iX_Coord = 10 + (($i - 1) * 100)
        $aButton[$i - 1] = GUICtrlCreateButton($aOptionBar[$i], $iX_Coord, 30, 70, 30)
    Next

    GUISetState()

    While 1
        $nMainMsg = GUIGetMsg()
        Switch $nMainMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($hMainGui)
                ExitLoop
            Case $aButton[0] To $aButton[UBound($aButton) - 1]
                $sSection = GUICtrlRead($nMainMsg)
                flavorco() ; flavor company
        EndSwitch
     WEnd
EndFunc

Func flavorco() ;opened flavor companys flavors
    Local $x, $y
    Local $aFlavors = IniReadSection($sFilePath, $sSection)
    _ArrayDelete($aFlavors, 0)
    Local $iIndex
    Local $iTotButtons = UBound($aFlavors)
    Local $iNumPerRow = 5
    Local $iButWidth = 100
    Local $iButDepth = 30
    Local $aButiD[$iTotButtons]
    Local $hFlavors = GUICreate('Ingredients Stock "' & $sFilePath & '"', 10 + ($iButWidth + 10) * $iNumPerRow, 10 + Ceiling($iTotButtons / $iNumPerRow) * ($iButDepth + 10), -1, $WS_EX_TOPMOST)
    For $i = 0 To $iTotButtons - 1
        $x = 10 + (($iButWidth + 10) * Mod($i, $iNumPerRow))
        $y = 10 + (($iButDepth + 10) * Int($i / $iNumPerRow))
        $aButiD[$i] = GUICtrlCreateButton($aFlavors[$i][0], $x, $y, $iButWidth, $iButDepth)
    Next

    GUISetState(@SW_SHOW)

    While 1
        $nFlavorCoMsg = GUIGetMsg()
        Switch $nFlavorCoMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($hFlavors)
                ExitLoop
            Case $aButiD[0] To $aButiD[$iTotButtons - 1] ;clicking on a flavor name
                $iIndex = ($nFlavorCoMsg - $aButiD[0])
                openflavor($aFlavors[$iIndex][0], $aFlavors[$iIndex][1], $aFlavors[$iIndex][1]*0.000264172)
        EndSwitch
    WEnd
EndFunc

Func openflavor($sRSINGRflavor, $iRSINGRml, $iRSINGRgal)
    #Region ### START Koda GUI section ### Form=F:\Karl\AutoIt\FJ-Stock JP\GUI Forms\RSINGRSUBFORM.kxf ;opens flavor to view stock and restock submit
        Local $nRSINGRmsg
        Local $hRSINGRSUBFORM = GUICreate($sSection & " " & $sRSINGRflavor, 242, 213, 530, 269)
        GUICtrlCreateLabel($sSection & " " & $sRSINGRflavor, 32, 8, 200, 28)
            GUICtrlSetFont(-1, 16, 800, 0, "MS Sans Serif")
        GUICtrlCreateLabel("Current Stock in ml:", 16, 48, 96, 17)
        GUICtrlCreateLabel($iRSINGRml, 120, 48, 114, 25)
            GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        Local $idRSINGRInput = GUICtrlCreateInput("ml", 40, 112, 153, 21)
        Local $idRSINGRSUBMIT = GUICtrlCreateButton("SUBMIT", 16, 152, 81, 33)
        Local $idRSINGRCLOSE = GUICtrlCreateButton("CLOSE", 145, 151, 81, 33)
        GUICtrlCreateLabel("Current Stock in gal:", 16, 80, 97, 17)
        GUICtrlCreateLabel($iRSINGRgal, 120, 80, 114, 25)
            GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    #EndRegion ### END Koda GUI section ###

    GUISetState(@SW_SHOW)

    While 1
        $nRSINGRmsg = GUIGetMsg()
        Switch $nRSINGRmsg
            Case $GUI_EVENT_CLOSE, $idRSINGRCLOSE
                GUIDelete($hRSINGRSUBFORM)
                ExitLoop
        EndSwitch
    WEnd
EndFunc

 

Share this post


Link to post
Share on other sites
kartune

Thank you!  I am going to clean up my coding as I learn more and practice :).

 

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

    • XinYoung
      By XinYoung
      Hello all! I hope everyone is enjoying their holiday festivities. 
      I'm working on a script that involves copying a string of text from an Excel workbook and searching for it in a particular website's search tool. If a result is found, it will do something. If not, it will do something else.
      So far, it can successfully execute the search -- and then it shows me the results in an array.
      Screenshot of the successful search:

      The search results in an array:

       
      Here's the code (sorry for all my comments):
      ;~ All the functions this app performs require the external files listed here. So, theyre "included". #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <File.au3> #include <Excel.au3> #include <DateTimeConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIShellEx.au3> #include <Date.au3> #include <ComboConstants.au3> #include <Misc.au3> #include <WinAPIProc.au3> #include <WinAPISys.au3> #include <WinAPIConstants.au3> #include <Crypt.au3> #include <ColorConstants.au3> #include <guimenu.au3> #include <IE.au3> ;~ Kill all functions and close the app at anytime by pressing F4. HotKeySet("{F4}", "_Exit") ;~ Keep track whether or not a file is selected. When the program first opens, a file is currently not selected. Global $FileChosen = 0 ;~ The app must remember certain strings of text: ;~ 1. Login page Global $urlBBLogin = "website.com" ;~ 2. Credentials Global $bbUsername = "USER" Global $bbPassword = "PW" ;~ 3. Search page Global $urlBBCourseSearch = "website.com/search" ;~ When you launch the app, the UI gets built and is displayed to the user in the center of the screen. the "Function" buttons are disabled until a file is chosen. $MasterUI = GUICreate("Master Re-Creator", 469, 145, -1, -1) $Label1 = GUICtrlCreateLabel("Choose the Excel file", 8, 8, 103, 17) $Select = GUICtrlCreateButton("Select File", 16, 32, 75, 25) $FileName = GUICtrlCreateLabel("[No File Selected]", 104, 40, 88, 17) $Group1 = GUICtrlCreateGroup("Functions", 8, 72, 449, 65) $CheckCourse = GUICtrlCreateButton("Check Courses Exist", 24, 96, 123, 25) GUICtrlSetState(-1, $GUI_DISABLE) $DeleteCourse = GUICtrlCreateButton("Delete Courses", 168, 96, 123, 25) GUICtrlSetState(-1, $GUI_DISABLE) $CopyCourse = GUICtrlCreateButton("Copy Courses", 312, 96, 123, 25) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) ;~ While the UI is open, it listens for triggers (in this case, button presses). While 1 $UI = GUIGetMsg() Select ;~ If the app is closed, the _Exit() function is performed (same function the F4 hotkey calls). Case $UI = $GUI_EVENT_CLOSE _Exit() ;~ The user has clicked the "Select File" button, the _LocateGetFileName() function is performed. Go there. Case $UI = $Select _LocateGetFileName() ;~ The user has clicked the "Check Courses Exist" button. Case $UI = $CheckCourse _CheckCourses() ;~ Other buttons are not ready EndSelect WEnd ;~ The user clicked the "Select File" button. This function will execute now. Func _LocateGetFileName() ;~ Prepare the app to take note of the details of a file. Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" ;~ Open a File Explorer to allow the user to select a file. Only Excel files are allowed to be chosen. Global $ChosenFileName = FileOpenDialog("Locate File", @DesktopDir, "Excel Files (*.xlsx)|Excel Macro Files (*.xlsm)", BitOR(1, 2), "") If @error Then Return 0 EndIf ;~ When an Excel file is selected, remember of the files location (path), file name, and file extension. $aPathSplit = _PathSplit($ChosenFileName, $sDrive, $sDir, $sFileName, $sExtension) ;~ Show me what file I selected in a Message Box. MsgBox(0, "Selected File", $sFileName) ;~ Display the chosen file name in the UI label (previously [No File Selected]) and make it green. GUICtrlSetData($FileName, "") $FileName = GUICtrlCreateLabel($sFileName, 104, 40) $FileName = GUICtrlSetColor($FileName, 0x32CD32) ;~ A file is now selected. The "Function" buttons are now enabled. Global $FileChosen = 1 GUICtrlSetState($CheckCourse, $GUI_ENABLE) GUICtrlSetState($DeleteCourse, $GUI_ENABLE) GUICtrlSetState($CopyCourse, $GUI_ENABLE) EndFunc ;==>_LocateGetFileName ;~ The user clicked the "Check Courses" button. This function will execute now. Func _CheckCourses() ;~ Disable the "Function" buttons again to prevent multiple processes. GUICtrlSetState($CheckCourse, $GUI_DISABLE) GUICtrlSetState($DeleteCourse, $GUI_DISABLE) GUICtrlSetState($CopyCourse, $GUI_DISABLE) ;~ Open a IE window and navigate to the login page. Global $oIE = _IECreate($urlBBLogin) ;~ Recognize the form on this page (login input boxes). Local $oForm = _IEFormGetObjByName($oIE, "login") Local $oTextLogin = _IEFormElementGetObjByName($oForm, "user_id") Local $oTextPass = _IEFormElementGetObjByName($oForm, "password") ;~ Enter the Automation user credentials into the form. _IEFormElementSetValue($oTextLogin, $bbUsername) _IEFormElementSetValue($oTextPass, $bbPassword) ;~ Click the Login button. _IEFormSubmit($oForm) ;~ Now that were logged in, navigate to the course search page. _IENavigate($oIE, $urlBBCourseSearch) ;~ Change the search criteria to "Course ID" _bbCourseSearchCategoryChange("Course ID") ;~ Open the selected Excel file Local $oAppl = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oAppl, $ChosenFileName, Default, Default, True) ;~ Copy just whats in cell A1 (for now) _Excel_RangeCopyPaste($oWorkbook.Worksheets(1), "A1") Global $WhatsCopied = ClipGet() ;~ Paste whats copied into the search text box and click submit Local $oForm = _IEGetObjByName($oIE, "courseManagerFormSearch") Local $oSearchString = _IEFormElementGetObjByName($oForm, "courseInfoSearchText") _IEFormElementSetValue($oSearchString, $WhatsCopied) _IEFormSubmit($oForm) ;~ Lets see what we got from the search Local $oBBTable = _IETableGetCollection($oIE, 2) Local $aBBTableData = _IETableWriteToArray($oBBTable) _ArrayDisplay($aBBTableData) EndFunc ;==>_CheckCourses ;~ This function allows changing the search criteria. Func _bbCourseSearchCategoryChange($sCategoryToSearch) Local $aSearchCategory[6] = ["Course ID", "Course Name", "Description", "Instructor", "Data Source Key", "Term"] Local $oForm = _IEGetObjByName($oIE, "courseManagerFormSearch") Local $oSearchCategory = _IEGetObjByName($oForm, "courseInfoSearchKeyString") _IEAction($oSearchCategory, "focus") _IEFormElementOptionSelect($oSearchCategory, $aSearchCategory[$sCategoryToSearch], 1, "byText") EndFunc ;==>_bbCourseSearchCategoryChange ;~ All exit commands, including F4, calls this function Func _Exit() Exit EndFunc ;==>_Exit  
      My main question is: How do I create an If... Then based on what is found in the search results? I need additional tasks to run if Col 1, Row 2 in the array contains the exact string I searched for. (Am I going about this the right way?)
      My next question (I might make a new thread for): How do I make the whole thing loop, as in, copy the next cell in the Excel sheet and do the whole thing over again until there's no more? I understand that a For/Next loop thingy would be used. I just don't know how. Loops are really confusing to me.
      Thank you all for your guidance and have a happy new year!
    • nooneclose
      By nooneclose
      I need help turning this string "20180913221626" into a formatted time string.
      I need to go from this: 20180913221626
      to this: 09/13/2018 10:16 PM
      I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 
      I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 
      As always any help would be appreciated. 
      Here is the code I use to find the date, but it always gives me the unformatted version. 
      ;retrieve the items object $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default) $oItem.GetInspector $eSentOn = $oItem.SentOn ; When was the email sent? MsgBox("", "Sent On of the email", $eSentOn) ;******************************************************************************* ; Formats the date and time from the email ;******************************************************************************* ;Local $fDatenTime = _DateTimeFormat($eSentOn, 1) ;MsgBox("", "Formatted email time", $fDatenTime) $aProperties = _AD_GetObjectProperties($eSentOn) _ArrayDisplay($aProperties, "Did the conversion work?")  
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
    • Rskm
      By Rskm
      Hi, I have the following line in a text file 'input.txt'. I know the line number - say '6'. I wish to replace the text 'WWW' in the below line with a random number (I can generate that with random()).
      WERIS  WWWJP   3.83  8.330  1.000                1097.RAXX 
      The WWW is a 3 digit integer (could be any number between 0 to 999), I can use stringtrimleft and get the numerical value of WWW in this file
      so, basically, I know the string to replace (ie; WWW stored in a variable), I know the line number to work on and the file location/name and the replacement variable (through random()). My requirement is to fill that 3 spaces with my random number (which Is a integer between 1 and 999)
      please put ur suggestions
       
×