match the array content

Blitz3D Forums/Blitz3D Beginners Area/match the array content

GC-Martijn(Posted 2006) [#1]
H!

How do I do this ??

a$(0) = "red"
a$(1) = "blue"
a$(2) = "red"
a$(3) = "green"
a$(4) = "purple"
a$(5) = "purple"
a$(6) = "purple"

now I want to know that red is at place 0 and 2
and purple at place 4,5,6

I was testing things but that fails:
aantal = 7
Dim a$(aantal)

a$(0) = "red"
a$(1) = "blue"
a$(2) = "red"
a$(3) = "green"
a$(4) = "purple"
a$(5) = "purple"
a$(6) = "purple"

For i1=0 To aantal

	For i2=0 To aantal
	
		If i1<>i2 Then
		
		;	If a$(i1)=a$(i2) Then
;
;			Else

;			EndIf
			
		EndIf
		
	Next
	
Next



Thanks,
GC-Martijn


Sir Gak(Posted 2006) [#2]
aantal = 7
Dim a$(aantal)

a$(0) = "red"
a$(1) = "blue"
a$(2) = "red"
a$(3) = "green"
a$(4) = "purple"
a$(5) = "purple"
a$(6) = "purple"

For i1=0 To aantal
	For i2=0 To aantal
		If i1<>i2 Then
		;	If a$(i1)=a$(i2) Then
;
;			Else

;			EndIf
			
		EndIf
		
	Next
	
Next

When you dimension an array, you tell it the number of elements you want in it. In your case, aantal=7, which is for elements 0 to 6. When you do your For-Next loops, do them with a
For i1=0 To aantal-1

	For i2=0 To aantal-1

Otherwise, you really have 8 elemnts, 0 to 7.

More than that, your code posted has semi-colons in front of various lines. The semi-colon is the way you tell Blitz to make that line a non-compiled comment, not code. Those lines wil not execute.


GC-Martijn(Posted 2006) [#3]
THanks Sir Gak,

It was the aantal-1 ;)
How stupid...