Public Class Form1
Private num() As Integer = {40, 6, 36, 23, 1}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declarations
'For element of num
Dim list As Integer = 0
'For swapping
Dim temp As Integer = 0
'Outer interation
Dim it As Integer = 1
'Flag to shorten outer interation
Dim no_change As Boolean
'Element change, also -1 because 0 base, -1 again because of list + 1
Dim innerit As Integer = num.Length - 2
'Inner loop
For it = 1 To 4
no_change = True
'Outter loop
For list = 0 To innerit
If num(list) > num(list + 1) Then
'Swap sequence
temp = num(list)
num(list) = num(list + 1)
'Complete swap
num(list + 1) = temp
'Register there is a change
no_change = False
End If
Next
'Largest to bottom, do not include
innerit = innerit - 1
If no_change Then
'If no change, array is sorted, no interation needed
Exit For
End If
'Reset for next iteration
list = 0
Next
ListBox1.DataSource = num
Debug.Print(it)
End Sub
End Class
Monday, February 18, 2008
Thursday, February 14, 2008
Chasing Snoopy Game code
Public Class Form1
Private myrandomnumber As New System.Random
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Label1.Text = (Integer.Parse(Label1.Text) + 1).ToString()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
myrandomnumber.Next(100, 200)
PictureBox1.Location = New Point(myrandomnumber.Next(100, 200), myrandomnumber.Next(100, 200))
End Sub
End Class
Private myrandomnumber As New System.Random
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Label1.Text = (Integer.Parse(Label1.Text) + 1).ToString()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
myrandomnumber.Next(100, 200)
PictureBox1.Location = New Point(myrandomnumber.Next(100, 200), myrandomnumber.Next(100, 200))
End Sub
End Class
Thursday, February 7, 2008
Subscribe to:
Posts (Atom)