# Sorting in a 2D array, VB6

Page 1 of 1

## 3 Replies - 3408 Views - Last Post: 20 February 2009 - 05:05 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=87400&amp;s=6d5b39009e1a2b1cd56b5e1d23662444&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 raspsaysthewaffle

• New D.I.C Head

Reputation: 0
• Posts: 2
• Joined: 18-February 09

# Sorting in a 2D array, VB6

Posted 18 February 2009 - 02:54 AM

```Dim row As Integer
Dim col As Integer

MsgBox " Activate Caps Lock Now "

'Input results

For col = 0 To 8
For row = 0 To 2
If row = 0 Then Call validatename(x)
If row = 1 Then Call validatenumber(x)
If row = 2 Then x = " seconds "
twodarray(col, row) = x
Next row
Next col

'sort results
Do
NoSwaps = True
For i = 0 To 8 - 1
If twodarray(i, 1) > twodarray((i + 1), 1) Then

temp = twodarray((i + 1), 1)
twodarray((i + 1), 1) = twodarray(i, 1)
twodarray(i, 1) = temp

temp2 = twodarray((i + 1), 0)
twodarray((i + 1), 0) = twodarray(i, 0)
twodarray(i, 0) = temp2

NoSwaps = False
End If
Next i
Loop Until NoSwaps

For col = 0 To 8
For row = 0 To 2
Picture1.Print Tab(row * 35); twodarray(col, row);
Next row
Picture1.Print
Picture1.Print
Next col

```

This code will sort the numeric values contained in the array, however when dealing with numeric values above nine the sort algorithm seems only to register the value of the units in the array space. If anyone knows why could they please leave their suggestion as to why.

Is This A Good Question/Topic? 0

## Replies To: Sorting in a 2D array, VB6

### #2 luigiplumbersinc

Reputation: 4
• Posts: 82
• Joined: 16-February 09

## Re: Sorting in a 2D array, VB6

Posted 18 February 2009 - 05:21 PM

i dont think i understand you problem what do you mean
"when dealing with numeric values above nine the sort algorithm seems only to register the value of the units in the array space"

as the sort runs through with 8 results (array index 0-7) checking to see if its larger than the next it should look something like

2 2 2 1 1
4 4 1 2 2
5 1 4 4 4
1 5 5 5 5
7 7 7 7 7
8 8 8 8 8
10 9 9 9 9
9 10 10 10 10
11 11 11 11 11

regardless of whether one of the values is above 9
perhaps the problem is in your validatenumber(x) procedure
im assuming x is a public variant as you assign it both string and integer values...

Goodluck

### #3 raspsaysthewaffle

• New D.I.C Head

Reputation: 0
• Posts: 2
• Joined: 18-February 09

## Re: Sorting in a 2D array, VB6

Posted 20 February 2009 - 03:18 AM

The problem is that if the values

1 11 16 2 3 4 5 6 7

were added to this sort then the final sorted result would be

1 11 16 2 3 4 5 6 7

This seems to be because the first value of each number is only seen in the sort .

### #4 luigiplumbersinc

Reputation: 4
• Posts: 82
• Joined: 16-February 09

## Re: Sorting in a 2D array, VB6

Posted 20 February 2009 - 05:05 AM

raspsaysthewaffle, on 20 Feb, 2009 - 02:18 AM, said:

The problem is that if the values

1 11 16 2 3 4 5 6 7

were added to this sort then the final sorted result would be

1 11 16 2 3 4 5 6 7

This seems to be because the first value of each number is only seen in the sort .

well from what i can see that means there much be a problem with the way you defined the variable "twodarray" please post this code as a suggest this would be appropriate
```dim twodarray(8) as String

```

and then when setting score values
```twodarray(index) = str(validatenumber(x))

```

and then when sorting the values
```if Val(twodarray(i)) > Val(twodarray(i + 1)) then

```