If conditionals
String data type
Methods
Calculate student's grade
* Midterm grade
* Final grade
* Bribe amount
Text property of a textbox has data type of String
Automatically, implicitly, Convert from one data type to another
CDbl
Option Strict On
Val
Option Strict On
Public Class Form1
Private Sub btnCalcGrade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcGrade.Click
' declare variables
Dim midtermGrade, finalGrade, bribe As Double
Dim semesterAvg As Double
' get input
midtermGrade = Val(txtMidterm.Text)
finalGrade = Val(txtFinal.Text)
bribe = Val(txtBribe.Text)
' processing
If bribe >= 50 Then
semesterAvg = 100
Else
semesterAvg = (midtermGrade + finalGrade) / 2
End If
' print out output
lblAverage.Text = CStr(semesterAvg)
End Sub
End Class
HW: convert from f to c, from c to f, based on an if and the value in a textbox
HW: Take the text "The rain in Spain falls mainly on the ground" and separate it into separate words. Print each word on a separate line in a ListBox.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s = "hello"
s = s & " " & "world"
s = s.ToUpper()
s = s.Replace("WORLD", "EARTH")
Dim i As Integer
i = s.IndexOf("EARTH")
MessageBox.Show(i.ToString())
s = s.Substring(6, 5)
Button1.Text = s
End Sub
End Class
No comments:
Post a Comment