Just3ala2
08-16-04, 08:10 PM
hi to all
this is my code
but it doesn't work
u all know the bubble sort
i needed to visualise it on vb.net
i used a group of columns to display the number weight and a group of numeric updowns for the input
i have two buttons, draw and sort
the draw works fine but the problem is in the sort part
here is the full code
************************************************** *******
Private Sub BubbleSort_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Function bubbleSort() As Integer
Dim incounter As Integer = 0
Dim outcounter As Integer = 0
For outcounter = 0 To 9
For incounter = 0 To 8
If grpValues.Controls(incounter).Text > grpValues.Controls((incounter + 1)).Text Then
swap(incounter, (incounter + 1))
End If
Next
Next
Return 0
End Function
Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
Pic1.Height = Convert.ToInt16(nud1.Value) * 3
Pic2.Height = Convert.ToInt16(nud2.Value) * 3
Pic3.Height = Convert.ToInt16(nud3.Value) * 3
Pic4.Height = Convert.ToInt16(nud4.Value) * 3
Pic5.Height = Convert.ToInt16(nud5.Value) * 3
Pic6.Height = Convert.ToInt16(nud6.Value) * 3
Pic7.Height = Convert.ToInt16(nud7.Value) * 3
Pic8.Height = Convert.ToInt16(nud8.Value) * 3
Pic9.Height = Convert.ToInt16(nud9.Value) * 3
Pic10.Height = Convert.ToInt16(nud10.Value) * 3
End Sub
Private Sub btnSort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSort.Click
bubbleSort()
End Sub
Private Function swap(ByRef x As Integer, ByRef y As Integer) As Integer
Dim Temploc As Point
Temploc = PicTemp.Location
If x <> y Then
grpVisual.Controls(21).Location = grpVisual.Controls(x).Location
grpVisual.Controls(x).Location() = grpVisual.Controls(y).Location
grpVisual.Controls(y).Location = grpVisual.Controls(21).Location
End If
PicTemp.Location = Temploc
End Function
Private Sub TimerBubbles_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerBubbles.Tick
picBub1.Top -= 4
If picBub1.Top < -20 Then
picBub1.Top = Me.Height - 20
End If
picBub2.Top -= 4
If picBub2.Top < -20 Then
picBub2.Top = Me.Height - 20
End If
picBub3.Top -= 4
If picBub3.Top < -20 Then
picBub3.Top = Me.Height - 20
End If
picBub4.Top -= 4
If picBub4.Top < -20 Then
picBub4.Top = Me.Height - 20
End If
End Sub
************************************************** ********
i'll be grateful for ur help
this is my code
but it doesn't work
u all know the bubble sort
i needed to visualise it on vb.net
i used a group of columns to display the number weight and a group of numeric updowns for the input
i have two buttons, draw and sort
the draw works fine but the problem is in the sort part
here is the full code
************************************************** *******
Private Sub BubbleSort_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Function bubbleSort() As Integer
Dim incounter As Integer = 0
Dim outcounter As Integer = 0
For outcounter = 0 To 9
For incounter = 0 To 8
If grpValues.Controls(incounter).Text > grpValues.Controls((incounter + 1)).Text Then
swap(incounter, (incounter + 1))
End If
Next
Next
Return 0
End Function
Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
Pic1.Height = Convert.ToInt16(nud1.Value) * 3
Pic2.Height = Convert.ToInt16(nud2.Value) * 3
Pic3.Height = Convert.ToInt16(nud3.Value) * 3
Pic4.Height = Convert.ToInt16(nud4.Value) * 3
Pic5.Height = Convert.ToInt16(nud5.Value) * 3
Pic6.Height = Convert.ToInt16(nud6.Value) * 3
Pic7.Height = Convert.ToInt16(nud7.Value) * 3
Pic8.Height = Convert.ToInt16(nud8.Value) * 3
Pic9.Height = Convert.ToInt16(nud9.Value) * 3
Pic10.Height = Convert.ToInt16(nud10.Value) * 3
End Sub
Private Sub btnSort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSort.Click
bubbleSort()
End Sub
Private Function swap(ByRef x As Integer, ByRef y As Integer) As Integer
Dim Temploc As Point
Temploc = PicTemp.Location
If x <> y Then
grpVisual.Controls(21).Location = grpVisual.Controls(x).Location
grpVisual.Controls(x).Location() = grpVisual.Controls(y).Location
grpVisual.Controls(y).Location = grpVisual.Controls(21).Location
End If
PicTemp.Location = Temploc
End Function
Private Sub TimerBubbles_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerBubbles.Tick
picBub1.Top -= 4
If picBub1.Top < -20 Then
picBub1.Top = Me.Height - 20
End If
picBub2.Top -= 4
If picBub2.Top < -20 Then
picBub2.Top = Me.Height - 20
End If
picBub3.Top -= 4
If picBub3.Top < -20 Then
picBub3.Top = Me.Height - 20
End If
picBub4.Top -= 4
If picBub4.Top < -20 Then
picBub4.Top = Me.Height - 20
End If
End Sub
************************************************** ********
i'll be grateful for ur help