5 Replies - 1091 Views - Last Post: 15 October 2009 - 05:34 PM Rate Topic: -----

#1 jackhellstorm27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-October 09

Need Help with my Array Sorting Code

Posted 08 October 2009 - 07:22 AM

Used Listbox named List1 and Command1
This code creates a listbox of 100 random numbers in an array
I'm now trying to get it to sort the listbox but it won't work I
always get the message type mismatch plz help

Dim intMYRANDOMS(100) As Integer
Dim intARRAYSIZE As Integer
Dim intSWITCH1 As Integer
Dim intSWITCH2 As Integer
Dim nC As String
Private Sub Form_Load()
Randomize
For x = 1 To 100 Step 1
intMYRANDOMS(x) = Int(Rnd * 100)
List1.AddItem intMYRANDOMS(x)
Next x
End Sub
Private Sub Command1_Click()
Do Until nC = intARRAYSIZE - 1 ' you can change this to -2 and the bonus number will remain at the end
If intMYRANDOMS(nC) > intMYRANDOMS(nC + 1) Then
	
	MsgBox intMYRANDOMS(nC) & "  " & intMYRANDOMS(nC + 1)
	intSWITCH1 = intMYRANDOMS(nC)
	intSWITCH2 = intMYRANDOMS(nC + 1)
	intMYRANDOMS(nC) = intSWITCH2
	intMYRANDOMS(nC + 1) = intSWITCH1
		If nC = 0 Then
			nC = nC + 1
	   Else
		   nC = nC - 1
	   End If
Else
  nC = nC + 1
End If
   
   
Loop

End Sub


Mod Edit: When you are posting code please use code tags like this. :code:

Is This A Good Question/Topic? 0
  • +

Replies To: Need Help with my Array Sorting Code

#2 magius96  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 75
  • View blog
  • Posts: 834
  • Joined: 15-April 09

Re: Need Help with my Array Sorting Code

Posted 08 October 2009 - 07:33 AM

Please put your code inside the [ code] [ /code] tags, it makes it easier to read. :D

Also, what line is it giving you the error on?

Here's part of your problem though:Dim nC As String
You're declaring nC as a string, but you use it as an Integer. Perhaps you meant to declare nC as an Integer?
Was This Post Helpful? 0
  • +
  • -

#3 jackhellstorm27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-October 09

Re: Need Help with my Array Sorting Code

Posted 08 October 2009 - 09:50 PM

I believe that nC must be a string, really I think my problem could be in the area of declaring what intARRAYSIZE is... the line that troubles me is
 Do Until nC = intARRAYSIZE - 1 

This post has been edited by jackhellstorm27: 08 October 2009 - 09:52 PM

Was This Post Helpful? 0
  • +
  • -

#4 magius96  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 75
  • View blog
  • Posts: 834
  • Joined: 15-April 09

Re: Need Help with my Array Sorting Code

Posted 09 October 2009 - 04:54 AM

intMYRANDOMS(nC)
intMYRANDOMS(nC + 1)

These lines just scream that nC must be an integer.

Heck even Do Until nC = intARRAYSIZE - 1 screams it too.
But hey, as my signature suggests, I'm not an expert.
Was This Post Helpful? 0
  • +
  • -

#5 jackhellstorm27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-October 09

Re: Need Help with my Array Sorting Code

Posted 12 October 2009 - 10:56 AM

You were correct nC is an integer but it still hasn't fixed my first problem, type mismatch
Dim intMYRANDOMS(100) As Integer
Dim intARRAYSIZE As Integer
Dim intSWITCH1 As Integer
Dim intSWITCH2 As Integer
Dim nC As Integer
Private Sub Form_Load()
Randomize
For x = 1 To 100 Step 1
intMYRANDOMS(x) = Int(Rnd * 100)
List1.AddItem intMYRANDOMS(x)
Next x
End Sub
Private Sub Command1_Click()
Do Until nC = intARRAYSIZE - 1 ' you can change this to -2 and the bonus number will remain at the end
If intMYRANDOMS(nC) > intMYRANDOMS(nC + 1) Then
	
	MsgBox intMYRANDOMS(nC) & "  " & intMYRANDOMS(nC + 1)
	intSWITCH1 = intMYRANDOMS(nC)
	intSWITCH2 = intMYRANDOMS(nC + 1)
	intMYRANDOMS(nC) = intSWITCH2
	intMYRANDOMS(nC + 1) = intSWITCH1
		If nC = 0 Then
			nC = nC + 1
	   Else
		   nC = nC - 1
	   End If
Else
  nC = nC + 1
End If
   
   
Loop

End Sub


This post has been edited by jackhellstorm27: 12 October 2009 - 10:56 AM

Was This Post Helpful? 0
  • +
  • -

#6 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,607
  • Joined: 17-April 07

Re: Need Help with my Array Sorting Code

Posted 15 October 2009 - 05:34 PM

i think
still you are not in the right way

seems there is no sorting enable in your code

check out this link

vb6 sorting algorithms

This post has been edited by thava: 15 October 2009 - 05:34 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1