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
Posted (edited)

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
Posted (edited)

@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!

Share this post


Link to post
Share on other sites
kartune
Posted (edited)

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
JLogan3o13

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


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

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!

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

    • 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
       
    • nacerbaaziz
      By nacerbaaziz
      Hello Members of this best Forum
      i have a question please
      for example if i have a long string
      and i want to extract a text between two tag
      what i can do to make that?
      note :
      i know that there is a
      StringRegExp function
      it's do that work
      but it result is be as an array
      i want the result to be a string
      is there any function on autoit can do that?
      Thanks in advance.
    • mistersquirrle
      By mistersquirrle
      Hello!
       
      I wrote myself a script to follow Google Maps Polyline encoding steps: https://developers.google.com/maps/documentation/utilities/polylinealgorithm, and that works (although I think that it's a bit janky), but now I'm having issues getting the output.
       
      When I run the script, all the points come out correctly in the console, and even when they're the only things that I log, it displays them fine. However, I'm adding each point into a variable to return all of them at once at the end, fully formatted, and it's only taking the very first point. I can't figure out what I'm doing wrong, as it seems fine.
       
      When run with the default value, it should output this at the end: Custom Polygon: _p~iF~ps|U_ulLnnqC_mqNvxq`@
      But instead I'm just getting this: Custom Polygon: _p~iF
       
      I know that it's reaching the string combination lines because it's logging the data before it (and even if a put log AFTER the $sPolygon &= $aPoints[0], it's logged fine).
       
      Here's my full code (problem is lines ~209 - 234, search "$sPolygon &= $aPoints[1]"):
      #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> _PolyGUI() Func _PolyGUI() #Region ### START Koda GUI section ### Form= $hInputGUI = GUICreate("Lat Long encoder", 403, 301, 192, 124) GUISetFont(8, 400, 0, "Consolas") GUICtrlCreateLabel("Input polygon points here, format as:", 8, 8, 263, 19) GUICtrlSetFont(-1, 10, 800, 0, "Consolas") GUICtrlCreateLabel("Lat Long - Single point", 8, 24, 142, 17) GUICtrlCreateLabel("Lat Long, Lat Long, Lat Long - Multiple points", 8, 40, 280, 17) Local $sPoints = GUICtrlCreateEdit("", 8, 64, 385, 201, BitOR($ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetData(-1, "38.5 -120.2, 40.7 -120.95, 43.252 -126.453") GUICtrlSetFont(-1, 10, 400, 0, "Consolas") $bOK = GUICtrlCreateButton("bOK", 16, 272, 123, 25) GUICtrlSetFont(-1, 12, 800, 0, "Consolas") $bCancel = GUICtrlCreateButton("bCancel", 304, 272, 75, 25) GUICtrlSetFont(-1, 12, 800, 0, "Consolas") GUISetState(@SW_SHOW, $hInputGUI) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $bCancel Exit Case $bOK $sPoints = GUICtrlRead($sPoints) GUISetState(@SW_HIDE, $hInputGUI) _GetPoly($sPoints, True) ExitLoop EndSwitch Sleep(10) WEnd EndFunc ;==>_PolyGUI ;https://developers.google.com/maps/documentation/utilities/polylinealgorithm ;https://app.dsmobileidx.com/api/DescribeSearchForLinkId?linkId=469787 ; Note that this will only really work inside the US (this side of the World), as it's assuming any negative is the Longitude ;https://gist.github.com/ismaels/6636986 - decoder ;Using: 41.83162 -87.64696 ; Expected: sfi~F np}uO ; Actual: sfi~f np}uo ; If we remove 32 from the last ASCII code, since the last bit chunk is 0, we get the correct case/ characters ; We need to run this logic back through all the indexes though and do this to all that that <= 63 ;LinkId=469787 ; Expected: q{`aHpa_iVi[kp@}`Aa{@e[eCoqBbAyc@iRy{@g_@mz@|gA{eAh~@Vf~Etv@gB~p@gQ`^yg@~p@ekAldA{KfFxIrJ^pO~Mtl@dPrJnUz[nSpo@wf@fc@yw@n@ob@ ; Actual: s{`aHpa_iVg[kp@}`Aa{@g[gCmqBbA{c@iRy{@e_@kz@|gA{eAh~@Td~Evv@gB|p@gQb^wg@|p@ekAndA{KfFvIpJ`@rO~Mrl@dPrJnU|[lSpo@wf@dc@yw@n@mb@ ; I assume that this is because of bad data, the points have repeating 9's and 0's, which looks fishy. The polygon is (very) close, but not quite the same. Func _GetPoly($sPoints, $bLog = False) Local $timer = TimerInit(), $sConsole[11] Local $sPolygon = "" ; Step 1, take the initial signed value: Local $aCoords = StringRegExp($sPoints, "(-*?\d*\.\d*) (-*?\d*\.\d*)", 3), $aPoints[2] ;~ _ArrayDisplay($aCoords) If $bLog Then _Log(_ArrayToString($aCoords)) For $c = 0 To (UBound($aCoords) - 1) Step 2 ;~ If $bLog Then _Log($c) If $c = 0 Then $aPoints[0] = $aCoords[$c] $aPoints[1] = $aCoords[$c + 1] Else $aPoints[0] = $aCoords[$c] - $aCoords[$c - 2] $aPoints[1] = $aCoords[$c + 1] - $aCoords[$c - 1] EndIf If $bLog Then _Log("- Step 1, take the initial signed value:") _Log(" " & $aPoints[0]) _Log(" " & $aPoints[1]) EndIf ; Step 2, multiply each by 1e5, and round $aPoints[0] = Round($aPoints[0] * 1e5, 0) $aPoints[1] = Round($aPoints[1] * 1e5, 0) If $bLog Then _Log("- Step 2, multiply each by 1e5, and round") _Log(" " & $aPoints[0]) _Log(" " & $aPoints[1]) EndIf ; Step 3, convert Decimal to Binary, using two's complement for negatives. Padded to 32 bits $aPoints[0] = _NumberToBinary($aPoints[0]) $aPoints[1] = _NumberToBinary($aPoints[1]) If $bLog Then _Log("- Step 3, convert Decimal to Binary, using two's complement for negatives. Padded to 32 bits") _Log(" " & $aPoints[0]) _Log(" " & $aPoints[1]) EndIf ; Step 4, left-shifted 1 bit $aPoints[0] = StringTrimLeft($aPoints[0], 1) & "0" $aPoints[1] = StringTrimLeft($aPoints[1], 1) & "0" If $bLog Then _Log("- Step 4, left-shifted 1 bit") _Log(" " & $aPoints[0]) _Log(" " & $aPoints[1]) EndIf ; Step 5, if negative, invert binary If $c = 0 Then If $aCoords[$c] < 0 Then $aPoints[0] = _InvertBinary($aPoints[0]) If $aCoords[$c + 1] < 0 Then $aPoints[1] = _InvertBinary($aPoints[1]) Else If $aCoords[$c] - $aCoords[$c - 2] < 0 Then $aPoints[0] = _InvertBinary($aPoints[0]) If $aCoords[$c + 1] - $aCoords[$c - 1] < 0 Then $aPoints[1] = _InvertBinary($aPoints[1]) EndIf If $bLog Then _Log("- Step 5, if negative, invert binary") _Log(" " & $aPoints[0]) _Log(" " & $aPoints[1]) EndIf Local $aChunks[2][6], $0x20 For $i = 0 To 1 $0x20 = "1" ; This is out BitOR flag, 0x20 BitOR'd onto our 5-bit chunks is always 1*****, except the last chunk $sConsole[5] = "" ; Clearing console variables $sConsole[6] = "" $sConsole[7] = "" $sConsole[8] = "" $sConsole[9] = "" For $j = 0 To 5 ;There will always be 6 chunks ; Step 6 & 7, break into 5-bit chunks, and reverse order $aChunks[$i][$j] = StringTrimLeft($aPoints[$i], StringLen($aPoints[$i]) - 5) ; This splits into 5-bit chunks in reverse order, doing 6 & 7 in one operation ;~ If $bLog Then _Log(" " & $aPoints[$i]) ;~ If $bLog Then _Log(" " & StringLen($aPoints[$i])) ;~ If $bLog Then _Log(" " & StringTrimLeft($aPoints[$i], StringLen($aPoints[$i]) - 5)) ;~ If $bLog Then _Log(" " & $aChunks[$i][$j]) ; Here we consume the original binary string, so the next loop gets the correct next 5-bit chunk $aPoints[$i] = StringTrimRight($aPoints[$i], 5) $sConsole[5] &= $aChunks[$i][$j] & " " ; Once consumed, if the remaining length isn't enough for another bit chunk, switch 0x20 to 0 (no following chunks) If StringLen($aPoints[$i]) <= 5 Then $0x20 = "0" ; Step 8, BitOR 100000 (0x20) to our 5-bit chunks (effectively) $aChunks[$i][$j] = $0x20 & $aChunks[$i][$j] $sConsole[7] &= $aChunks[$i][$j] & " " ; Step 9, converting the chunk from Binary back to Decimal $aChunks[$i][$j] = _BinaryToDec($aChunks[$i][$j]) $sConsole[8] &= $aChunks[$i][$j] & " " ; Step 10, adding 63 to decimal values $aChunks[$i][$j] += 63 $sConsole[9] &= $aChunks[$i][$j] & " " If StringLen($aPoints[$i]) < 5 Then ExitLoop Next If $bLog Then _Log("- Step 6 & 7 (part " & $i & "), break into 5-bit chunks, and reverse order") _Log(" " & $sConsole[5]) _Log("- Step 8 (part " & $i & "), BitOR 100000 (0x20) to our 5-bit chunks (effectively)") _Log(" " & $sConsole[7]) _Log("- Step 9 (part " & $i & "), converting the chunk from Binary back to Decimal") _Log(" " & $sConsole[8]) _Log("- Step 10 (part " & $i & "), adding 63 to decimal values") _Log(" " & $sConsole[9]) EndIf Next Local $aASCII[0] For $i = 0 To 1 Dim $aASCII[0] ; Reset ASCII array For $j = 0 To (UBound($aChunks, 2) - 1) ; For both chunk sets ReDim $aASCII[UBound($aASCII) + 1] ; Add an index for the ASCII array If $aChunks[$i][$j] = "" Or $aChunks[$i][$j] <= 63 Then ; If the chunk is not useful $l = $j For $k = $l To 1 Step -1 If $aChunks[$i][$k] = "" Or $aChunks[$i][$k] <= 63 Or $aASCII[$k] <= 63 Then $aASCII[$k - 1] -= 32 If $aASCII[$k - 1] <= 63 Then _ArrayDelete($aASCII, $k - 1) Else ExitLoop EndIf Next ExitLoop EndIf $aASCII[$j] = Int($aChunks[$i][$j]) Next ;Step 11, convert each value to ASCII equivalent For $k = UBound($aASCII) - 1 To 0 If $aASCII[$k] <= 63 Or $aASCII[$k] = "" Then ReDim $aASCII[UBound($aASCII) - 1] Else ExitLoop EndIf Next $aPoints[$i] = StringFromASCIIArray($aASCII, 0, -1, 0) Next If $bLog Then _Log("- Step 11, convert each value to ASCII equivalent, finished") If $aCoords[$c] <= 0 Then ;@CRLF & " " & If $bLog Then _Log($aPoints[1]) _Log($aPoints[0]) _Log("Next set") EndIf $sPolygon &= $aPoints[1] $sPolygon &= $aPoints[0] Else If $bLog Then _Log($aPoints[0]) _Log($aPoints[1]) _Log("Next set") EndIf $sPolygon &= $aPoints[0] $sPolygon &= $aPoints[1] EndIf Next If $bLog Then _Log("Custom Polygon: " & $sPolygon) _Log(TimerDiff($timer) & @CRLF) EndIf Return $sPolygon EndFunc ;==>_GetPoly Func _NumberToBinary($iNumber) Local $sBinString = "" ; Maximum 32-bit # range is -2147483648 to 2147483647 If $iNumber < -2147483648 Or $iNumber > 2147483647 Then Return SetError(1, 0, "") ; Convert to a 32-bit unsigned integer. We can't work on signed #'s $iUnsignedNumber = BitAND($iNumber, 0x7FFFFFFF) ; Cycle through each bit, shifting to the right until 0 Do $sBinString = BitAND($iUnsignedNumber, 1) & $sBinString $iUnsignedNumber = BitShift($iUnsignedNumber, 1) Until Not $iUnsignedNumber ; Was it a negative #? Put the sign bit on top, and pad the bits that aren't set If $iNumber < 0 Then Return '1' & StringRight("000000000000000000000000000000" & $sBinString, 31) ; Always return 32 bit binaries If StringLen($sBinString) < 32 Then Return StringRight("0000000000000000000000000000000" & $sBinString, 32) Return $sBinString EndFunc ;==>_NumberToBinary Func _BinaryToDec($sBinary) Local Const $aPower[8] = [128, 64, 32, 16, 8, 4, 2, 1] Local $iDec If StringRegExp($sBinary, "[0-1]") Then If StringLen($sBinary) < 8 Then Do $sBinary = "0" & $sBinary Until StringLen($sBinary) = 8 EndIf $aBinary = StringSplit($sBinary, "", 2) For $i = 0 To UBound($aBinary) - 1 ;~ $aBinary[$i] = $aBinary[$i] * $aPower[$i] $iDec += $aBinary[$i] * $aPower[$i] Next Return $iDec Else Return SetError(0, 0, "Not a binary string") EndIf EndFunc ;==>_BinaryToDec Func _InvertBinary($iNumber) ;~ ConsoleWrite(@CRLF & $iNumber) Local $sNumber $aNumber = StringSplit($iNumber, "") For $i = 1 To $aNumber[0] If $aNumber[$i] = 0 Then $aNumber[$i] = 1 ElseIf $aNumber[$i] = 1 Then $aNumber[$i] = 0 Else Return SetError(0, 0, "Not a binary number") EndIf $sNumber &= String($aNumber[$i]) Next Return $sNumber EndFunc ;==>_InvertBinary Func _Log($data) ;~ Local Static $LogEnable = True ConsoleWrite(@CRLF & @HOUR & ":" & @MIN & "." & @SEC & " " & $data) LogData(@HOUR & ":" & @MIN & "." & @SEC & " " & $data, "logs/LOGFILE.txt") EndFunc ;==>_Log Func LogData($text, $File = "logs/LOGFILE.txt") Global $LogFile = "" If $LogFile = "" Then $LogFile = FileOpen($File, 9) OnAutoItExitRegister(CloseLog) EndIf FileWriteLine($LogFile, $text) EndFunc ;==>LogData Func CloseLog() If $LogFile <> "" Then _Log("Closing LoD script" & @CRLF) FileClose($LogFile) EndIf EndFunc ;==>CloseLog  
      I've tried:
      $sPolygon &= $aPoints[0] & $aPoints[1] ;---- $sPolygon = $sPolygon & $aPoints[0] & $aPoints[1] ;---- $sPolygon = $sPolygon & String($aPoints[0] & $aPoints[1]) ;---- $sPolygon = String($sPolygon) & String($aPoints[0]) & String($aPoints[1]) ;---- $sPolygon &= $aPoints[1] $sPolygon &= $aPoints[0] ;----  
      I'm sure it's something basic that I'm overlooking, but I don't understand why it's not combining the strings. 
      Also, unrelated, why doesn't $LogFile = FileOpen($File, 9) create the directory/ file if they don't exist? 9 should be $FO_CREATEPATH (8) + $FO_APPEND (1)?
      Thanks!
    • careca
      By careca
      This is another take on string triggers, triggers on specific strings.
      Able to simple text pasting,
      opening links (as long as there's a www. http:\\ or https:\\ at the beggining)
      and is able to open applications.
      The user selects the modifier key, and then uses a combination of that key with a couple others to perform tasks like
      screenshot the active window, (modkey + prtscr), turn off the screen (modkey + pause / break),
      open clipboard string in registry (modkey + R), change system volume (modkey + arrouw up/dn).
      The following keys pressed at the same time prompt for shutdown: S+D+T
      The following keys pressed at the same time prompt for restart: S+R+T
      Middle mouse button click on titlebar minimizes to tray, or a left mouse button click in the icon in the tray also minimizes.
      Trigger is set off by space or enter, and timeouts after 3 seconds.
      Shows your external, lan, and gateway ip's, can refresh with right mouse click, and opens the default browser if the correspondent button is pressed.
      Able to change system volume by a set percentage, reading from the inputbox the number the user sets, if 0 or empty uses system default.
      I made this because the existing string trigger applications didn't do it for me for a number of reasons.
      I did this for me, but if someone finds it useful all the better.
×