Jump to content

make array item by indexed with a text


 Share

Recommended Posts

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!

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 ().

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...