Sign in to follow this  
Followers 0
marko001

Editbox values to Array?

8 posts in this topic

Hi all guys,

I'm trying to find a solution for the following:

I have an Editbox

$CH_Edit = GUICtrlCreateEdit("", 71, 40, 81, 353, BitOR($WS_VSCROLL,$ES_WANTRETURN))
$CH_Close = GUICtrlCreateButton("Save&Close", 70, 408, 75, 25)

 

and I would like to pass to an array all the datas inside, row by row.

i.e. if I have in the editbox

John-Holder

Frank-MCGregor

Alex-Dentis

I would like to have, once Button has been clicked,

dm $names[100][2] ; fixed or it would be better dinamic based on the row of the editbox

 

and

$names[0][0]=John
$names[0][1]=Holder
$names[1][0]=Frank
$names[1][1]=MCGregor
$names[2][0]=Alex
$names[2][1]=Dentis

 

Can you please help me to solve this?

Thanks in advance,

Marco

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try something like this here:

#include <Array.au3>

$sText = "John-Holder" & @CRLF & _
         "Frank-MCGregor" & @CRLF & _
         "Alex-Dentis"

$a = StringRegExp($sText, "(.+)\S*", 3)

Global $aSplitted[UBound($a)][2]
For $i = 0 to UBound($a) - 1
    $aTmp = StringRegExp($a[$i], "(\w+)", 3)
    $aSplitted[$i][0] = $aTmp[0]
    $aSplitted[$i][1] = $aTmp[1]
Next

_ArrayDisplay($aSplitted)

No error checks added!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Hi UEZ and thanks, it works perfectly.

Just one thing: I'm usual to store all datas in a settings.ini file

IniWrite($_settings, "Datas", "Full Names", GUICtrlRead($ch_edit))

In this way it stores the datas in this way:

[Datas]

[...]
Full Names=John-Holder
Frank-MCGregor
Alex-Dentis

and this is an error since when I'll iniread(..) it will get just read into editbox the first name after the key.

Shall I save the editbox content to a file and call it at _loadsettings()?

Thanks,

Marco

Share this post


Link to post
Share on other sites

Do you want the ini to look like this

[Full Names]
1=John-Holder
2=Frank-MCGregor
3=Alex-Dentis

or this

[Data]
Full Names=John-Holder,Frank-MCGregor,Alex-Dentis

or else ?

Share this post


Link to post
Share on other sites

Honestly it's important for me to iniread() and iniwrite() them so I can get them back.

I will, when needed, store the values to the array[$x][$y].

Second solution seems more "space"-efficient since I have other keys in the .ini

It's important I can retrieve them and store in the editbox.

Thanks a lot, mate.

Marco

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Here it is, very raw

But maybe it's not the best way if you have a huge number of names to store  :)

#include <Array.au3>

$_settings = "settings.ini"

$sText = "John-Holder" & @CRLF & _
         "Frank-MCGregor" & @CRLF & _
         "Alex-Dentis"
$names = StringReplace($sText, @crlf, ",")
IniWrite($_settings, "Data", "Full Names", $names)

$a = StringRegExp($sText, "(.+)\S*", 3)

Global $aSplitted[UBound($a)][2]
For $i = 0 to UBound($a) - 1
    $aTmp = StringRegExp($a[$i], "(\w+)", 3)
    $aSplitted[$i][0] = $aTmp[0]
    $aSplitted[$i][1] = $aTmp[1]
Next
_ArrayDisplay($aSplitted)

$get = IniRead($_settings, "Data", "Full Names", "")
$names2 = StringReplace($get, ",", @crlf)
Msgbox(0,"", $names2)

Edit

typo...

Edited by mikell

Share this post


Link to post
Share on other sites

Great, yes I used it in the past and honestly I forgot it.

Thanks again dude,

Marco

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

[sOLVED!]

Err... I found that if I use an editbox to store datas

$CH_Edit = GUICtrlCreateEdit("", 71, 56, 81, 313, BitOR($WS_VSCROLL,$ES_WANTRETURN))
GUICtrlSetData(-1, "")

It doesn't recognize the @crlf so using stringreplace() it doesn't work.

Any suggestion?

Thanks,

M.

Edited by marko001

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

  • Similar Content

    • 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  
    • hcI
      By hcI
      Hey !
      I was looking for an array display to see the result of StringSplit but when i called the <Array.au3>, an error is showing up when i try to launch the script.
      I took a screenshoot of the windows dialog box error : imp.bmp
      And when I look into the Array.au3 there is no error :
      Why is it doing this ?