HW:
Sub Procedures, Part I
question 6, 8, 36, 38, 48-54 even
look at answer to one of the odd questions to get a sense of how to do it.
answer to q 38 for If blocks
If year mod 400 = 0 Then
'leap
ElseIf year mod 100 = 0 Then
' not leap
ElseIf year mod 4 = 0 Then
'leap
Else
' not leap
Endif
' leap year
If year mod 400 = 0 Or (year mod 100 <> 0 And year mod 4 = 0) Then
MsgBox("Leap year!")
MessageBox.Show("Leap year!")
Else
MsgBox("Not a leap year!")
Endif
Write a program that allows the user to use a button to toggle the color of the text in a text box between black and red.
' this will NOT work
If textbox1.ForeColor = Color.Black Then
textbox1.ForeColor = Color.Red
Endif
If textbox1.ForeColor = Color.Red Then
textbox1.ForeColor = Color.Black
Endif
' this WILL work
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.ForeColor = Color.Black Then
TextBox1.ForeColor = Color.Red
Else ' If TextBox1.ForeColor = Color.Red Then
TextBox1.ForeColor = Color.Black
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.ForeColor = Color.Black
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Visible = Not TextBox1.Visible
End Sub
biggest:
Public Class Form1
Dim biggest As Integer
Dim secondBiggest As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim theNum As Integer
theNum = Val(TextBox1.Text)
If theNum >= biggest Then
' update my maxes
secondBiggest = biggest
biggest = theNum
ElseIf theNum > secondBiggest Then
secondBiggest = theNum
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.ForeColor = Color.Black
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button2.Text = "Biggest: " & biggest & vbTab & "SecondBiggest: " & secondBiggest
End Sub
End Class
No comments:
Post a Comment