Page 1 of 1 1
Topic Options
#111898 - 2004-01-16 08:04 AM Nesting elements
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
This works... but does -
Quote:


1 A
1 B
1 C
1 D




etc.
Code:

cls
break on
$1=Split('1 2 3 4 5 6 7 8 9')
FOR EACH $e1 IN $1
$a=Split('A B C D E F G H I')
FOR EACH $e2 IN $a
?$e1+' '+$e2
NEXT
NEXT
GET $



What I am trying to do is -
Quote:


1 A
2 B
3 C
4 D




I am probably missing something really simple.
Code:

cls
break on
$1=Split('1 2 3 4 5 6 7 8 9')
$A=Split('A B C D E F G H I')
FOR EACH $e1 IN $1+$A
?$E1
NEXT
get $



Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#111899 - 2004-01-16 08:16 AM Re: Nesting elements
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep.
for $element=0 to ubound($myarray)
_________________________
!

download KiXnet

Top
#111900 - 2004-01-16 09:52 AM Re: Nesting elements
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Without context it's a bit difficult to see what you are trying to achieve.

It looks like you want some sort of associative array.

Here's one way of doing it, but this will only work if the entries in the first array are unique:


Cls
Break ON
$aiNumbers=Split('1 2 3 4 5 6 7 8 9')
$asLetters=Split('A B C D E F G H I')
For Each $sKey In $aiNumbers
$sKey+" "+$asLetters[AScan($aiNumbers,$sKey)] ?
Next
Get $


Top
#111901 - 2004-01-16 09:56 AM Re: Nesting elements
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
If you just want to iterate the two arrays in parallel, do as Jooel suggested:


Cls
Break ON
$aiNumbers=Split('1 2 3 4 5 6 7 8 9')
$asLetters=Split('A B C D E F G H I')
For $iKey=0 To UBound($aiNumbers)
$aiNumbers[$iKey]+' '+$asLetters[$iKey] ?
Next
Get $


Top
#111902 - 2004-01-16 10:02 AM Re: Nesting elements
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, you had to first go the fancy way around?
_________________________
!

download KiXnet

Top
#111903 - 2004-01-16 10:08 AM Re: Nesting elements
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

so, you had to first go the fancy way around?




Of course! The simple answer was not interesting enough to warrant a post

I couldn't decide (from the example) why a simple problem would cause difficulties for a long-termer like Kent, so I assumed that the requirement must be more complex than stated in the first post.

Top
#111904 - 2004-01-16 11:34 AM Re: Nesting elements
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja...
but on the other hand, like kent said, "I'm probably missing something really simple."
he has done that too previously... like we all.
so, decided to go with the simple and be the fastest answerer rather than ask for more specific info...

now, if we just would get him reply back
_________________________
!

download KiXnet

Top
#111905 - 2004-01-16 03:07 PM Re: Nesting elements
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Just to elaborate:

The initial problem is that the first code is using nested loops where the second loop is run each time the first loop is incremented. So, the final output of the initial code is
Code:

1 A
1 B
1 C
...
2 A
2 B
2 C
...

_________________________
There are two types of vessels, submarines and targets.

Top
#111906 - 2004-01-17 05:09 PM Re: Nesting elements
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Perfect! That works a treat!

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1452 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.098 seconds in which 0.064 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