Help with code!!

TECKSPEED

New member
Joined
Apr 15, 2013
Messages
4
Programming Experience
Beginner
Hi all new to the forum and Im needing a bit of help with my code here.

Below is my code


VB.NET:
Public Class frmConferenceRegistration

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

        Const REGISTRATION_PRICE As Integer = 895
        Const OPENING_DINNER_KEYNOTE As Integer = 30
        Const WORKSHOP_295 As Integer = 295
        Const WORKSHOP_395 As Integer = 395
        
        'Create an instance of the Conference Options Form
        Dim frmConferenceOptions As New frmConferenceOptions
        frmConferenceOptions.ShowDialog()

        'Checks to see if Conference Registration is check, if not it displays an error and asks the user to select it.
        If frmConferenceOptions.chkConferenceRegistration.Checked = False Then
            MessageBox.Show("Please select Conference Registration when you see the Conference Options Dialog box again!", "Error!")

            'Computes the total based off of the two checkboxes 
            'If Conference Registration is check total = 895.
            'If both checkboxes are checked then the total is 925
        ElseIf frmConferenceOptions.chkConferenceRegistration.Checked = True Then
            lblTotalAmount.Text = REGISTRATION_PRICE.ToString("c")
            If frmConferenceOptions.chkDinnerAndKeynote.Checked = True Then
                If frmConferenceOptions.chkConferenceRegistration.Checked Then
                    lblTotalAmount.Text = (REGISTRATION_PRICE + OPENING_DINNER_KEYNOTE).ToString("c")
                End If
            End If
        End If

        'Calculates the listbox prices based on the selection that is made
        If frmConferenceOptions.lstboxOptions.SelectedIndex = 0 Then
            lblTotalAmount.Text = CDec(REGISTRATION_PRICE + OPENING_DINNER_KEYNOTE + WORKSHOP_295).ToString("c")
            If frmConferenceOptions.lstboxOptions.SelectedIndex = 1 Then
                lblTotalAmount.Text = CDec(REGISTRATION_PRICE + OPENING_DINNER_KEYNOTE + WORKSHOP_295).ToString("c")
                If frmConferenceOptions.lstboxOptions.SelectedIndex = 2 Then
                    lblTotalAmount.Text = CDec(REGISTRATION_PRICE + OPENING_DINNER_KEYNOTE + WORKSHOP_395).ToString("c")
                Else : frmConferenceOptions.lstboxOptions.SelectedIndex = 3
                    lblTotalAmount.Text = CDec(REGISTRATION_PRICE + OPENING_DINNER_KEYNOTE + WORKSHOP_395).ToString("c")
                End If
            End If
        End If
    End Sub

    Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnReset_Click(sender As System.Object, e As System.EventArgs) Handles btnReset.Click

        'Resets all labels 
        lblTotalAmount.Text = String.Empty
        txtAddress.Clear()
        txtCity.Clear()
        txtCompany.Clear()
        txtEmail.Clear()
        txtName.Clear()
        txtPhone.Clear()
        txtState.Clear()
        txtZip.Clear()
    End Sub
End Class


I have a list box with four items in it,

-Introduction to Ecommerce
-The Future of the Web
- Advanced Visual Basic
- Network Security

The first two entries need to cost $295, and the last two need to cost $395. The project has two form one being the main form (Conference Registration System) and a sub form (Conference Options), the conference options has a list box that has the above entries in it and I need to have the user check a check box to make sure they are attending the conference once that is done the user can choose an optional dinner and keynote and an options workshop. I have the initial conference fee and optional dinner and keynote checkbox correct, but the list box is where im struggling. I cant get the computations right for the list box.

If someone could point me in the right direction that would be great.

I am following a book and have read and read and read it over and over and over and am having no luck, thus is why i am here.

Thanks guys,

TECK
 
There are numerous ways that this could be done but, under the circumstances, the simplest option is a Select Case for the SelectedIndex of the ListBox, e.g.
Select Case myListBox.SelectedIndex
    Case 0, 1
        'One of first two items selected.
    Case 2, 3
        'One of last two items selected.
    Case Else
        'No item selected.
End Select
 
There are numerous ways that this could be done but, under the circumstances, the simplest option is a Select Case for the SelectedIndex of the ListBox, e.g.
Select Case myListBox.SelectedIndex
    Case 0, 1
        'One of first two items selected.
    Case 2, 3
        'One of last two items selected.
    Case Else
        'No item selected.
End Select

I wasn't sure exactly if I could use that and it was that simple or if I had to use a module and do it that way. How exactly would I implement that select case into my code? Just put it around the list box code I already have?


Sent from my iPhone using Tapatalk 2
 
You place code like that wherever you want to do something based on the SelectedIndex of the ListBox. You add code to each case that you want executed in that case.
 
Thanks, that solved that issue but now im having another issue. When the user checks Conference Registration but not Opening Night Dinner and Keynote, my calculations are still including the dinner and keynote. Should i use another if loop to get rid of that or how should i go about it?

THanks for your help,

TECK
 
Never mind I figured it out myself, I used the select case in a nested if loop and got it working perfectly, thank you for your help.


Sent from my iPhone using Tapatalk 2
 
Back
Top