improve my code?

shambles

New member
Joined
Mar 28, 2009
Messages
2
Programming Experience
Beginner
Hi guys i am a first year college student and i am under pressure to get my vb project finished for next week and the problem is i have a maths exam next week that i need to get over 80 perncent in to pass otherwise i fail so basically i haven't got much time to really concentrate on my vb project so please help by telling me how i can improve my code, i am having problems with getting a text box to display the selected content of a combo box that is read in from a text file, and also in the email address it has to contain both the @ and . symbol and therer has to be text both before and after each symbol, please guys any advice you can give me to improve mu code and get it working properly will be greatly appreciated. Thank you

Public Class Form1
Dim Title() As String
Dim Artist() As String
Dim Record_Label() As String
Dim year() As Integer
Dim price() As Single
Dim upperbound As Integer = -1
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
'Displays Form 2
Form2.cboTitle.SelectedIndex = cboTitle1.SelectedIndex
Form2.Show()
Me.Hide()
End Sub

Private Sub cboQuantity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboQuantity.SelectedIndexChanged
'When the quantity is selected it add the quantity to the quantity box in order details

If cboQuantity.SelectedIndex <> -1 Then
txtQuantity.Text = (cboQuantity.Items(cboQuantity.SelectedIndex))
End If
End Sub

Private Sub chkSigned_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSigned.CheckedChanged, chkCard.CheckedChanged, chkWrapped.CheckedChanged

'Check Boxex
'Add the price of the value selected in check box to the extras box in order details
Dim total As Single

If chkSigned.Checked = True Then
total = total + 20.0
End If

If chkCard.Checked = True Then
total = total + 8.5
End If

If chkWrapped.Checked = True Then
total = total + 5.0

End If
txtExtras.Text = total.ToString("c2")
End Sub

Private Sub radStandard_checkchanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radAir.CheckedChanged, radCourier.CheckedChanged, radExpress.CheckedChanged, Radnone.CheckedChanged, radStandard.CheckedChanged
'Radio Buttons
'Add the price of the value selected in radio button to the delivery box in order details

If radAir.Checked = True Then
txtDelivery.Text = FormatCurrency(10.0)

ElseIf radCourier.Checked = True Then
txtDelivery.Text = FormatCurrency(12.0)

ElseIf radExpress.Checked = True Then
txtDelivery.Text = FormatCurrency(7.0)

ElseIf Radnone.Checked = True Then
txtDelivery.Text = FormatCurrency(0)

ElseIf radStandard.Checked = True Then
txtDelivery.Text = FormatCurrency(2.75)


End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Calculates the discount, the subtotal and the total due

Dim price As Single
Dim quantity As Integer
Dim subtotal As Double
Dim discount As Double
Dim total As Double
Dim extras As Double
Dim delivery As Double

If txtDelivery.Text = "" Then
MsgBox("You must select a delivery method")
'txtPrice.Clear()
txtDiscount.Clear()
txtTotaldue.Clear()
txtSubtotal.Clear()
Else
delivery = txtDelivery.Text
'price = txtPrice.Text
'subtotal = price * quantity
'txtSubtotal.Text = ((FormatCurrency(subtotal)))
End If

If cboQuantity.SelectedIndex = -1 Then
MsgBox("You must select a quantity")
Else
quantity = txtQuantity.Text

End If

'extras = txtExtras.Text

'subtotal = price * quantity
subtotal = price * quantity
txtSubtotal.Text = ((FormatCurrency(subtotal)))

If subtotal > 150 Then
discount = subtotal * 0.1
ElseIf subtotal > 100 And subtotal < 150 Then
discount = subtotal * 0.05

End If

txtDiscount.Text = ((FormatCurrency(discount)))

total = subtotal + extras + delivery - discount
txtTotaldue.Text = FormatCurrency(total)
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Clear's the form


cboTitle1.SelectedIndex = -1
cboQuantity.SelectedIndex = -1
radAir.Checked = False
radStandard.Checked = False
radCourier.Checked = False
radExpress.Checked = False
Radnone.Checked = False
chkCard.Checked = False
chkSigned.Checked = False
chkWrapped.Checked = False
txtTitle.Clear()
txtPrice.Clear()
txtQuantity.Clear()
txtDelivery.Clear()
txtExtras.Clear()
txtSubtotal.Clear()
txtDiscount.Clear()
txtTotaldue.Clear()

End Sub

Private Sub btnPayment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPayment.Click

'Display's the form for payment details

Me.Hide()
Form3.Show()
End Sub

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
txtCustomerName.Clear()
txtEmail.Clear()
txtCreditCard.Clear()
txtCreditNumber.Clear()
End Sub

Private Sub btnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirm.Click
If cboTitle1.SelectedIndex = -1 Then
MsgBox("Please select a title")
ElseIf cboQuantity.SelectedIndex = -1 Then
MsgBox("Please select a quantity")
ElseIf txtDelivery.Text = "" Then
MsgBox("You must select a delivery method")
ElseIf cboQuantity.SelectedIndex = -1 Then
MsgBox("You must select a quantity")
ElseIf txtCustomerName.Text = "" Then
MsgBox("Payment details must be entered before order can be processed")
Else


txtCustomerName.Clear()
txtEmail.Clear()
txtCreditCard.Clear()
txtCreditNumber.Clear()
cboTitle1.SelectedIndex = -1
cboQuantity.SelectedIndex = -1
radAir.Checked = False
radStandard.Checked = False
radCourier.Checked = False
radExpress.Checked = False
Radnone.Checked = False
chkCard.Checked = False
chkSigned.Checked = False
chkWrapped.Checked = False
txtTitle.Clear()
txtPrice.Clear()
txtQuantity.Clear()
txtDelivery.Clear()
txtExtras.Clear()
txtSubtotal.Clear()
txtDiscount.Clear()
txtTotaldue.Clear()
Me.Hide()
Form4.Show()
End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim sr As IO.StreamReader = IO.File.OpenText("details.txt")
Do While sr.Peek <> -1

ReDim Preserve Title(i)
ReDim Preserve Artist(i)
ReDim Preserve Record_Label(i)
ReDim Preserve year(i)
ReDim Preserve price(i)
Title(i) = sr.ReadLine
Artist(i) = sr.ReadLine
Record_Label(i) = sr.ReadLine
year(i) = sr.ReadLine
price(i) = sr.ReadLine
i = i + 1
upperbound = upperbound + 1
Loop
For i = 0 To upperbound
cboTitle1.Items.Add(Title(i))
Next
txtTitle.Text = cboTitle1.SelectedItem

End Sub

Private Sub cboTitle1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboTitle1.SelectedIndexChanged
If cboTitle1.SelectedIndex <> -1 Then
txtTitle.Text = (cboTitle1.Items(cboTitle1.SelectedText))
End If
End Sub
End Class
 
Back
Top