Sign in to follow this  
Followers 0
gcue

setting array values

16 posts in this topic

Hello.

I have an array with several pre-declared values which I set this way:

local $array[4][2]

$array[0][0] = "value"
$array[0][1] = "value"

$array[1][0] = "value"
$array[1][1] = "value"

$array[2][0] = "value"
$array[2][1] = "value"

$array[3][0] = "value"
$array[3][1] = "value"

I would like to do this without having to keep changing the numberg of records in both the declaration (local $array[4][2] and the new record i would be adding)

id like to be able to do something like this:

Local $array[1][1]

$array[$array][0] = "eh"
$array[$array][1] = "eh"
$array[ReDim $array[UBound($array) + 1]][0] = "eh"
$array[ReDim $array[UBound($array) + 1]][1] = "eh"
...

I cant seem to format this in a way in which the syntax would be acceptable.

thanks in advance

Share this post


Link to post
Share on other sites



Do you know in advance how many lines and columns the array will have?

Do the values you want to assign change or are they all the same (like "eh" in your example)?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
ReDim($array[uBound($array)+1][2])

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

i do know in advance how many lines and columns, but i will keep adding lines to it

the values definitely change, my example was just to illustrate.

thanks water

Share this post


Link to post
Share on other sites

ReDim($array[uBound($array)+1][2])

hey Brewman, im still getting a syntax error with your suggestion

thanks though

Share this post


Link to post
Share on other sites

ReDim $array[uBound($array)+1][2]


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

still getting syntax errors, maybe im confused

Local $array[1][1]

$array[$array][0] = "record 1 - column 1"
$array[$array][1] = "record 1 - column 2"
$array[ReDim $array[UBound($array)+1][2][0]] = "record 2 - column 1"
$array[ReDim $array[UBound($array)+1][2][1]] = "record 2 - column 2"

Share this post


Link to post
Share on other sites

ReDim only allows to re-dimension an array. You can't assign values.

Local $array[1][2]
$i = 1
$array[$i][0] = "record 1 - column 1"
$array[$i][1] = "record 1 - column 2"
$i = $i + 1
ReDim $array[$i][2]
$array[$i][0] = "record 2 - column 1"
$array[$i][1] = "record 2 - column 2"

But that isn't shorter as if you would do everything manually.

Can you get the values from a file? Then you could use _FileReadToArray. With a bit additional code you can then create a 2D array.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

hmm yea seems more work than doing it manually. no i set the values manually.. im up to 723 records so just thought there was an easier way to manage the long list =)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Do you have the list available so you can copy and paste it into an AutoIt script? You could then use stringsplit or something similar.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

ReDim $array[uBound($array)+1][2]

Cut and paste mistakes hurt :)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

hmm yea seems more work than doing it manually. no i set the values manually.. im up to 723 records so just thought there was an easier way to manage the long list =)

Use an ini file and then use IniReadSection, it puts the key into the [0] element and the value into the [1] element of an array.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

water:

i don't sorta just add as i go along... its a change log of changes, fixes, additions, removals catagorized

$changelog_all_entries[698] = 'Changedprinters are being pulled from new site'

$changelog_all_entries[699] = 'Fixed||when adding a printer, selection toggle was not working.'

$changelog_all_entries[700] = 'Added|Option to Copy Results as Image.'

in the end i catagorize the output based on the tag i put in the begining of the value

looks like manual is the easiest way then =/

thanks guys =)

Share this post


Link to post
Share on other sites

Use an ini file and then use IniReadSection, it puts the key into the [0] element and the value into the [1] element of an array.

yea the array is so long id hate to deal with a file attached to it. besides wouldnt each key need its own unique label - back to square 1 if you ask me =)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

You have to somehow put the data into your script: read a file, split a string or fill the array manually.

The string method could look like:

#include <array.au3>

Global $sInput = "record 1 - column 1|record 1 - column 2" & @LF & _
    "record 2 - column 1|record 2 - column 2"

Global $aArray1D = StringSplit($sInput, @LF)
Global $aArray2D[$aArray1D[0]+1][2] = [[$aArray1D[0], 2]]
For $i = 1 To $aArray1D[0]
    $aTemp = StringSplit($aArray1D[$i], "|")
    $aArray2D[$i][0] = $aTemp[1]
    $aArray2D[$i][1] = $aTemp[2]
Next

_Arraydisplay($aArray2D)

You need two separators. One to denote a new line (e.g. @LF) and another to separate the two values in each line (e.g. |).

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

thanks water ill play with that method =)

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