SorryButImaNewbie

[SOLVED] Another "Array variable has incorrect number of subscripts or subscript dimension range exceeded"

22 posts in this topic

#1 ·  Posted (edited)

Hello!

Sorry for the weekly simpleton question, but:

I tried to make a part of my code be able to handle arrays of any size (Before, I used a fixed array size of 4, which is far from ideal, I just wanted it to run)

I szccesfully read the array size, ReDim it and I thought that I can easly read the values I need, but the 5. version of my code is giving me the same error. I'm not sure, how should I use variabels as "array subscripts" (I mean: $Array[!This for example!][!Or this!])

I wrote the following abomination, Its job would be to read through an array of running/open excel instances and find the one with a .xls extension. Then read its filepath and name  so I can make a copy of it a bit down on the line (BTW Anyother insight if you think I'm doing something wrong or not idealy is welcome!) 

Local $aWorkBooks = _Excel_BookList()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookList Example 2", "Error listing Workbooks." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_ArrayDisplay($aWorkBooks, "Excel UDF: _Excel_BookList Example 2 - List of workbooks of all instances")

;CONSTRUCTION-----------------------------------
;$aWorkBooks array méretezés
If IsArray($aWorkBooks) Then
    ReDim $aWorkBooks[UBound($aWorkBooks)]
    ;MsgBox($MB_SYSTEMMODAL, "Értesítás", "Cucc:" & UBound($aWorkBooks) & "")
    Local $ArrayElement = UBound($aWorkBooks)
    Do
        Local $Int = Int(0)
        ;MsgBox($MB_SYSTEMMODAL, "Értesítés", "Cucc: " & $ArrayElement &" Int: " & $Int &"")
        Local $Array = $aWorkBooks[Int($Int)][1]
        Local $xls = StringRegExp(String($Array), ".xls")
        $Int = Int($Int + 1)
    Until $xls = 1
    $ExcelName = $aWorkBooks[$Int][1]
    $ExcelPath = $aWorkBooks[$Int][2]
Else
    MsgBox($MB_SYSTEMMODAL, "Excel Array Hiba", "Hiba a formázandó excel felismerése közben.")
    Exit
EndIf

Consol Error:

(242) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Local $Array = $aWorkBooks[Int($Int)][1]
Local $Array = ^ ERROR

I try to use an increasing variable to read the array until its find the .xls extension, the values of $Int is okey according to the message boxes

Thanks for the help, wise users of this forum!

Edit:

You find the solution to this problem in the thread below, also the problem developed into an other one, _Excel_SheetList UDF returned with a "funny array" with numbers (see the pic around comment 5-8) the solution was to disable excel addons: Analysis ToolPak and Solver, not sure which one did the trick at the end. Also in this thread you can find a "bug fix" for _Excel_SheetList , in the current version, _Excel_SheetList gave 0 return to every error, master water posted a fix to that (you have to change a 0 value to @error).

Best of luck!

Edited by SorryButImaNewbie
Because the problem blossomd in to a new one, I edit this so others with similar problems may benefit

Share this post


Link to post
Share on other sites



You ReDim a 2D array to a 1D array with this statement

ReDim $aWorkBooks[UBound($aWorkBooks)]

Drop this statement as I do not see any need for it in your script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ohhh, sounds logical, since I only "read in" the array once, I only need to know its size... And yes, its not a 1D array as I display it and can clearly see...

Thank you master water, I also moved the $int = 0 out from the loop, so its value doesnt jump on 1 to 0 making an infinite loop :D (thats help to)

My code right now:

Local $aWorkBooks = _Excel_BookList()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookList Example 2", "Error listing Workbooks." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_ArrayDisplay($aWorkBooks, "Excel UDF: _Excel_BookList Example 2 - List of workbooks of all instances")

;CONSTRUCTION-----------------------------------
;$aWorkBooks array méretezés
If IsArray($aWorkBooks) Then
    ;ReDim $aWorkBooks[UBound($aWorkBooks)]
    ;MsgBox($MB_SYSTEMMODAL, "Értesítás", "Cucc:" & UBound($aWorkBooks) & "")
    Local $ArrayElement = UBound($aWorkBooks)
    Local $Int = Int(0)
    Do
        ;MsgBox($MB_SYSTEMMODAL, "Értesítés", "Cucc: " & $ArrayElement &" Int: " & $Int &"")
        Local $Array = $aWorkBooks[Int($Int)][1]
        Local $xls = StringRegExp(String($Array), ".xls")
        $Int = $Int + 1
        If $xls = 1 Then
            Global $ExcelName = $aWorkBooks[Int($Int)][1]
            Global $ExcelPath = $aWorkBooks[Int($Int)][2]
        EndIf
    Until $xls = 1
Else
    MsgBox($MB_SYSTEMMODAL, "Excel Array Hiba", "Hiba a formázandó excel felismerése közben.")
    Exit
EndIf
;_Excel_SheetCopyMove
;----------------------------------------------

$ExcelObject = _Excel_BookAttach($ExcelName, "filename")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookAttach Example 2", "Error attaching to '" & $ExcelObject & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

$ExcelSheetListArray = _Excel_SheetList($ExcelObject)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetList Example 1", "Error listing Worksheets." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;_ArrayDisplay($ExcelSheetListArray, "Excel UDF: _Excel_SheetList Example 1")
$ExcelSheetListArrayMaxIndex = _ArrayMaxIndex($ExcelSheetListArray)

Local $oCopiedSheet = _Excel_SheetCopyMove($ExcelObject,Default,Default,Number(($ExcelSheetListArrayMaxIndex+2)),True,True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetCopyMove", "Error copying sheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Local $aWorkBooks = _Excel_BookList()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookList Example 2", "Error listing Workbooks." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

I'm getting a new error: (pic added)

I belive Its an error for _Excel_SheetCopyMove, according to help: 

5 - Error occurred when copying/moving the sheet. @extended is set to the COM error code. 

Com error: 0

I aslo added extra code to my snipet, because I realized, the error giving part isn't here, so its makes any rescu attempt a "bit tricky".

Képkivágás.JPG

Edited by SorryButImaNewbie
Missing code with the error...

Share this post


Link to post
Share on other sites

This might be a bug in the UDF. Which version of AutoIt do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

3.3.14.1 right now

Share this post


Link to post
Share on other sites

You need to change the marked line in function _Excel_SheetCopyMove in Excel.au3 to get the COM error code.

If $bCopy Then
        $vSourceSheet.Copy($vBefore, $vAfter)
    Else
        $vSourceSheet.Move($vBefore, $vAfter)
    EndIf
    If @error Then Return SetError(5, @error, 0) ; <== Modify

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ohhh, to what? (I thought the error = 0)

 

So I tried to overwrite excel.au3, but I can't, only with different name (SciTE error)

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

It's a bug so it does not report @error correctly.

Now it is:

If @error Then Return SetError(5, 0, 0)

but it needs to be:

If @error Then Return SetError(5, @error, 0)

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I understand that, but when I try to save it with 0 replaced by @error , I get an error (pic)

What i think I can do, is to rename it to excel2.au3 or something, and then simply #include that?

(Sorry I like to make sure before I do something I dont understand instead of try and make things worse :) )

Képkivágás2.JPG

Share this post


Link to post
Share on other sites

You do not have write permission to this directory where AutoIt is installed.
Either edit the file as administrator or copy the following code to your script

Func _Excel_SheetCopyMoveEX($oSourceBook, $vSourceSheet = Default, $oTargetBook = Default, $vTargetSheet = Default, $bBefore = Default, $bCopy = Default)
    ; Error handler, automatic cleanup at end of function
    Local $oError = ObjEvent("AutoIt.Error", "__Excel_COMErrFunc")
    #forceref $oError
    Local $vBefore = Default, $vAfter = Default
    If Not IsObj($oSourceBook) Or ObjName($oSourceBook, 1) <> "_Workbook" Then Return SetError(1, 0, 0)
    If $vSourceSheet = Default Then $vSourceSheet = $oSourceBook.ActiveSheet
    If $oTargetBook = Default Then $oTargetBook = $oSourceBook
    If Not IsObj($oTargetBook) Or ObjName($oTargetBook, 1) <> "_Workbook" Then Return SetError(2, 0, 0)
    If $vTargetSheet = Default Then $vTargetSheet = 1
    If $bBefore = Default Then $bBefore = True
    If $bCopy = Default Then $bCopy = True
    If Not IsObj($vSourceSheet) Then
        $vSourceSheet = $oSourceBook.Sheets($vSourceSheet)
        If @error Or Not IsObj($vSourceSheet) Then SetError(3, @error, 0)
    EndIf
    If Not IsObj($vTargetSheet) Then
        $vTargetSheet = $oTargetBook.Sheets($vTargetSheet)
        If @error Or Not IsObj($vTargetSheet) Then SetError(4, @error, 0)
    EndIf
    If $bBefore Then
        $vBefore = $vTargetSheet
    Else
        $vAfter = $vTargetSheet
    EndIf
    If $bCopy Then
        $vSourceSheet.Copy($vBefore, $vAfter)
    Else
        $vSourceSheet.Move($vBefore, $vAfter)
    EndIf
    If @error Then Return SetError(5, @error, 0)
    If $bBefore Then
        Return $oTargetBook.Sheets($vTargetSheet.Index - 1)
    Else
        Return $oTargetBook.Sheets($vTargetSheet.Index + 1)
    EndIf
EndFunc   ;==>_Excel_SheetCopyMoveEX

and replace all function calls to _Excel_SheetCopyMove to _Excel_SheetCopyMoveEX so the modified version gets called.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Wow, thanky you so much!

Can I   "Replace owner on subcontainers and objects"  on the folder? Or thats not a good idea? (I try to run as administrator, but I can't, I even tried to make a sgortcut for excel.au3, so I can use the properties/shortcut/advanced to run as admin, but I dont seems to have admin rights for that (its greyed out) which is actually pretty disturbing now that I think about it

Edit:

I tried to run your code, I get an @error = 5, @extended = 1 error on sheet copying

Edit2:

I found @extended = 1 to be the error of Read-only excel object at book_attach, I'm not sure if thats the reason here as well

Edited by SorryButImaNewbie
I save my advantures here instead of posting extras

Share this post


Link to post
Share on other sites

Did you check that all parameters for _Excel_SheetCopyMove have sensible values?
Does $ExcelSheetListArrayMaxIndex hold a sensible value (means the number of a worksheet that exists)?  I'm not sure as you add 2 to the maximum number returned by _ArrayMaxIndex. If you have 5 worksheets in your workbook thn this value shouldn't be > 5.
Use ConsoleWrite/MsgBox to display this values to check.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

According to MsgBox checks, yes, it had a value 1, 1+2 = 3 I had 3 sheets.

I tried Default value, same outcome.

The suspicous part for me is the Excel_SheetList, I displayed that during checking and it returned this, again I have 3 Sheets, none of them can be found in this list.

 

Képkivágás3.JPG

Edit: Also the $ExcelSheetListArrayMaxIndex value is 1. Which doesn't really make sense to me

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

Strange.
Which version of Office do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I'm not sure.

I have a 2016 "unoffical" version.

Now that I started digging, I found a Shortcut at C:\ProgramData\Microsoft\Windows\Start Menu\Programs, which seems to lead into itself (open containing folder), maybe because its the Start Menu folder

I'm not sure actually (I use it for maybe 2-3 years) according to office download I have an up to date version.

Will Edit for more info

Edit:

Well I may spend some time to install a real office... I'm still a student so I should be able to get a fre copy somehow, but downloading it from a "third party" was much quicker, when I only needed it for some school stuffs and basic use. It was much easier for my younger self...

Thy for the troubelshooting master water!

(verziószám = versionnumber)

Officeversionnumber.JPG

Edit2: I had a windows update, hoped it will solve the problem, it didn't this is my last update today, thanks for the help! (I love this forum)

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

I'm not sure it is caused by the Office version.
Does the _Excel_SheetList.au3 example script work for you? Means - IIRC - you should get 3 sheets listed.
Could it be possible that your workbook contains a lot of hidden sheets?
Are there custom made addons active? I once had problems with a badly written addon driving me crazy!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

I checked for hidden sheets and looked for other VBA shenanigans, but nothing.

I don't know about custom meda addons, but i don't think so.

Excel sheet list gives an "interesting" error. @error = 2 for _Excel_BookOpen meaning 

Specified $sFilePath does not exist, I think this is because its ask for activation first. I added lines

MsgBox($MB_SYSTEMMODAL, " Stop ", "Hammer Time!") 

after the _Excel_BookOpen lines in the _Excel_BookList example, to close these (@error = 2 is avoided this way)

Returns empty array with display, picture of array and one excel (they look the same, empty without sheet, I can go to files and open recently used excels)

However! I can see these excels in System information/Softenvierment/RunningTasks I'm not sure that would usually mean that autoit should see it as well.

I try to open some excels (2 so its like the example) and try to list those, maybe It leads to something

Edit: Okey I tried the booklist example... not sheetlist, Trying with sheet list with the added HammerTime msg box to close the product activation It returns an @error = 1 , I don't know, I try to attach to an excel instance where there is something in the file, and list there... I don't understand I use _excel_SheetList in my code and worked there so far (if array dimensions and size were handeld correctly) it displayed the sheets like it should,

My other "idea" of the origin of the problem is that if I list the _Excel_BookList and display it I get back 3 extra thing. I'm not sure what are these (I wrote a script that goes trhought the array searching for -xls extension, so I can simply skip these) I know what the SOLVER is but I don't know it should be displayed by this function. (see: pic2, arraylist)

Could these XLAM files be the source of my problem to begin with? with some excel extension?

ExcelBookListTest.JPG

ArrayList.JPG

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

I have absolutely no idea what causes your problem :'(
You are sure that you attach to the correct workbook?

Or maybe the problem is caused by the missing activation?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I'm pretty sure (there are no other workbooks open, also before I started to upgrade my code to handel arrays, it attached to the workbook and formated the rows/columns inside just nice, so the script was interacting with it before).

Yes, the missing activation is a possible culprit.... You dont't think that these XLAM files are the problem?

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

According to the web:
http://pcsupport.about.com/od/fileextensions/f/xlamfile.htm

"A file with the XLAM file extension is an Excel Macro-Enabled Add-In file that's used to add new functions to Excel."

So this add-ins might influence the way Excel COM (and hence the Excel UDF) works.
You could try to deactivate the add-ins and check if that makes any difference.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

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

    • JayHawkfl
      By JayHawkfl
      Super simple super quick script I made to randomize teams for mixed doubles. Haven't coded for a while so it felt good to write anything. 
       
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <SliderConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> Local $arraySize = 2 local $array1[50] = ["Doug","Julio"] local $array2[50] = ["Hannah","Sheila"] Local $oBook #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Doubles Team Mixer", 615, 438, 192, 124) $Bachround = GUICtrlCreatePic("C:\Users\a607150\Pictures\2.jpg",0,0,615,438) $Input1 = GUICtrlCreateInput("", 64, 128, 121, 175) $Input2 = GUICtrlCreateInput("", 364, 128, 121, 175) $Button1 = GUICtrlCreateButton("Serve",216,140,121,42) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $array1 = GUICtrlRead($input1) $array1 = StringSplit($array1,",") $array2 = GUICtrlRead($input2) $array2 = StringSplit($array2,",") _ArrayDelete($array1,0) _ArrayDelete($array2,0) _ArrayShuffle($array2) $oBook = _Excel_Open(Default, Default, Default, Default, True) $oWorkBook = _Excel_BookNew($oBook, 1) _Excel_RangeWrite($oWorkBook,$oWorkBook.activesheet,"Guys","A1") _Excel_RangeWrite($oWorkBook,$oWorkBook.activesheet,"Gals","B1") _Excel_RangeWrite($oWorkBook,$oWorkBook.activesheet,$array1,"A2") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "Error writing $array1 to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_RangeWrite($oWorkBook,$oWorkBook.activesheet,$array2,"B2") EndSwitch WEnd  
    • jjohn
      By jjohn
      Hi all,
      I have the following code, basically, it populates an array with unique characters found in a string, but it turns out only one character is in the array, i don't want to think it is due to a bug of autoit at this point, so i need your help on why, please
      Dim $sx[0] Dim $cn $ss = "Xx" ConsoleWrite(StringLeft($ss, 1) & " " & StringRight($ss, 1) & @CRLF) ConsoleWrite(StringLeft($ss, 1) = StringRight($ss, 1) & @CRLF) ;here show X <> x ConsoleWrite(@CRLF) ;the following is to populate array $sx with different unique characters in $ss For $b = 1 To StringLen($ss) $flg = 0 For $a = 0 To UBound($sx) - 1 ;if asc(StringMid($ss,$b,1)) = asc($sx[$a]) Then ;if this line is used instead of the next, everything is fine If StringMid($ss, $b, 1) = $sx[$a] Then If StringMid($ss, $b, 1) = "x" Then ConsoleWrite("<<->>" & StringMid($ss, $b, 1) & " " & $sx[$a] & @CRLF) $flg = 1 ExitLoop EndIf Next If $flg = 0 Then $cn = $cn + 1 ReDim $sx[$cn] $sx[$cn - 1] = StringMid($ss, $b, 1) EndIf Next ConsoleWrite(UBound($sx) & @CRLF);list the ubound of $sx ;list what is in array $sx For $a = 0 To UBound($sx) - 1 ConsoleWrite($sx[$a] & @CRLF) Next same code in a file is attached as uniqueChar2Array.au3
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening
      I was looking around the forum if I could find a function that allows to convert a string into a 2 dimensional array...
      The first column of the array is always the same, but the rows could change...
      I have a pattern like:

      Column A|Column B
      Static Text 1|Data 1
      Static Text 2|Data 2
      Static Text 3|Data 3
      Static Text 4|Data 4

      Where, Static Text (1...4) will be always the same, and I don't want to change them... But, Data 1...4 are dynamic fields... So, I could have the pattern above AND I coould have the pattern I'm going to show you right below

      Column A|Column B
      Static Text 1|Data 1
      Static Text 2|Data 2
      Static Text 3|Data 3
      Static Text 4|Data 4
      Static Text 1|Data 5
      Static Text 2|Data 6
      Static Text 3|Data 7
      Static Text 4|Data 8

      How can I do in this case?

      Thanks for everyone's help


       
    • ur
      By ur
      I have a string with comma seperated as below.
      Name="Test-win10x64,Test-win10x65,Test-win10x67"
      $machine_names = StringSplit($tempINIValue, ',', $STR_ENTIRESPLIT) with the above line i can get a single dimension array.
      But I want a tabular format array like 4X4 where I want to add the 4 single dimension arrays as different columns in them.
       
      Is there any option to do the same.
    • 232showtime
      By 232showtime
      im getting strange output in array display,$split_[1] is not properly aligned to other arrays and why guictrlsetdata is not writting any data if i put comma(,) at the end of the text in $Input1???
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #Region ### START Koda GUI section ### Form=C:\Users\user\Desktop\Script\StringSplit.kxf $Form1 = GUICreate("Form1", 623, 449, 192, 114) $Input1 = GUICtrlCreateInput("50UGITQ421X, 50UGITQ422X, 50UGITQ423X, 50UGITQ427X, 50UGITQ431X, 50UGITQ435X, 50UGITQ436X, 50UGITQ437X, 50UGITQ441X, 50UGITQ445X, 50UGITQ449X, 50UGITQ453X, 50UGITQ454X, 50UGITQ455X, 50UGITQ459X", 24, 16, 553, 21) $Split = GUICtrlCreateButton("Split", 24, 48, 75, 25) $List1 = GUICtrlCreateList("", 24, 96, 553, 97) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Split $read = GUICtrlRead($Input1) $split_ = StringSplit($read, ",") $Max = UBound($split_, 1) For $i = 1 To UBound($split_) - 1 ConsoleWrite($split_[$i] & @CRLF) ;~ ControlSetText($Form1, "", $List1, $split_[$i]) GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $i) Next _ArrayDisplay($split_) EndSwitch WEnd