Page 1 of 1 1
Topic Options
#17872 - 2002-02-23 02:56 PM Script logic using arrays
tmclean Offline
Fresh Scripter

Registered: 2001-01-26
Posts: 18
Loc: Sault Ste. Marie Ontario
I need help with the logic of a script I'm working on. I have no code as of yet to post but what I want to do is read in an array of values like 1 2 4 5 2 1 5 6 7 1. From this the script would loop through each value and do something and if it encountered the same value again in the array do something else. For example using the above array 1=do something, 2=do something, 4=do something, 5=do something, 2=do something else, 1=do something else, 5=do something else etc. Can anyone help me in this logic of this loop. Thanks
Top
#17873 - 2002-02-23 05:11 PM Re: Script logic using arrays
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
what about the 3rd time that number 1 comes up?
Top
#17874 - 2002-02-23 05:24 PM Re: Script logic using arrays
tmclean Offline
Fresh Scripter

Registered: 2001-01-26
Posts: 18
Loc: Sault Ste. Marie Ontario
If any number appears again in the array no matter how many times do something else. Thanks Bryce for any help or guidance you can give.
Top
#17875 - 2002-02-23 05:35 PM Re: Script logic using arrays
Will Hetrick Offline
Hey THIS is FUN

Registered: 2001-10-02
Posts: 320
Loc: Harrisburg, PA USA
Hey TMClean,

For some reason, I just cannot get what type of logic you are doing.

So a number does not have a set thing to do? if the number is encountered a second time, it will do something else that the first time it was called?

_________________________
You have at least 2 choices. Each choice changes your destiny. Choose wisely!

Top
#17876 - 2002-02-23 05:41 PM Re: Script logic using arrays
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
ok.... here you go.

code:

$array = "1 2 4 5 2 1 5 6 7 1 1"
$array = split($array," ")


;setting the event arrays
$1events = "Event #1 'a'",
"Event #1 'b'",
"Event #1 'c'",
"Event #1 'd'",
"Event #1 'e'"

$2events = "Event #2 'a'",
"Event #2 'b'",
"Event #2 'c'",
"Event #2 'd'",
"Event #2 'e'"

$4events = "Event #4 'a'",
"Event #4 'b'",
"Event #4 'c'",
"Event #4 'd'",
"Event #4 'e'"

$5events = "Event #5 'a'",
"Event #5 'b'",
"Event #5 'c'",
"Event #5 'd'",
"Event #5 'e'"

$6events = "Event #6 'a'",
"Event #6 'b'",
"Event #6 'c'",
"Event #6 'd'",
"Event #6 'e'"

$7events = "Event #7 'a'",
"Event #7 'b'",
"Event #7 'c'",
"Event #7 'd'",
"Event #7 'e'"


for each $number in $array
$nul = execute("$$eventarray = $$"+$number+"events")
$EAsize = ubound($eventarray)
for $eventid = 0 to $easize
if $eventarray[$eventid] <> ""

;the first unused event for # had been found
;this is where your would do your actions that are based
;on the event. All i am doing here is displaying the
;event information.
? $eventarray[$eventid]


$nul = execute("$$"+$number+"events["+$eventid+"] = ''")
$eventid = $easize
endif
next
next


if you need help "understanding" the code let me know

with out knowing what the different events that you are wanting to do.... i just took a best guess.

Bryce

Top
#17877 - 2002-02-23 05:43 PM Re: Script logic using arrays
tmclean Offline
Fresh Scripter

Registered: 2001-01-26
Posts: 18
Loc: Sault Ste. Marie Ontario
Yes exactly!! When a number is called once from the array "do something" and if the same number is called again no matter how many times "do something else".
Top
#17878 - 2002-02-23 05:49 PM Re: Script logic using arrays
tmclean Offline
Fresh Scripter

Registered: 2001-01-26
Posts: 18
Loc: Sault Ste. Marie Ontario
Thanks Bryce for the quick response. It looks good but theres one twist. The numbers in the array are random not fixed values. The script must be able to read any random number of values. Thanks again
Top
#17879 - 2002-02-23 05:53 PM Re: Script logic using arrays
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
ok,

what are the number ranges? just add a $#event array for each # used.

what are the series of event actions that you want to happen for a given number?

Bryce

Top
#17880 - 2002-02-23 05:55 PM Re: Script logic using arrays
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Looks like others have a head start on me, but will toss this in anyway. I put together this little demonstration using two arrays.
code:

break on
Dim $Array[10]
Dim $Unique[10]
$Array=Split("1 2 4 5 2 1 5 6 7 1")
For $X=0 to UBound($Array)
? "Element = "+$Array[$X]
For $Y=0 to $X
If $Array[$Y] = $Array[$X]
$Unique[$X] = $Unique[$X]+1
"Unique count = " + $Unique[$X]
Endif
Next
Next
get $_

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (mole) and 1300 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.054 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org