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

    • dexto
      By dexto
      Why idea why would I get an error (Autoit Beta 3.3.15.0):
      Local $json[] Local $map[] $map['test'] = 'hello' Local $array[5] = [1, 2, 3, 4, 5] $json["data"] = $map $json["data"]["arr"] = $array ConsoleWrite($json["data"]["arr"][0] & @CRLF)  
    • cookiemonster
      By cookiemonster
      Im trying to read a JSON file into an array.
       
      The JSON looks like this:
       
      { "project_info": { "project_number": "123456789", "url": "https://www.website.com", "project_id": "PRJ08", "Bucket": "Buk09" }, "client": [ { "client_info": { "id": "1:1001306455", "info": { "name": "banana" } }, "oauth_client": [ { "client_id": "1001306455694-m3h6v", "client_type": 3 } ], "a_key": [ { "key": "dkldkdkd" } ], "Avail": { "ana": { "status": 1 }, "vit": { "status": 1, "other": [] }, "ad": { "status": 2 } } }, { "client_info": { "id": "1:1838346", "info": { "name": "orange" } }, "oauth_client": [ { "client_id": "2145696315633-dmdhe", "client_type": 3 } ], "a_key": [ { "key": "osikdme" } ], "Avail": { "ana": { "status": 1 }, "vit": { "status": 1, "other": [] }, "ad": { "status": 2 } } }, ], "configuration_version": "1" } What I want to do is read it all into one single large array, can anyone help? 
      All I have so far is:
      #include "JSON.au3" #include "array.au3" $file = fileread("C:\file.json") JsonToArray($file) Func JsonToArray($JSON) $JSON = StringRegExpReplace($JSON, "[\[\]{}]", "") $sBreak = StringSplit($JSON, ",") For $a = 1 To $sBreak[0] $t = _JSONDecode("{" & $sBreak[$a] & "}") _ArrayDisplay($t, "multi " & $a & " of " & $sBreak[0]) Next EndFunc ;==>JsonToArray  
    • SkysLastChance
      By SkysLastChance
      I was wondering if it is possible to make this code skip to the next row if it reads a blank line?
      I tried this.
      If $aArray = "" Then $r += 1 EndIf #include <Excel.au3> Local $r = 1 Local $aArray = _Excel_RangeRead($oWorkbook) ;~ If $iBox is greater than no. of rows in $aArray then $iBox equals the number of rows in $aArray If $iBox > (UBound($aArray) - 1) Then $iBox = UBound($aArray) - 1 For $i = 1 To UBound($aArray) - 1 ;$i =0 Start from row A If $aArray = "" Then $r += 1 EndIf $sR0 = $aArray[$i][0] ;status $sR1 = $aArray[$i][1] ;first name $sR2 = $aArray[$i][2] ;Last name $sR3 = $aArray[$i][3] ;Last 4 SSN $sR4 = $aArray[$i][4] ;DOB $sR5 = $aArray[$i][5] ;Email Address $sR6 = $aArray[$i][6] ;Mailling Address $sR7 = $aArray[$i][7] ;City $sR8 = $aArray[$i][8] ;state $sR9 = $aArray[$i][9] ;Zip Code $sR10 = $aArray[$i][10] ;Gender $sR11 = $aArray[$i][11] ;Phone WinSetState ("ADM.MCK - Registration Management Desktop","",@SW_MAXIMIZE) WinWaitActive("[CLASS:Notepad]", "", 10) ControlSend("[CLASS:Notepad]", "", "", ("{F8}")) Sleep (500) ControlSend("[CLASS:Notepad]", "", "", ("{F8}")) Sleep (500) ControlSend("[CLASS:Notepad]", "", "", ("N")) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (3000) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR1 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR2 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR6& @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR7 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR8 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR9 & @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR11& @CR) Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR5 & @CR) ;Email Sleep (200) ControlSend("[CLASS:Notepad]", "", "Edit1", $sR5 & @CR) ;Email Sleep (200) ControlSend("[CLASS:Notepad]", "", "", (FormatDate($sR4) & @CR)) $r += 1  
       
    • nss
      By nss
      Hi all.
       
      Because of me wondering if I could access the key/value pair arrays with the numbers as indexes, I have found out that the zeroth element for some reason doesn't return anything.
      Here's the example:
       
      local $r[2] $r["test1"]="hello" $r["test2"]="how are you" msgbox(64, $r[0], $r[1]) ; prints the ["test2"] but not ["test1"]. Is this even supposed to be a thing?  
       
      BTW, I haven't seen Autoit get updated since 2015; is it abandened or something?
      Any help/clarification appreciated.
    • Starf0x
      By Starf0x
      Hi,
       
      I'm a bit stuck (my brains might be hanging in a loop).
      Here's my dillema, what if there is no command line parameters are given?
       
      Global $aCmdLine = _WinAPI_CommandLineToArgv($CmdLineRaw) I've tried this, and more:
      If UBound($aCmdLine) - 1 < 1 Then ConsoleWriteError(@CRLF & "For more information use: " & @ScriptName & " /?" & @CRLF) Exit EndIf This works, the program doesn't continue, but doesn't show the ConsoleWrite, I've tried sleeps etc...
      Cheers, Starf0x