Jump to content
Sign in to follow this  
vkrisz81

make array item by indexed with a text

Recommended Posts

vkrisz81

Hello!

here is an example:

1 if $lineparts[1]="logfile" or $lineparts[1]="1stnames" or $lineparts[1]="2ndnames" or $lineparts[1]="mailservers" or $lineparts[1]="fullnames" Then

2 $filelist[$lineparts[1]]["name"]=$lineparts[2]

3 $filelist[$lineparts[1]]["object"]=f($lineparts[2],$lineparts[3])

4 ConsoleWrite($filelist[$lineparts[1]]["name"]&@LF)

5 ConsoleWrite($lineparts[2]&@LF)

6 EndIf

so, the program found the text "logfile"

the 4 row write out me 2 instead of logfile.txt, but the next row looks the string, writeout logfile.txt

i wanna know, why cant put into ["name"] index this text?? why???????

i can directly use text indexed array items. now why doesnt work it?

thank you!

Share this post


Link to post
Share on other sites
water

You can't access an array element by name, only by index.

What you are looking for are "associative arrays". Search the forum for this term and you will find a lot of examples ().


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
vkrisz81

I FOUND THAT AFTER row 2 the text indexed arra item has the text, but after row 3 that value sets to number.. is it normal?? i dont think so.

Share this post


Link to post
Share on other sites
vkrisz81

i can use the formula, $arraynam['indexname']

it add me back correct value, like after row2 with an inserted consolewrite. it writes out the correct value, after f function it changes.

You can't access an array element by name, only by index.

What you are looking for are "associative arrays". Search the forum for this term and you will find a lot of examples ().

Share this post


Link to post
Share on other sites
vkrisz81

ok now i can see, i can set 1 text called item, but after i get another text called item, last has been rewriten

i sry that this is not work standardly, the other way too complicated instead of $arrayname["index1"]["item2"]

thanks

Share this post


Link to post
Share on other sites
vkrisz81

how can i make subarray to associated array?

Share this post


Link to post
Share on other sites
water

Did you have a look at the link I specified in post #2?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
vkrisz81

yes, i saw that but i choose another way, i use number indexed array, i think that is too complicate to use! elegant, but complicated for me in use. i will use it later! thanks

Share this post


Link to post
Share on other sites
MilesAhead

This makes it a lot simpler

For the most common case where you want case insensitive keys just call

$myAssocArray = _AssocArray()
; then test succeeded by $myAssocArray <> 0
If $mAssocArray then
  ; do stuff with the array
EndIf

If you are done with the array long before the program ends you can free memory by

calling _AssocArrayDestroy($myAssocArray)

For some reason editing this post I cannot leave an underlined link named Dictionary Object. But if I could, it would be here:

msdn.microsoft.com/en-us/library/x4k5wbx4(v=vs.84).aspx

Edited by MilesAhead

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  

×