Jump to content
Sign in to follow this  
kartune

array variable has incorrect number of subscripts

Recommended Posts

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

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

@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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites

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

Thanks, will take a look.

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


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
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

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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By cruisepandey
      Hi, 
      I have a string like this : 
      Global $Msga = "urrent directory is /send.  (Submission of file with log number 29381077284 is confirmed)";
      I want to extract the number 29381077284  from the string. I did StringSplit to split based on "(" and then use space to reach there, But it's not a good choice. 
      Can anyone help me with regular expression to find the number from String using AutoIT. TIA
    • By DannyJ
      I have this example string:
       
      2020-06-08 09:23:33 : abcdefghifjklm How to trim just the right part? Or how to trim this text right to left?
      I want to trim this string right to left until ' : '.
      In ohter words: I need the 'abcdefghifklm' text.
      I have tried StringTrimRight, but that requires 
      The number of characters to trim. Unfortunately StringSplit trims the left part of the strings.
       
       
    • By careca
      This is my 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, if there is a parameter in the parameter field, it uses it.
      Shows your external, lan, and gateway ip's.
      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.
      I did this for me, but if someone finds it useful, all the better.
    • By Colduction
      Hi guys!, i have a problem to convert Python code to AutoIt code, in fact i had not coded with Python yet!, this code is about permutation a string's case, i will be happy with your comments :)❤;

      Python code:
       
      # Python code to print all permutations # with respect to cases # Function to generate permutations def permute(inp): n = len(inp) # Number of permutations is 2^n mx = 1 << n # Converting string to lower case inp = inp.lower() # Using all subsequences and permuting them for i in range(mx): # If j-th bit is set, we convert it to upper case combination = [k for k in inp] for j in range(n): if (((i >> j) & 1) == 1): combination[j] = inp[j].upper() temp = "" # Printing current combination for i in combination: temp += i print(temp), # Driver code permute("Hello") # This code is contributed by Sachin Bisht
      My code in AutoIt:
      ; https://www.geeksforgeeks.org/permute-string-changing-case/ _PermuteCase("ABC") Func _PermuteCase($sText) If StringRegExp($sText, "^[A-Za-z]{1,}$") Then Local $iLength = StringLen($sText) ; Get length of the text. Local $iMaxPerm = 2 ^ $iLength ; Number of permutations is 2^n Local $sLow_Text = StringLower($sText) ; Converting string to lower case Local $asChrs = StringToASCIIArray($sLow_Text) ; Split the text into array of chars. For $i = 1 To $iMaxPerm Step 1 For $j = 0 To $asChrs[0] ;................................................... Next Next Else Return SetError(-1, 0, "Error: Input is incorrect!") EndIf EndFunc ;==>_PermuteCase  
       
       
       
       
       
      ====================== SOLUTION by @TheXman ======================
       
    • By jmp
      i am trying to get number from string using this code :
      #include <IE.au3> $oIE = _IEAttach ("Edu.corner") Local $aName = "Student name & Code:", $iaName = "0" Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.InnerText = $aName Then $iaName = $oTd.NextElementSibling.InnerText $iGet = StringRegExpReplace($iaName, "\D", "") EndIf Next MsgBox(0, "", $iGet) it was get number like 52503058
      But, I want to get only student code 5250. (Different student have different code, sometime its 3 digits, Sometime 4)

       
×
×
  • Create New...