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!

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

    • Rskm
      By Rskm
      i have seen many pointing out issues related to this, i tried reading through them - still unable to solve mine.. i have a script which reads certain lines based on a search item, this is an iterative process - the ldflst_file gets updated for each iteration and the script finds the line number which has the search item. this works perfectly for few iterations, but stops in some cases abruptly with the error = 
      Subscript used on non-accessible variable $aRead^ ERROR I have verified that the search item is present in the file. what could be the reason for this code to stop in certain cases. thanks for help
      my code below (partial).. full code is in attachment
       
      local $aRead=FileReadToArray($ldflst_file)
      global $ldflst_var1=" JOINT  LOAD       FORCE(X)        FORCE(Y)        FORCE(Z)       MOMENT(X)       MOMENT(Y)       MOMENT(Z)"
       
      for $i= 0 to $ldflst_totlines    ; ldflst_totlines is total number of  lines in the file 'ldflst_file'

          if $aRead[$i]=$ldflst_var1 Then
              $ldflst_LFound=$i
              ExitLoop
              else
              EndIf
      Next
       
       
      nomo_new1.au3
    • XinYoung
      By XinYoung
      Hello again,
      I'm trying to use the FileMove function to rename a bunch of text files.
      Some of the files have "_1" at the end of their name, for example, "File123_1.txt". I want to remove the "_1" so it would become "File123.txt".
      What I currently have...
              FileMove($sSource & "\*_1.txt", $sDestination & "\*.txt")
      But since I'm using a wildcard, it doesn't appear to be working. I think it's just replacing .txt with .txt. Am I going about this the wrong way? How can I use wildcards and still accomplish this?
      Any help is greatly appreciated ^__^
    • ur
      By ur
      I have date in the string format as "DD-MM-YYYY".
       
      I need to get yesterday's date from it.
      I tried converting this from _DateTimeFormat but not working.
      Is there any direct UDF available to get this.?
    • rkr
      By rkr
      Hi, i want to read a particular string from a text file using autoit. i wish to read it without explicitly opening the text file. the copied string should be then transferred to an excelbook (again, no need to explicitly open the excel book)... 

      with reference to my screenshot attached, my input to the  'script'' is going to be 0017-0008, and the script should copy the highlighted two lines from the input file to excel
      thanks

    • cheeroke
      By cheeroke
      Hi all,
      I got this code and would like to be able to change Baud Rate and instead of sending character by character i would like to be able (if possible) to send whole string. But i don't know how to change it.
      I am taking input from file and processing whole line (this is done in FilesHandling.au3).
      To execute this i am just calling SendData("FileName", int) in "main" script.
      Any help very appreciated.
      #include <WinAPI.au3> #include <Array.au3> #include "FilesHandling.au3" ;init DLL function, we need handle to call the function $h = DllCall("Kernel32.dll", "hwnd", "CreateFile", "str", "\\.\COM19", "int", BitOR($GENERIC_READ,$GENERIC_WRITE), "int", 0, "ptr", 0, "int", $OPEN_EXISTING, "int", $FILE_ATTRIBUTE_NORMAL, "int", 0) $handle=$h[0] Func SendData($FileName, $LineNumber) ;string to be send $c = readFile($FileName, $LineNumber) $cLenght = StringLen($c) $aArray = StringSplit($c, "") ;_ArrayDisplay($aArray, "", Default, 64) For $i = 1 To $cLenght writeChar($handle, $aArray[$i], $cLenght) Next ;move to next line writeChar($handle, @CR,1) EndFunc ;write a single char func writeChar($handle,$c,) $stString = DLLStructCreate("char str") $lpNumberOfBytesWritten = 0 DllStructSetData($stString, 1, $c) $res = _WinAPI_WriteFile($handle, DllStructGetPtr($stString, "str"), 1,$lpNumberOfBytesWritten) if ($res<>true) then ConsoleWrite ( _WinAPI_GetLastErrorMessage() & @LF) EndIf EndFunc  
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.