Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
38 views

Exercise Coding 1-13

The document contains code examples from 12 coding exercises. The code examples demonstrate how to use Visual Basic .NET to manipulate labels, display text, perform calculations, and display the current time and date when buttons are clicked in a Windows Forms application. Key features shown include setting label text, handling button clicks, performing math operations, and formatting output.

Uploaded by

api-307933836
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Exercise Coding 1-13

The document contains code examples from 12 coding exercises. The code examples demonstrate how to use Visual Basic .NET to manipulate labels, display text, perform calculations, and display the current time and date when buttons are clicked in a Windows Forms application. Key features shown include setting label text, handling button clicks, performing math operations, and formatting output.

Uploaded by

api-307933836
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Exercise 1 Coding

Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Label1.Text = "Noah Harker"
Label2.Text = "Surrey"
Label3.Text = "British Columbia"
End Sub
End Class

Exercise 2 Coding
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Label1.Text = "Lord Tweedsmuir"
Label2.Text = "Tweedsmuir Panthers"
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
End Class

Exercise 3 Code
Public Class Form1
Private Sub RadioButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton1.Click
Label1.Text = "Chris Martin - Vocals/Piano/Guitar"
Label2.Text = "Jonny Buckland - Guitar"
Label3.Text = "Guy Berryman - Bassist"
Label4.Text = "Will Champion - Drums"
End Sub
Private Sub RadioButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton2.Click
Label1.Text = "James Hetfield - Guitar"
Label2.Text = "Kirk Hammett - Lead Guitar"
Label3.Text = "Robert Trujillo - Bassist"
Label4.Text = "Lars Ulrich - Drums"
End Sub
Private Sub RadioButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton3.Click
Label1.Text = "John Lennon - Guitar"
Label2.Text = "George Harrison - Lead Guitar"
Label3.Text = "Paul McCartney - Bassist"
Label4.Text = "Ringo Starr - Drums"

End Sub
End Class

Exercise 4 Code
Public Class Form1
Private Sub RadioButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton1.Click
Label1.Text = "Surrey"
Label2.Text = "British Columbia"
End Sub
Private Sub RadioButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton2.Click
Label1.Text = "Cambridge"
Label2.Text = "Massachusetts"
End Sub
Private Sub RadioButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton3.Click
Label1.Text = "Princeton"
Label2.Text = "New Jersey"
End Sub
Private Sub RadioButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton4.Click
Label1.Text = "Syracuse"
Label2.Text = "New York"
End Sub
Private Sub RadioButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton5.Click
Label1.Text = "East Lansing"
Label2.Text = "Michigan"
End Sub
End Class

Exercise 5 Code
Public Class Form1
Private Sub btnExpression1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExpression1.Click
Me.lblExpression1.Text = "(a + b) + c = a + (b + c)"
End Sub
Private Sub btnExpression2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExpression2.Click
Me.lblExpression1.Text = "a + b = b + a"
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub CommutativeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CommutativeToolStripMenuItem.Click
Me.lblExpression1.Text = "a + b = b + a"
End Sub
Private Sub AssociativeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AssociativeToolStripMenuItem.Click
Me.lblExpression1.Text = "(a + b) + c = a + (b + c)"
End Sub
End Class

Exercise 6 Code
Public Class Form1
Private Sub btnExpression1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExpression1.Click
Me.lblExpression1.Text = "Hello"
End Sub
Private Sub btnExpression2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExpression2.Click
Me.lblExpression1.Text = "Goodbye"
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub HelloToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles HelloToolStripMenuItem.Click
Me.lblExpression1.Text = "Hello"
End Sub
Private Sub GoodbyeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles GoodbyeToolStripMenuItem.Click
Me.lblExpression1.Text = "Goodbye"
End Sub
End Class

Exercise 7 Code
Public Class Form1
Private Sub btnExpression1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExpression1.Click
Me.lblExpression1.Text = 2 * 3.14 * 15
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
End Class

Exercise 8 Code
Public Class Form1
Private Sub btnExpression1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExpression1.Click
Me.lblExpression1.Text = 5 * 3
Me.lblExpression2.Text = 5 * 2 + 3 * 2
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
End Class

Exercise 9 Code
Public Class Form1
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
lblAnswer.Text = (3.0 + 3.3 + 3.5 + 4.0) / 4
End Sub
End Class

Exercise 10 Code
Public Class Form1
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub TopLeftToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TopLeftToolStripMenuItem.Click
With Me.Label1

.TextAlign = ContentAlignment.TopLeft
End With
End Sub
Private Sub TopCenterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TopCenterToolStripMenuItem.Click
With Me.Label1
.TextAlign = ContentAlignment.TopCenter
End With
End Sub
Private Sub TopRightToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TopRightToolStripMenuItem.Click
With Me.Label1
.TextAlign = ContentAlignment.TopRight
End With
End Sub
Private Sub MiddleLeftToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MiddleLeftToolStripMenuItem.Click
With Me.Label1
.TextAlign = ContentAlignment.MiddleLeft
End With
End Sub
Private Sub CenterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CenterToolStripMenuItem.Click
With Me.Label1
.TextAlign = ContentAlignment.MiddleCenter
End With
End Sub
Private Sub MiddleRightToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MiddleRightToolStripMenuItem.Click
With Me.Label1
.TextAlign = ContentAlignment.MiddleRight
End With
End Sub
Private Sub BottomLeftToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BottomLeftToolStripMenuItem.Click
With Me.Label1
.TextAlign = ContentAlignment.BottomLeft
End With
End Sub
Private Sub BottomCenterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BottomCenterToolStripMenuItem.Click
With Me.Label1
.TextAlign = ContentAlignment.BottomCenter
End With
End Sub
Private Sub BottomRightToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BottomRightToolStripMenuItem.Click
With Me.Label1
.TextAlign = ContentAlignment.BottomRight
End With

End Sub
End Class

Exercise 11 Code
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btn1.Click
With Me.lbl1
.Text = "Goodbye"
.AutoSize = False
.TextAlign = ContentAlignment.BottomRight
End With
End Sub
End Class

Exercise 12 Code
Exercise 13 Code
Public Class Form1
Private Sub btntime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btntime.Click
Me.lbltime.Text = TimeOfDay
End Sub
Private Sub btndate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btndate.Click
Me.lbldate.Text = DateString
End Sub
End Class

You might also like