Airfare project (
PowerPoint twodimarray.ppt)
Public Class
frmAirFare
Inherits
System.Windows.Forms.Form
Dim fromCity(3) As String
Dim toCity(2) As String
Dim
priceArray(3, 2) As Single
Private Sub btnGetPrice_Click(ByVal sender
As System.Object, ByVal
e As System.EventArgs) Handles
btnGetPrice.Click
Dim fromPtr As Integer, toPtr As Integer, wkPrice As Single
Dim wkMsg As String
If IsNumeric(txtFrom.Text) And CInt(txtFrom.Text)
< 4 Then
fromPtr = CInt(txtFrom.Text)
If
IsNumeric(txtTo.Text) And CInt(txtTo.Text) < 3 Then
toPtr = CInt(txtTo.Text)
wkPrice = priceArray(fromPtr, toPtr)
wkMsg = "The price to fly from " &
fromCity(fromPtr) & _
" to " & toCity(toPtr) & "
is " & _
FormatCurrency(wkPrice)
txtFare.Text = wkMsg
Else
txtFare.Text = "From City is valid, To City is
not valid"
End If
Else
If
IsNumeric(txtTo.Text) And CInt(txtTo.Text) < 3 Then
txtFare.Text = "From City is not valid, To
City is valid"
Else
txtFare.Text = "Both From City and To City are
invalid"
End If
End If
End Sub
Private Sub frmAirFare_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
MyBase.Load
fromCity(0) = "Boston, MA"
fromCity(1) = "New York, NY"
fromCity(2) = "Austin, TX"
fromCity(3) = "Washington,DC"
toCity(0) = "Istanbul"
toCity(1) = "Baku"
toCity(2) = "London"
priceArray(0, 0) = 800.97
priceArray(0, 1) = 987.98
priceArray(0, 2) = 299.99
priceArray(1, 0) = 745.75
priceArray(1, 1) = 923.45
priceArray(1, 2) = 235.97
priceArray(2, 0) = 967.87
priceArray(2, 1) = 1120.98
priceArray(2, 2) = 496.98
priceArray(3, 0) = 750.75
priceArray(3, 1) = 950.75
priceArray(3, 2) = 250.98
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnClear.Click
txtFrom.Clear()
txtTo.Clear()
txtFare.Clear()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnExit.Click
Me.Close()
End Sub
End Class
Totalairfare
project
Public Class
frmAirFare
Inherits
System.Windows.Forms.Form
Dim fromCity(3) As String
Dim toCity(2) As String
Dim priceArray(3, 2) As Single
Private Sub btnGetPrice_Click(ByVal sender
As System.Object, ByVal
e As System.EventArgs) Handles
btnGetPrice.Click
Dim fromPtr As Integer, toPtr As Integer, wkPrice As Single
Dim wkMsg As String
If IsNumeric(txtFrom.Text) And CInt(txtFrom.Text)
< 4 Then
fromPtr = CInt(txtFrom.Text)
If
IsNumeric(txtTo.Text) And CInt(txtTo.Text) < 3 Then
toPtr = CInt(txtTo.Text)
wkPrice = priceArray(fromPtr, toPtr)
wkMsg = "The price to fly from " &
fromCity(fromPtr) & _
" to " & toCity(toPtr) &
" is " & _
FormatCurrency(wkPrice)
txtFare.Text = wkMsg
Else
txtFare.Text
= "From City is valid, To City is not valid"
End If
Else
If
IsNumeric(txtTo.Text) And CInt(txtTo.Text) < 3 Then
txtFare.Text = "From City is not valid, To
City is valid"
Else
txtFare.Text
= "Both From City and To City are invalid"
End If
End If
End Sub
Private Sub frmAirFare_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
MyBase.Load
fromCity(0) = "Boston, MA"
fromCity(1) = "New York, NY"
fromCity(2) = "Austin, TX"
fromCity(3) = "Washington,DC"
toCity(0) = "Istanbul"
toCity(1) = "Baku"
toCity(2) = "London"
priceArray(0, 0) = 800.97
priceArray(0, 1) = 987.98
priceArray(0, 2) = 299.99
priceArray(1, 0) = 745.75
priceArray(1, 1) = 923.45
priceArray(1, 2) = 235.97
priceArray(2, 0) = 967.87
priceArray(2, 1) = 1120.98
priceArray(2, 2) = 496.98
priceArray(3, 0) = 750.75
priceArray(3, 1) = 950.75
priceArray(3, 2) = 250.98
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnClear.Click
txtFrom.Clear()
txtTo.Clear()
txtFare.Clear()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnExit.Click
Me.Close()
End Sub
Private Sub btnWorthlessTotal_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
btnWorthlessTotal.Click
Dim eachFare As Single, totFare As Single
For Each eachFare In priceArray
totFare = totFare + eachFare
Next
txtWorthlessTotal.Text = FormatCurrency(totFare)
End Sub
Private Sub btnAnother_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnAnother.Click
Dim arrayCol As Integer, arrayRow As Integer, wkTotal As Single
For arrayCol = 0 To 2
For arrayRow = 0 To 3
wkTotal += priceArray(arrayRow, arrayCol)
Next
Next
txtWorthlessTotal.Text = FormatCurrency(wkTotal)
End Sub
End Class