Port Said International Schools – National Section Hand Out Better education for future generations Date: 21/4/2013 Grade: 10 Multiplication table Public Class Form1 Dim fnum, maxnum As Integer Private Sub btn_ShowTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ShowTable.Click fnum = Val(txt_FirstNumber.Text) maxnum = Val(txt_MaxNumber.Text) Dim result As Integer For index As Integer = 1 To maxnum result = fnum * index lb_Table.Items.Add(fnum & " * " & index & " = " & result) Next End Sub Private Sub btn_Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Clear.Click lb_Table.Items.Clear() txt_FirstNumber.Clear() txt_MaxNumber.Text = "" End Sub Private Sub btn_Exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Exit.Click End End Sub End Class Random Picture Position Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Randomize() PictureBox1.Top = Rnd() * 115 PictureBox1.Left = Rnd() * 200 End Sub Port Said International Schools – National Section Hand Out Better education for future generations Date: 21/4/2013 Grade: 10 Show Flags Project( Using buttons) For this project, you want to insert 3 picture boxes, and 3 buttons. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load PictureBox1.Visible = False PictureBox2.Visible = False PictureBox3.Visible = False End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PictureBox1.Visible = True PictureBox2.Visible = False PictureBox3.Visible = False End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click PictureBox1.Visible = False PictureBox2.Visible = True PictureBox3.Visible = False End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click PictureBox1.Visible = False PictureBox2.Visible = False PictureBox3.Visible = True End Sub Show Flags Project( Using Combo Box) For this project, you want to insert a picture boxes, and an image list. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged PictureBox4.Image = ImageList1.Images(ComboBox1.SelectedIndex) End Sub Port Said International Schools – National Section Hand Out Better education for future generations Date: 21/4/2013 Grade: 10 Dice Game Project For this project, you want to insert a picture box, an image list, a timer and a button. Public Class Form1 Dim randomImage As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Timer1.Enabled = True Then Timer1.Enabled = False Else Timer1.Enabled = True End If End Sub The code in the button (The previous code) used to enable and disable the timer. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Randomize() randomImage = Rnd() * 5 PictureBox1.Image = ImageList1.Images(randomImage) End Sub End Class The code in the timer used to get a random number from 0 to 5 and then assign this number as an index to the image list (to get a random image) then put this image in the picture box. Please notice the randomImage variable that is declared in the class scope. Port Said International Schools – National Section Hand Out Better education for future generations Date: 21/4/2013 Grade: 10 Sum Numbers Project For this project, you want to insert 3 text boxes, 3 labels and a button. Public Class Form1 Dim startnum, endnum As Integer Dim total As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click total = 0 startnum = Val(TextBox1.Text) endnum = Val(TextBox2.Text) For index As Integer = startnum To endnum total = total + index Next TextBox3.Text = total End Sub End Class Please notice the startnum, endnum and total variables that are declared in the class scope. The code assigned with the button used to: 1. 2. 3. 4. Declared a total variable and assign a zero value to it. Get the value of the text box1 and assigned it to the startnum variable. Get the value of the text box2 and assigned it to the endnum variable. Make a loop from the value of the startnum variable to the endnum value: a. In each iteration, the total will be equals to the old total + the index. 5. After finishing the loop, the value of the total is assigned to the textbox3