Jump to content

# get summary form array elements

## Recommended Posts

Below is a simplified array of what I have, but should be easier to explain.

I have an array: \$aEventData[11]

[0] = 10

[1] =a

[2] =a

[3] =b

[4] =c

[5] =d

[6] =d

[7] =d

[8] =d

[9] =e

[10] =e

I would like to cycle throught the array and once the value changes get the summary for that value.

Summary = end index, number of occurances.

I have already sorted the array.

Eg.

```For \$i = 1 To \$aEventData[0] Step 1
;once I get to \$aEventData[3] I want to know that \$endIndex = 2 and \$occurance = 2 for the letter a
;..
;..
;once I get to \$aEventData[9] I want to know that \$endIndex = 8 and \$occurance = 4 for the letter d
Next```

Thanks.

#### Share this post

##### Share on other sites

See if this gives you some ideas:

```Dim \$aEventData[11]

\$aEventData[0] = 10
\$aEventData[1] = 'a'
\$aEventData[2] = 'a'
\$aEventData[3] = 'b'
\$aEventData[4] = 'c'
\$aEventData[5] = 'd'
\$aEventData[6] = 'd'
\$aEventData[7] = 'd'
\$aEventData[8] = 'd'
\$aEventData[9] = 'e'
\$aEventData[10] = 'e'

\$max = UBound(\$aEventData) - 1
\$occurence = 0
\$match = False
\$endIndex = "N/A"
For \$i = 1 To \$max
If \$aEventData[\$i] == \$aEventData[\$i - 1] Then
\$match = True
Else
\$match = False
EndIf

Switch \$match
Case True
If \$occurence = 0 Then
\$occurence = 2
Else
\$occurence += 1
EndIf
\$endIndex = \$i
ConsoleWrite("\$i = " & \$i & ", \$match = " & \$match & ", \$endIndex = " & \$endIndex & ", \$occurence = " & \$occurence & @CR)
Case False
\$endIndex = "N/A"
\$occurence = 0
ConsoleWrite("\$i = " & \$i & ", \$match = " & \$match & ", \$endIndex = " & \$endIndex & ", \$occurence = " & \$occurence & @CR)
EndSwitch
Next```

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

#### Share this post

##### Share on other sites

Thanks, will check it out

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

×

• Wiki

• Back

• Git

## Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.