Jump to content

Write data to array


 Share

Recommended Posts

for $i = 1 to 10
next

How can I add all the appearing numbers (strings, data) to array? So that later I could say

$i[0] = 1

$i[1] = 2

etc

Note: Here I am showing may be very abstract example. In fact I will have a list of strings which will be appearing from the loop- so how can I get them into array?

Link to comment
Share on other sites

  • Moderators

topten,

Do you mean something like this?

#include <Array.au3>

Global $aArray[10]

For $i = 1 To 10
    $aArray[$i - 1] = $i

Next

_ArrayDisplay($aArray, "Loaded", Default, 8)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I myself not sure about it :)

I will try to explain

For example you are getting some list of words from the loop (regexp)

$infoarray = StringRegExp($info, '(.*?);', 3)

for $i = 0 to Ubound ($infoarray)-1

;  here  $infoarray[i$] is my resulted string

And here I need this string to be written  into some $y, so later when I get $y[0] - I have first string written into $y, and $y[1] - second string written into $y etc

next

 

Something like that ...

Edited by topten
Link to comment
Share on other sites

  • Moderators

topten,

That makes no sense at all. You have an array of results in $infoarray - why do you need to get these values into another array before accessing them? If you will be overwriting the initial array then just copy it into another like this:

#include <Array.au3>

$aInfoArray = StringSplit("0123456789", "")

_ArrayDisplay($aInfoArray, "Initial return", Default, 8)

$aCopyArray = $aInfoArray ; Copy the array

_ArrayDisplay($aCopyArray, "Copy", Default, 8)

If that is not the answer then I suggest you try and write some pseudo-code (plain language logic flow) so that we can better understand what it is you want to do - because if you have trouble formulating it how are we supposed to understand?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I try to paraphrase, may be I have missed something

$data = fileread ("words.txt")

$g = StringRegExp($data, '(.*?);', 3) ; the words are separated by ";"

for $i = 0 to Ubound($g)-1

$g[$i] - here is  every word I am getting from the list

$word = $g[$i]

getspecialdatafromtheword ($word) ; here I am getting special data which is accordingly to this word (my custom function)


;;;;;;;;;;

And here I need   $specialdata write into some $y so that later I could get from $y[0] first $specialdata from $y[1] get second special data from $y[2] get third special data etc
;;;;;;;;;;

next

func     getspecialdatafromtheword ($word)

;;;;;; my function

Return $specialdata

endfunc

I hope this is more clear. Is such possible?

 

Link to comment
Share on other sites

  • Moderators

topten,

Perhaps this:

#include <Array.au3>
#include <StringConstants.au3>
#include <MsgBoxConstants.au3>

; Simulate reading file
$sData = "0123456789"

; Simulate RegEx split into "words"
$g = StringSplit($sData, "", $STR_NOCOUNT)

; The "data" array
_ArrayDisplay($g, "Words", Default, 8)

; Create array to hold "special data" - same size as the data array
Global $y[UBound($g)]


; Now loop though the data
For $i = 0 To UBound($g) - 1

    ; Extract "word"
    $word = $g[$i]
    ; Save "special data" into new array
    $y[$i] = _getspecialdatafromtheword($word)

Next

; The "special data" array
_ArrayDisplay($y, "Special data", Default, 8)

; And to show that they 2 arrays are linked
For $i =  0 To UBound($g) - 1
    MsgBox($MB_SYSTEMMODAL, $i, $g[$i] & @CRLF & $y[$i])
Next

Func _getspecialdatafromtheword($sWord)
    ; Get the "special data"
    Return "Special data for " & $sWord
EndFunc

Any closer?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

What Melba examplified, or use _ArrayColInsert($g, 1) and store in $g[$i][1] data from word read in $g[$i][0]. That would be simpler IMVHO.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Moderators

topten,

Glad I could help.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×
×
  • Create New...