Display Array element in MsgBox Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Display Array element in MsgBox

23 Feb 2018, 05:06

Hi there,

It's been some time i've used ahk, and I'm a little rusty :)

Could you guys help me out ?

How do I display the values in 'EditList' ?

Small snippet of bigger code:

Code: Select all

Voornaam := "John"
EditList := [Voornaam|Achternaam|Status|Geboortedatum|Geslacht|Adres|Postcode|Woonplaats|Toevoeging|Telefoonnummer|Mobielnummer|Emailadres|DatumInDienst|DatumUitDienst|Dienstverband|Uitzendnummer|Uren|Maandag|Dinsdag|Woensdag|Donderdag|Vrijdag|Huisarts|Huisartsnummer|Contact|Contactnummer|BGG|BGGnummer]
MsgBox, % Voornaam ;this works
;below doesn't work
MsgBox, % EditList
MsgBox, % EditList[1]
MsgBox, % EditList[2]
MsgBox, % EditList[3]
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Display Array element in MsgBox

23 Feb 2018, 05:44

predefined array

Code: Select all

EditList := ["Voornaam","Achternaam","Status","Geboortedatum","Geslacht","Adres","Postcode","Woonplaats","Toevoeging","Telefoonnummer","Mobielnummer","Emailadres","DatumInDienst","DatumUitDienst","Dienstverband","Uitzendnummer","Uren","Maandag","Dinsdag","Woensdag","Donderdag","Vrijdag","Huisarts","Huisartsnummer","Contact","Contactnummer","BGG","BGGnummer"]

MsgBox, % EditList
MsgBox, % EditList[1]
or create array with loop

Code: Select all

List := "Voornaam|Achternaam|Status|Geboortedatum|Geslacht|Adres|Postcode|Woonplaats|Toevoeging|Telefoonnummer|Mobielnummer|Emailadres|DatumInDienst|DatumUitDienst|Dienstverband|Uitzendnummer|Uren|Maandag|Dinsdag|Woensdag|Donderdag|Vrijdag|Huisarts|Huisartsnummer|Contact|Contactnummer|BGG|BGGnummer"
array := []
for a, b in StrSplit(List, "`|")
			array.Insert(b)
			
MsgBox, % array[1]
loop
	MsgBox, % array[a_index]
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Display Array element in MsgBox

23 Feb 2018, 06:02

Thank you Xeo786, but the values of the array are actually variables taken from a gui.
How would I go about it in this case ?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Display Array element in MsgBox

23 Feb 2018, 06:36

This should cover the essentials.

Code: Select all

q:: ;arrays and keys
oArray := ["a", "b", "c"]
MsgBox, % oArray.2

oArray := StrSplit("a,b,c", ",")
MsgBox, % oArray.2

var1 := "a", var2 := "b", var3 := "c"
oArray := [var1, var2, var3]
MsgBox, % oArray.2

Loop, % oArray.Length()
	MsgBox, % A_Index " " oArray[A_Index]

;equivalent to the Loop example above
for vKey, vValue in oArray
	MsgBox, % vKey " " vValue
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Display Array element in MsgBox

23 Feb 2018, 10:27

Thanks jeeswg,

I think I understand a little better now.

Is it okay if I expand my question a little ?

I have a gui in which I want to prevent semicolons getting saved that are typed in edit boxes.
My code save a .csv and and extra ; - symbol messes it up.

To replicate I have below code:

Code: Select all

; This would be inputted by the user in an edit box.
Voornaam := "Jo;hn"
Achternaam := "Doe"
Status := "Bla"

EditList := [Voornaam, Achternaam, Status]

MsgBox, % EditList.1
MsgBox, % EditList.2
MsgBox, % EditList.3

; Is there a way to simplify below ? In my orginal code I have more than 30 variables that need to be checked.

Voornaam := StrReplace(EditList.1, ";", "", all)
Achternaam := StrReplace(EditList.2, ";", "", all)
Status := StrReplace(EditList.3, ";", "", all)

MsgBox, % Voornaam
So what I basically want to achieve is to remove all semicolons that are in the EditList variables and update them
to the new value.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Display Array element in MsgBox  Topic is solved

23 Feb 2018, 13:24

How about this?

Code: Select all

q:: ;remove semicolons from strings
Voornaam := "Jo;hn"
Achternaam := "Doe"
Status := "Bla"

EditList := "Voornaam,Achternaam,Status"

Loop, Parse, EditList, % ","
	%A_LoopField% := StrReplace(%A_LoopField%, ";")

MsgBox, % Voornaam
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Display Array element in MsgBox

26 Feb 2018, 02:14

jeeswg wrote:How about this?

Code: Select all

q:: ;remove semicolons from strings
Voornaam := "Jo;hn"
Achternaam := "Doe"
Status := "Bla"

EditList := "Voornaam,Achternaam,Status"

Loop, Parse, EditList, % ","
	%A_LoopField% := StrReplace(%A_LoopField%, ";")

MsgBox, % Voornaam
return
Thanks, but then it throws an error:

Code: Select all

---------------------------
remove semicolon.ahk
---------------------------
Error:  The following variable name contains an illegal character:
"Jo;hn"

	Line#
--->	015: %A_LoopField% := StrReplace(%A_LoopField%, ";")

The error makes perfect sense of course, but a user can still type the ; in an editbox..
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Display Array element in MsgBox

26 Feb 2018, 02:44

I tested again and my script works, you should probably post your full script, you might be doing something different to me.

Code: Select all

q:: ;test double-deref
var1 := "hello"
var2 := "var1"
MsgBox, % var1 ;hello
MsgBox, % var2 ;var1 ;deref
MsgBox, % %var2% ;hello ;double-deref
%var2% := "new"
MsgBox, % var1 ;new
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Display Array element in MsgBox

26 Feb 2018, 03:15

You are right jeeswg, sorry for the confusion. I made a typo in the array.

Thanks again.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Noitalommi_2, ReyAHK, ulysim and 311 guests