Jump to content

From StringSplit to workable 2D Array.

Recommended Posts

Hi again. this is my second time standing in front of a wall needing someone to push my brain in a different direction.

To my Problem.

At work before shipping an item, we scan the Tracking # as well as the Serial# of the device.

I was thinking about creating a $Edit window. which will look like this








and so on

(doing it in an edit window, allows for continues scanning , without looking at the pc , as the scanner makes a new line after each scan)


i want to StringSplit the Edit which returns an 1DArray.

and now comes the part where i simply have no idea any more.

With the created Array, i would like to save it in an INI file like this:

iniwrite ("Filename.ini" _nowdate, Tracking#1, Serial#1)

iniwrite ("Filename.ini" _nowdate, Tracking#2, Serial#2)

the Help file makes it even more less understandable for me.

maybe someone can push my toughs in a direction.

i am sure there must be an easy solution i simply do not see.


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 544, 437, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 360, 24, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 360, 64, 75, 25)
$Button3 = GUICtrlCreateButton("Button3", 360, 104, 75, 25)
$Edit1 = GUICtrlCreateEdit("", 40, 24, 297, 369)
GUICtrlSetData(-1, "Edit1")
$Date1 = GUICtrlCreateDate("2021/01/21 10:07:25", 344, 192, 186, 21)

#EndRegion ### END Koda GUI section ###

GuiCtrlSetOnEvent($Button1,"test")  ; Start Add Stock

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE


Func _Close()

Func Test ()

$sText = GUICtrlRead($Edit1)
Local $sText1 = StringSplit($sText, @CRLF )
For $i = 1 To $sText1

   For $j = 2 To $sText1
     IniWrite("Test.ini", "Variables", $i, $j)


i did thinks like this: as well. but i don't know ... i might should take a brake..

$sText = GUICtrlRead($Edit1)
;$sText = StringReplace($sText, @CRLF, @tab)
Local $sText1 = StringSplit($sText, @CRLF)
Global $aArray_2D[100][2] ; Set these dimensions as required

For $i = 0 To UBound($sText1) - 1
 ; $aTemp = StringSplit($sText1[$i], @tab)
 For $j = 0 To UBound($aArray_2D, 2) - 1
        $aArray_2D[$i][$j] = $sText1[$j + 1] ; Get the elements into the 2D array



Don't take the code to serious. as its just a Test.


I Appreciate your / any thoughts on this.

Link to post
Share on other sites

You should be able to program the scanner to add a character for example a pipe "|" when scanning, if not try something like:

Func Test ()
    ;~ Read the Editbox
    Local $sText = GUICtrlRead($Edit1)
    ;~ Split the Editbox text into an array by using @CRLF, note flag option 1 splits by the entire delimiter, 0 or blank would split by @CR and @LF creating additional lines
    Local $aText = StringSplit($sText, @CRLF, 1)
    ;~ Loop through the array, step by 2 i.e. 1, 3, 5, etc... until $aText[0] (which is the last row number)
    For $i = 1 To $aText[0] - 1 Step 2
        ;~ $aText[$i] = Tracking#
        ;~ $aText[$i+1] = Serial#
        ;~ Ternary expression "($i+1 > $aText[0] ? "" : $aText[$i+1])" is used just in cast [$i+1] is greater than $aText[0] which would cause an error, if it is we default to "" rather than $aText[$i+1]
        ;~ Following line is for debug purposes only
        ConsoleWrite($aText[$i] & " = " & ($i+1 > $aText[0] ? "" : $aText[$i+1]) & @CRLF)
        ;~ Write to the ini file
        IniWrite("Filename.ini", _NowDate(), $aText[$i], ($i+1 > $aText[0] ? "" : $aText[$i+1]))


Edited by Subz
Link to post
Share on other sites
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...