Jump to content

flexibility with declaring an array


gcue
 Share

Recommended Posts

gcue,

That's still way too vague to infer any useful direction.

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

How about a dictionary...no overhead of a database, no overhead of re-working arrays:

Local $oDictionary = ObjCreate("Scripting.Dictionary")
$oDictionary.Add("a","test")
$oDictionary.Add("b","test2")
$oDictionary.Add("c","test3")
$oDictionary.Remove("a")

I would even suggest a virtual XML file...you can add and remove nodes as you see fit...as well as do anything that an array can do.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

 

but in that example, those elements still exist.  If they were deleted the ubound would change.  It is the same as ignoring them, doesnt matter what the exclude string is.

#include <array.au3>


local $array[10]


$x = 0


$array[$x] = "bob"
$x +=1
$array[$x] = "larry"
$x +=1
$array[$x] = "mark"
$x +=1
$array[$x] = "will"
$x +=1
$array[$x] = "pete"
$x +=1
$array[$x] = "martha"
$x +=1
$array[$x] = "jane"
$x +=1
$array[$x] = "jill"
$x +=1
$array[$x] = "jack"
$x +=1
$array[$x] = "jim"


$array = _deletefolk($array , "larry;jane;jill;jack") 
_ArrayDisplay($array)


Func _deletefolk($aArray, $sNames)
$aNames = stringsplit($sNames , ";" , 3)
for $i = 0 to ubound($aNames) - 1
$aFound = _ArrayFindAll($aArray , $aNames[$i])
$aArray[$aFound[0]] = ""
next

return $aArray

EndFunc

right i know the $x += 1 soluition i showed would work in that scenario.. but like i said i was just asking if there was a better way

Link to comment
Share on other sites

right, i was focused more on the option of blanking -vs- deleting (to overcome the issue with indexes changing).  How you populate the intial array best is certainly not addressed. 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

gcue,

Externalize the data in any of; a DB, ini file, flat file, etc.  Then your code can react to changes real-time. 
That is as specific as the scenario that you present permits.

kylomas

edit: spelling

edit: simple example using a flat file (1 name per line)

#include <date.au3>

Local $sFileName = @ScriptDir & '\names.txt'
Local $DTStamp = FileGetTime($sFileName, 0, 1) ; return last modified date/time as string
Local $aNames = StringSplit(FileRead($sFileName), @CRLF, 3)

While 1 ;   your main loop

    If FileGetTime($sFileName, 0, 1) <> $DTStamp Then _Refresh_Array()

    ;
    ; do your thing
    ;

    Sleep(100)

WEnd

Func _Refresh_Array()

    $aNames = StringSplit(FileRead($sFileName), @CRLF, 3)
    ConsoleWrite('Names array refreshed at ' & _Now() & @CRLF)
    $DTStamp = FileGetTime($sFileName, 0, 1)

EndFunc   ;==>_Refresh_Array
Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Am I missing something in this thread or is _ArrayAdd all you were looking for in the first place?

#include <array.au3>

Dim $myArray[0]

_ArrayAdd($myArray, "hello");
_ArrayAdd($myArray, "another element");
_ArrayAdd($myArray, "bye");

_ArrayDisplay($myArray)

Not that I disagree with all the other suggestions - using SQLite or using an external textfile or something is probably easier, if only because you won't have to recompile your script if the data changes, because apparently you have to do that now. 

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Still >#21

We don't have the faintest idea about:

-) what the true nature of the data really is (I bet first names was just an illustration)

-) where the data comes from

-) what triggers a change

-) do changes occur on index or content

-) how is the data recognized (index or what)

-) the example shows last names; is this a list of 4000 different last names or a list of the last names of 4000 persons? In the latter case it's obvious there will be duplicates and then how is it planned to deal with that?

-) how is it required to search in the list?

-) is the data case-sensitive

-) is the search plain 7-bit ASCII or full ANSI, e.g. andre vs. andré

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

How about a dictionary...no overhead of a database, no overhead of re-working arrays:

Local $oDictionary = ObjCreate("Scripting.Dictionary")
$oDictionary.Add("a","test")
$oDictionary.Add("b","test2")
$oDictionary.Add("c","test3")
$oDictionary.Remove("a")

I would even suggest a virtual XML file...you can add and remove nodes as you see fit...as well as do anything that an array can do.

 

definitely a good idea.. thanks man

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