Ok so i have to make a car rental application for a programming assignment and we have to use radio buttons that represent small,medium and large and correspond with the values for those sizes, etc( you will see in the code below) and with a confirm booking button the user clicks after they enter full name, CC number and days for hire and then you select which size on the radio buttons which is stored in a parallel array,
obviously to test if it works i test all 3 radio buttons then extract the info as a text file with the bottom buttons code( you will see below) which contains, customer name, CC Number and the cost( days hired * size selected) yet when i open it seems that the last radio button i clicked for the 3rd booking overwrites the others so...
1 days rented = 45(small),65(medium),85(large) yet when i open up the txt documented saved from the application to my desktop they all say 85(large) so it seems like the last radio button used overwrites them all in the parallel array BUT WHYYYYYYYYY!!!!!!!
anyone that fixes this is GENUIS , thanks to who ever tries or helps me :)
!!!CODE BELOW!!!
Public Class FrmCarRental
Const SMALL_RATE As Integer = 45
Const MEDIUM_RATE As Integer = 65
Const LARGE_RATE As Integer = 85
Dim strcarsize As String
Dim intCardNum(20) As Integer
Dim IntDaysHire As Integer
Dim IntNumEntries As Integer = 0
Dim intHireCost(20) As Integer
Dim strfullname(20) As String
Private Sub BtnConfirmBooking_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConfirmBooking.Click
Dim i As Integer
If IntNumEntries >= 20 Then
MessageBox.Show("Arrays are full")
End
Else
If TxtFullName.Text = "" Then
MessageBox.Show("Error Enter a name")
TxtFullName.Focus()
Exit Sub
End If
End If
If Not IsNumeric(TxtCardNum.Text) Then
MessageBox.Show("Error Enter a number")
TxtCardNum.Clear()
TxtCardNum.Focus()
Exit Sub
End If
If Not IsNumeric(TxtDaysHire.Text) Then
MessageBox.Show("Error Enter a number")
TxtDaysHire.Clear()
TxtDaysHire.Focus()
Exit Sub
End If
intCardNum(IntNumEntries) = Convert.ToInt32(TxtCardNum.Text)
IntDaysHire = Convert.ToInt32(TxtDaysHire.Text)
strfullname(IntNumEntries) = TxtFullName.Text
IntNumEntries = IntNumEntries + 1
For i = 0 To IntNumEntries
If RdoSmall.Checked = True Then
intHireCost(i) = IntDaysHire * SMALL_RATE
Else : RdoSmall.Checked = False
End If
If RdoMedium.Checked = True Then
intHireCost(i) = IntDaysHire * MEDIUM_RATE
Else : RdoMedium.Checked = False
End If
If RdoLarge.Checked = True Then
intHireCost(i) = IntDaysHire * LARGE_RATE
Else : RdoLarge.Checked = False
End If
Next
If RdoSmall.Checked = True Then
RdoSmall.Checked = False
ElseIf RdoMedium.Checked = True Then
RdoMedium.Checked = False
ElseIf RdoLarge.Checked = True Then
RdoLarge.Checked = False
End If
TxtFullName.Text = ""
TxtCardNum.Text = ""
TxtDaysHire.Text = ""
TxtFullName.Focus()
End Sub
Private Sub BtnSizeBooking_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSizeBooking.Click
Dim i As Integer
strcarsize = UCase(InputBox("Enter a car size", "Hello"))
If strcarsize.Contains("LARGE") Then
LstOutput.Items.Add("Customers who hired " & strcarsize & " sized cars")
ElseIf strcarsize.Contains("MEDIUM") Then
LstOutput.Items.Add("Customers who hired " & strcarsize & " sized cars")
ElseIf strcarsize.Contains("SMALL") Then
LstOutput.Items.Add("Customers who hired " & strcarsize & " sized cars")
Else
MessageBox.Show("Error Enter a car size of either small, medium or large.")
End If
End Sub
Private Sub BtnHireFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHireFile.Click
Dim i As Integer
Dim OutFile As StreamWriter
SaveFileDialog1.Title = "Name the file you want to send to"
SaveFileDialog1.ShowDialog()
OutFile = File.CreateText(SaveFileDialog1.FileName)
For i = 0 To IntNumEntries 1
OutFile.WriteLine(strfullname(i) & ", " & intCardNum(i) & ", " & intHireCost(i))
Next
OutFile.Close()
End Sub
End Class
obviously to test if it works i test all 3 radio buttons then extract the info as a text file with the bottom buttons code( you will see below) which contains, customer name, CC Number and the cost( days hired * size selected) yet when i open it seems that the last radio button i clicked for the 3rd booking overwrites the others so...
1 days rented = 45(small),65(medium),85(large) yet when i open up the txt documented saved from the application to my desktop they all say 85(large) so it seems like the last radio button used overwrites them all in the parallel array BUT WHYYYYYYYYY!!!!!!!
anyone that fixes this is GENUIS , thanks to who ever tries or helps me :)
!!!CODE BELOW!!!
Public Class FrmCarRental
Const SMALL_RATE As Integer = 45
Const MEDIUM_RATE As Integer = 65
Const LARGE_RATE As Integer = 85
Dim strcarsize As String
Dim intCardNum(20) As Integer
Dim IntDaysHire As Integer
Dim IntNumEntries As Integer = 0
Dim intHireCost(20) As Integer
Dim strfullname(20) As String
Private Sub BtnConfirmBooking_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConfirmBooking.Click
Dim i As Integer
If IntNumEntries >= 20 Then
MessageBox.Show("Arrays are full")
End
Else
If TxtFullName.Text = "" Then
MessageBox.Show("Error Enter a name")
TxtFullName.Focus()
Exit Sub
End If
End If
If Not IsNumeric(TxtCardNum.Text) Then
MessageBox.Show("Error Enter a number")
TxtCardNum.Clear()
TxtCardNum.Focus()
Exit Sub
End If
If Not IsNumeric(TxtDaysHire.Text) Then
MessageBox.Show("Error Enter a number")
TxtDaysHire.Clear()
TxtDaysHire.Focus()
Exit Sub
End If
intCardNum(IntNumEntries) = Convert.ToInt32(TxtCardNum.Text)
IntDaysHire = Convert.ToInt32(TxtDaysHire.Text)
strfullname(IntNumEntries) = TxtFullName.Text
IntNumEntries = IntNumEntries + 1
For i = 0 To IntNumEntries
If RdoSmall.Checked = True Then
intHireCost(i) = IntDaysHire * SMALL_RATE
Else : RdoSmall.Checked = False
End If
If RdoMedium.Checked = True Then
intHireCost(i) = IntDaysHire * MEDIUM_RATE
Else : RdoMedium.Checked = False
End If
If RdoLarge.Checked = True Then
intHireCost(i) = IntDaysHire * LARGE_RATE
Else : RdoLarge.Checked = False
End If
Next
If RdoSmall.Checked = True Then
RdoSmall.Checked = False
ElseIf RdoMedium.Checked = True Then
RdoMedium.Checked = False
ElseIf RdoLarge.Checked = True Then
RdoLarge.Checked = False
End If
TxtFullName.Text = ""
TxtCardNum.Text = ""
TxtDaysHire.Text = ""
TxtFullName.Focus()
End Sub
Private Sub BtnSizeBooking_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSizeBooking.Click
Dim i As Integer
strcarsize = UCase(InputBox("Enter a car size", "Hello"))
If strcarsize.Contains("LARGE") Then
LstOutput.Items.Add("Customers who hired " & strcarsize & " sized cars")
ElseIf strcarsize.Contains("MEDIUM") Then
LstOutput.Items.Add("Customers who hired " & strcarsize & " sized cars")
ElseIf strcarsize.Contains("SMALL") Then
LstOutput.Items.Add("Customers who hired " & strcarsize & " sized cars")
Else
MessageBox.Show("Error Enter a car size of either small, medium or large.")
End If
End Sub
Private Sub BtnHireFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHireFile.Click
Dim i As Integer
Dim OutFile As StreamWriter
SaveFileDialog1.Title = "Name the file you want to send to"
SaveFileDialog1.ShowDialog()
OutFile = File.CreateText(SaveFileDialog1.FileName)
For i = 0 To IntNumEntries 1
OutFile.WriteLine(strfullname(i) & ", " & intCardNum(i) & ", " & intHireCost(i))
Next
OutFile.Close()
End Sub
End Class