Im using visual basic language on visual studio 2010.I want to be asked to enter the cash payed after im done picking the order, now it asks to enter cash after every item i choose.
below you'll find the code and screenshots
Dim choice As String
Dim price As Double
Dim quantity As Integer
Dim total As Double
Dim tpayable As Double
Dim cash As Double
Dim change As Double
Dim spaces As String = Space(4)
Private Sub menue_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim spaces As String = Space(4)
End Sub
Private Sub badd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles badd.Click
quantity = InputBox("enter item quantity", "quantity")
If RadioButton1.Checked Then
choice = "Potato soup"
price = "80"
ElseIf RadioButton2.Checked Then
choice = "Salmon roll"
price = "100"
ElseIf RadioButton3.Checked Then
choice = "Smoked salmon potatos"
price = "75"
End If
If RadioButton4.Checked Then
choice = "Lasagna"
price = "250"
ElseIf RadioButton5.Checked Then
choice = "Cheese burger"
price = "120"
ElseIf RadioButton6.Checked Then
choice = "Pizza"
price = "450"
ElseIf RadioButton7.Checked Then
choice = "ugali & sukuma"
price = "80"
ElseIf RadioButton8.Checked Then
choice = "Chicken fried noodles"
price = "150"
End If
If RadioButton9.Checked Then
choice = "Chocolate fudge cake"
price = "250"
ElseIf RadioButton10.Checked Then
choice = "Ice cream"
price = "150"
ElseIf RadioButton11.Checked Then
choice = "Carrot Cake"
price = "230"
End If
If RadioButton12.Checked Then
choice = "Black tea"
price = "80"
ElseIf RadioButton13.Checked Then
choice = "White tea"
price = "80"
ElseIf RadioButton14.Checked Then
choice = "Coffee"
price = "80"
End If
If RadioButton15.Checked Then
choice = "Coke"
price = "60"
ElseIf RadioButton16.Checked Then
choice = "Milkshake"
price = "110"
ElseIf RadioButton17.Checked Then
choice = "Fanta"
price = "60"
End If
total = quantity * price
tpayable += total
txttpayable.Text = Str(tpayable)
cash = InputBox("enter cash payed")
txtcgiven.Text = Str(cash)
change = cash - tpayable
txtchange.Text = Str(change)
ListBox1.Items.Add(String.Concat(choice & spaces & price & spaces & quantity & spaces & total & spaces & tpayable))
End Sub
screenshot
The application can't read your mind. It can only react to some input from you. You need to handle an appropriate event to let the application know that you have made all the appropriate selections and so it needs to prompt. Looking more closely at your code, it appears that you have several groups of RadioButtons. Assuming that the user must select one option from each group, you can handle the CheckedChanged event of all the RadioButtons and then check whether one is checked from each group. Here's a simplified example using two groups of two that you can extend to any number of groups and controls:
Private Sub RadioButtons_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged,
RadioButton2.CheckedChanged,
RadioButton3.CheckedChanged,
RadioButton4.CheckedChanged
If Panel1.Controls.OfType(Of RadioButton)().Any(Function(rb) rb.Checked) AndAlso
Panel2.Controls.OfType(Of RadioButton)().Any(Function(rb) rb.Checked) Then
'A selection has been made from each group.
End If
End Sub
This assumes that RadioButton1 and RadioButton2 are on Panel1 and RadioButton2 and RadioButton3 are on Panel2. As I said, there can be as many groups as you like and each group can contain as many options as you like. Each group can be on a Panel, a GroupBox or some other container.
Related
from combobox to the dish i used if statement to display my dish in my dish area,
from dish to the list i used:
Dim quantity As Integer
quantity = txtQuantity.Text
If lstDish.SelectedIndex > -1 Then
Dim index1 As Integer
index1 = lstDish.SelectedIndex
Dim item1 As Object
item1 = lstDish.SelectedItem
lstList.Items.Add(item1 & " --> " & quantity)
End If
txtQuantity.Text = 1
The value display at list are will be in form Noodle -> 2
What should i do to get the noodle value as 3.50 * my quantity 2 and add all my sum for the list
Dim Total As Integer
Dim priceOfDish As String = 0
Dim quantity As Integer
Dim friesPrice, garlicBreadPrice, friedChickenWingPrice, springRollPrice As Double
Dim chickenRicePrice, friedRicePrice, curryRicePrice, thaiChickenRice As Double
Dim friedSeafoodNoodlePrice, chickenNoodlePrice, beefNoodlePrice, prawnNoodlePrice As Double
Select Case priceOfDish
Case Is = "Fries"
friesPrice += 2.5
Case Is = "Garlic Bread"
garlicBreadPrice += 2.5
Case Is = "Fried Chicken Wing"
friedChickenWingPrice += 2.5
Case Is = "Spring Roll"
springRollPrice += 2.5
Case Is = "Chicken Rice"
chickenRicePrice += 4
Case Is = "Fried Rice"
friedRicePrice += 4
Case Is = "Curry Rice"
curryRicePrice += 4
Case Is = "Thai Chicken Rice"
thaiChickenRice += 4
Case Is = "Fried Seafood Noodle"
friedSeafoodNoodlePrice += 3.5
Case Is = "Chicken Noodle"
chickenNoodlePrice += 3.5
Case Is = "Beef Noodle"
beefNoodlePrice += 3.5
Case Is = "Prawn Noodle"
prawnNoodlePrice += 3.5
End Select
Total = priceOfDish * quantity
txtTotal.Text = Total
End Sub
code for the total button
I have only included the code to demonstrate one method of getting the total. As several others have mentioned, a Class is probably the best method but I don't think you have reached the use of classes in your course yet.
I have declared 2 form level variables to hold values that can be accessed from more than one method. They do not lose their values at the end of a Sub but maintain them as long as the Form is open. You will need to reset the RunningTotal button to 0 in your Clear button.
When the user selects a category the code resets the value of CategoryCost is set so it is ready if the user chooses to add an item form this category. It is reset every time a new category is chosen.
It is then a simple matter to calculate the cost and add it to the RunningTotal in the AddButton. Then it is displayed in the txtTotal by calling .ToString with the "C2" parameter which stands for Currency with 2 numbers after the decimal point.
Private RunningTotal As Decimal
Private CategoryCost As Decimal
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim Category = ComboBox1.Text
Select Case Category
'Add your code to display the products in each category in the left hand list box
Case "Snack"
CategoryCost = 2.5D
Case "Noodle"
CategoryCost = 3.5D
Case "Rice"
CategoryCost = 4D
Case Else
CategoryCost = 0D
End Select
End Sub
Private Sub AddButton_Click(sender As Object, e As EventArgs) Handles AddButton.Click
'Your code to display the selected item from the left list box in the right list box
'can be entered here.
RunningTotal += CDec(txtQuantity.Text) * CategoryCost
'If you don't want to display a running total, put the following code in a total button
txtTotal.Text = RunningTotal.ToString("C2")
End Sub
You can create a database for store products and a table for products
By this query
Put like this query on button click event
Declare #sum as integer=0
Select #sum=product_cost * “+val(textboxcount.text)+” from product_table where product_name=“+listbox.selelcttext+” <—-listbox selected
Declare a variable in the form and do your calculation in the Add Button (Not Total Button)
Public Class MyForm
dim MyTotal as Double
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
' Do your stuff to move from dishes to the list
MyTotal = MyTotal + (cdbl(txtQuantity.Text) * Price)
End Sub
Private Sub btnTotal_Click(sender As Object, e As EventArgs) Handles btnTotal.Click
txt_Total.text = MyTotal.ToString("N2")
End Sub
End Class
I have been looking over this for the last couple of days and personally I am not to keen on VB, the tab is loading up but I am not getting an answer?
Private Sub Button1_click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Age As Double
Dim seatgrading As Double
Dim Cardaddition As Single
Dim Memberdiscount As Single
Dim installments As Double
Dim totalcost As Double
Dim eachpayment As Integer
Dim total As Single
Dim price As Single
Dim Subtotal As Single
Age = CBOAge.Text
If RBFootball.Checked = True And Age = rbChild.Checked Then
price = 275
ElseIf RBFootball.Checked = True And Age = rbAdult.Checked Then
price = 450
ElseIf RBFootball.Checked = True And Age = rbOAP.Checked Then
price = 295
End If
If RBRugby.Checked = True And Age = rbChild.Checked Then
price = 85
ElseIf RBRugby.Checked = True And Age = rbAdult.Checked Then
price = 175
ElseIf RBRugby.Checked = True And Age = rbOAP.Checked Then
price = 105
End If
' Seat Grades
If RBG1.Checked = True Then
seatgrading = 150
ElseIf RBG2.Checked = True Then
seatgrading = 120
ElseIf RBG3.Checked = True Then
seatgrading = 87.5
End If
total = price + seatgrading
MemberDiscount = installments
If RBBronze.Checked = True Then
MemberDiscount = total * 0.08
ElseIf RBSilver.Checked = True Then
MemberDiscount = total * 0.09
ElseIf RBGold.Checked = True Then
`Cardaddition` = total * 0.025
End If
If RBCard.Checked = True Then
Cardaddition = Subtotal = 0.025
End If
If installments = True Then
installments = total * 0.0375
total = totalcost + installments
eachpayment = totalcost / 12
For count = 1 To 12
installments = installments & "payment" & "is" & Format(eachpayment, "currency") & vbCrLf
Next
End If
total = Subtotal - MemberDiscount + Cardaddition
total = Format(totalcost, "currency")
End Sub
This answer is perhaps more of a way to show you how to get to the code you need than a complete answer.
When dealing with money, it is best to use the Decimal type instead of Single or Double, otherwise the pennies can go wrong after a calculation or two.
You can have an If statement inside another If statement, which can sometimes make for less typing and/or easier reading.
I can't see a need for the age variable because there are already radiobuttons for child/adult/OAP.
The way of calculating the final total price was not clear to me, so I moved some things around into what may or may not be the correct order.
Perhaps the installments variable is meant to be a checkbox for if the payments are going to be taken monthly - I assumed that is the case.
I couldn't see where the results are being presented to the user, so I used MessageBox.Show - I'm sure you will be able to adapt it to how you want to show the total etc.
Private Sub Button1_click(sender As Object, e As EventArgs) Handles Button1.Click
' What I think the variable types are:
' Dim rbChild, rbAdult, rbOAP As New RadioButton
' Dim rbFootball, rbRugby As New RadioButton
' Dim rbG1, rbG2, rbG3 As New RadioButton
' Dim rbBronze, rbSilver, rbGold As New RadioButton
' Dim cbCard As New CheckBox
' Dim cbInstallments As New CheckBox
Dim price As Decimal
If rbFootball.Checked Then
If rbChild.Checked Then
price = 275
ElseIf rbAdult.Checked Then
price = 450
ElseIf rbOAP.Checked Then
price = 295
End If
End If
If rbRugby.Checked Then
If rbChild.Checked Then
price = 85
ElseIf rbAdult.Checked Then
price = 175
ElseIf rbOAP.Checked Then
price = 105
End If
End If
Dim seatgrading As Decimal
If rbG1.Checked Then
seatgrading = 150
ElseIf rbG2.Checked Then
seatgrading = 120
ElseIf rbG3.Checked Then
seatgrading = 87.5D
End If
Dim subtotal As Decimal = price + seatgrading
Dim memberDiscount As Decimal
If rbBronze.Checked Then
memberDiscount = subtotal * 0.08D
ElseIf rbSilver.Checked Then
memberDiscount = subtotal * 0.09D
ElseIf rbGold.Checked Then
memberDiscount = subtotal * 0.025D
End If
Dim cardSurcharge As Decimal
If cbCard.Checked Then
cardSurcharge = subtotal * 0.025D
End If
Dim total As Decimal = subtotal - memberDiscount + cardSurcharge
If cbInstallments.Checked Then
Dim installmentSurcharge = total * 0.0375D
total = total + installmentSurcharge
Dim eachpayment As Decimal = total / 12
MessageBox.Show("Monthly payment is " & eachpayment.ToString("C"))
End If
MessageBox.Show("Total payment is " & total.ToString("C"))
End Sub
I have to write a program that calculates costs for a catering company. i have that part down, but whats stumping me is I have trouble displaying the total. What also is stumping me is that i have to make a summary button that adds everything up into a grand total from the previous calculations and display it in a message box. displaying and calculations aren't really my issues, but getting the data to calculate is.
Thank you
HERE's the code.
Const decPRIME_RIB As Decimal = 25.95D
Const decCHICKEN As Decimal = 18.95D
Const decPASTA As Decimal = 12.95D
Const decOPEN_BAR As Decimal = 25D
Const decWINE As Decimal = 8D
Const decBEER As Decimal = 10D
'Declare module-level variables for summary information.
Private TotalDollar As Decimal
Private AmountDue As Decimal
Private SubTotalDecimal As Decimal
Private TotalDecimal As Decimal
Private Guest As Integer
Private EventCountInteger As Integer
Private Sub CalcBtn_Click(sender As Object, e As EventArgs) Handles CalcBtn.Click
' Calculate and display the current amounts and add to totals.
Dim FoodChoiceDecimal As Decimal
Dim OpenBarDecimal As Decimal
Dim WineDecimal As Decimal
Dim DrinksDecimal As Decimal
' Find the price.
If PrimeRB.Checked Then
FoodChoiceDecimal = decPRIME_RIB
ElseIf ChickRB.Checked Then
FoodChoiceDecimal = decCHICKEN
ElseIf PastaRB.Checked Then
FoodChoiceDecimal = decPASTA
End If
If OpenCB.Checked Then
OpenBarDecimal = decOPEN_BAR
End If
If WineCB.Checked Then
WineDecimal = decWINE
End If
'Multiply price by number of guest and drink selection.
Try
DrinksDecimal = (OpenBarDecimal + WineDecimal)
AmountDue = (FoodChoiceDecimal + DrinksDecimal) * Guest
' display totals.
TotalLbl.Text = TotalLbl.ToString("C")
' Allow change for new event.
OpenCB.Enabled = False
WineCB.Enabled = False
ClearBtn.Enabled = True
SummaryBtn.Enabled = True
Catch NumberOfGuestsException As FormatException
MessageBox.Show("Number of Guests must be Numeric", _
"Data entry Error", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End Try
End Sub
Private Sub SummaryBtn_Click(sender As Object, e As EventArgs) Handles SummaryBtn.Click
' Calculate total dollar amounts and number of events.
Dim MessageString As String
If EventCountInteger > 0 Then
' Calculate the summary sales totals.
TotalDollar += AmountDue
'Concatenate the message string.
MessageString = "Number of Events:" & EventCountInteger.ToString() _
& Environment.NewLine & Environment.NewLine _
& "Total Sales: " & TotalDollar.ToString("C")
MessageBox.Show(MessageString, "Sales Summary", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
This is a very simple code. I am just beginning to use vb. Im making a game where you reorder the shuffled numbers into the correct order. You try to solve the puzzle in the least amount of time and least amount of clicks, and the next time you play, you try to get a lower score (or beat that record). You have sixteen buttons (4x4) and fifteen numbers. There is a checkbutton function to see if the puzzle is solved Every time I debug the program, it highlights the Clicks and FinalTime and says Null Reference Exception was Unhandled. Heres some of the code.
Public Class Form1
Dim Clicks As Integer = 0 'The variable that counts the number of times you clicked
Dim Time As Integer 'The vairable that holds the time
Dim TimeMin As Integer 'The variable that holds the minutes
Dim TimeSec As Integer 'The variable that holds the seconds
Dim FinalTime As String 'The variable that holds the final time (minutes and seconds)
Dim lngArray() As String = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", ""} {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", ""}
Dim NumArray() As Integer
Dim NumArray1() As String
Private Sub CheckButton(ByRef Butt1 As Button, ByRef Butt2 As Button)
If Butt2.Text = "" Then 'Checks if the button around the clicked number is empty "" It's the location of the empty square that you want the number in Butt1 to move to.
Butt2.Text = Butt1.Text 'If it is, the value from Butt2 will "copy and paste" into Butt1
Butt1.Text = "" 'Butt1 will keep the value and the value in Butt2 will clear ""
Clicks += 1 'Incrementing Each click by only 1. It's a counter. In addition, the code above only allows the click to increment by 1 if the number has moved. If you just click on a number that can't move, the click would not count.
End If
If Clicks > 1 Then
lblTotal.Text = Clicks & " Clicks" 'Shows the total amount of clicks when it is greater than one
Else
lblTotal.Text = Clicks & " Click" 'Shows the total amount of clicks when it is one
End If
End Sub
Private Sub CheckSolved() 'A private sub that checks if the puzzle is solved ,restarts the count, and stops the time
Dim strName As String = "" 'The variable that has the string of the winners name
If Me.Button1.Text = "1" And Me.Button2.Text = "2" And Me.Button3.Text = "3" And Me.Button4.Text = "4" And Me.Button5.Text = "5" And Me.Button6.Text = "6" And Me.Button7.Text = "7" And Me.Button8.Text = "8" And Me.Button9.Text = "9" And Me.Button10.Text = "10" And Me.Button11.Text = "11" And Me.Button12.Text = "12" And Me.Button13.Text = "13" And Me.Button14.Text = "14" And Me.Button15.Text = "15" Then 'Checks if the numbers are in the correct buttons
Timer1.Enabled = False 'Stops the time
strName = InputBox("What is your name", "Name of winner") 'Get's the winners name
MessageBox.Show("In " & FinalTime & " , you solved the puzzle in " & Me.Clicks & " clicks! Congratulations " & strName) 'Messagebox showing how many times you clicked to solve the puzzle. It gets the name you typed into the inputbox (strname) and displays it
Call Restart() 'Shuffles the buttons and restarts the game when you win
Call Record(NumArray, NumArray1)
End If
End Sub
Private Sub Record(ByVal NumArray() As Integer, ByVal NumArray1() As String)
'Make timemin array and then make time array. Then make click array
For i As Integer = 0 To 1000
NumArray(i) = Clicks 'This is where the Null Reference error occured
i = +1
Array.Sort(NumArray) 'sorting the array values from least to greatest
Next i
lblRecordClicks.Text = NumArray(0) & " Clicks" 'displaying the lowest number of clicks in the label
For k As Integer = 0 To 1000 'Making an integer that captures 1000 values
NumArray1(k) = FinalTime 'This is where the Null Reference error occured
k = +1
Array.Sort(NumArray1) 'sorting the array values from least to greatest
Next k
lblRecordTime.Text = NumArray1(0) 'displaying the lowest time in the label
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Call Times()
End Sub
Private Sub Shuffle(ByVal lngArray As Object) 'Shuffles the values of the Array
Dim i As Long
Dim iMin As Long
Dim iMax As Long
Dim lngReplace As Long
Dim varSwap As Object
iMin = LBound(lngArray)
iMax = UBound(lngArray)
For i = iMax To iMin + 1 Step -1
lngReplace = Int((i - iMin + 1) * Rnd() + iMin)
varSwap = lngArray(i)
lngArray(i) = lngArray(lngReplace)
lngArray(lngReplace) = varSwap
Next
Button1.Text = lngArray(0)
Button2.Text = lngArray(1)
Button3.Text = lngArray(2)
Button4.Text = lngArray(3)
Button5.Text = lngArray(4)
Button6.Text = lngArray(5)
Button7.Text = lngArray(6)
Button8.Text = lngArray(7)
Button9.Text = lngArray(8)
Button10.Text = lngArray(9)
Button11.Text = lngArray(10)
Button12.Text = lngArray(11)
Button13.Text = lngArray(12)
Button14.Text = lngArray(13)
Button15.Text = lngArray(14)
Button16.Text = lngArray(15)
End Sub
Private Sub RestartToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RestartToolStripMenuItem.Click
Call Restart()
Call Me.btnStart_Click(sender, e) 'Call the button click to enable all buttons
End Sub
Private Sub Times()
Time = Time + 1 'Increase the time by 1 second every interval
TimeSec = TimeSec + 1 'Increase the time by 1 second every interval
TimeMin = Convert.ToInt32(TimeSec \ 60) 'Takes the whole number of the amount of seconds divided by 60 and leaves out the remainder
If Time >= 60 Then
Time = 0
End If
'If the seconds pass 59 (and they do), it restarts to 0
FinalTime = TimeMin & " min " & Time & " seconds" 'Final time is the string displayed showing the final time
lblTime.Text = FinalTime 'The label displays the final time
End Sub
Private Sub Restart()
Time = 0 'Resets the time
Clicks = 0 'Resets the amount of clicks
lblTotal.Text = "" 'Clears the label
lblCheat.Visible = False
lblTotal.Visible = True
lblClicks.Visible = True
lblQuote.Visible = True
lblRecordClicks.Visible = True
lblRecordTime.Visible = True
'If the user cheated and hit the solve button and wants to restart and solve the puzzle on their own, then he can. Turning these label settings to true allows you to see them again
Call Shuffle(lngArray) 'Shuffles the numbers
Timer1.Enabled = True 'Continues the time when it resets to 0
End Sub
Public Sub RefreshEverythingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshEverythingToolStripMenuItem.Click
Timer1.Enabled = False 'Pauses the timer
If MessageBox.Show("Do you want to restart everything?", "Restart Game", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.Yes Then
Time = 0
TimeSec = 0
'Resets the time
Clicks = 0 'Resets the amount of clicks
lblTotal.Text = "" 'Clears the label
lblRecordClicks.Text = "" 'Resets the record click
lblRecordTime.Text = "" 'Resets the record time
End If
Call Shuffle(lngArray) 'Shuffles the numbers
Timer1.Enabled = True 'Continues the timer if no is selected
ReDim NumArray(1000) 'Clears the array data that was captured
ReDim NumArray1(1000) 'Clears the array data that was captured
End Sub
End Class
If you do decide to help (and I HOPE you do) could you try to avoid using "computer" talk and try to "dumb it down for me". Like I said before, I am new at this. Thanks for your time.
You are trying to save the values to an array. When you define an array like Dim NumArray() As Integer there are no bounds set for the array (the array is basically Nothing) and if you then try to access an array item you encounter the Null reference exception.
You only set the array bounds in Public Sub RefreshEverythingToolStripMenuItem_Click. Now I don't know all of your code but if the game is started without the user specifically clicking this button then your array will be Nothing.
You have to make sure that the array bounds are always set before a game is started.
You could also look into more abstract array-like types in .NET. For example you could try a list. A List is practically an array with arbitrary bounds. You define the List with a specific type using the Of keyword and you can then add items to it with the lists Add method, remove items, sort the list etc.
Define as a global variable:
Dim FinalTimes as New List(Of Integer)
Dim FinalClicks as New List(Of Integer)
Make sure you use the New keyword here. This means that a new object of class List will be created. Otherwise you would encounter Null Reference Exceptions on the lines below again.
When the user solves the puzzle you then do:
FinalTimes.Add(FinalTime)
FinalClicks.Add(Clicks)
FinalTimes.Sort
FinalClicks.Sort
This will basically increase the length of the list by one, write the FinalTime/Clicks value into the last item and then resort both lists. Ideas: For a highscore you might want to connect FinalTime, Clicks and Player Name into a structure and use the IComparer Interface to let the user sort the high score list by name/Time/Clicks.
Jens
PS: Before I forget: The For loops in which the exception occured in your code make no real sense. First problem is that in their current forms they would be infinite loops because you always set i to 1 in the loop while the loop ends when i=1000 (which would never happen, obviously). I think you meant i=i+1 or shorter i += 1 there. But they still make little sense. I tried it out to see what happens exactly (which is not obvious :-)) and half of your high score is overwritten by the new value etc. I think the above method will be easier. :-)
I am having problem with a button the code of my button is.
Private Sub btnCalculateCosts_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCalculateCosts.Click
it handles:
' This Calculate Costs button click event handler edits the
' registration(costs) form to ensure it contains valid data.
' Then, after passing control to the business class, it
' displays the registration cost.
Dim objCourse As Course
Dim objCourseCostsFile As Course
Dim InputError As Boolean = False
' Is student ID entered properly
If Me.txtCorporateID.MaskFull = False Then
MessageBox.Show("Enter your Corporate ID in the Corporate ID box", "Error")
Me.txtCorporateID.Clear()
Me.txtCorporateID.Focus()
InputError = True
' Is student name entered properly
ElseIf Me.txtFirstName.TextLength < 1 Or _
Me.txtFirstName.Text < "A" Then
MessageBox.Show("Please enter your first name in the First Name box", "Error")
Me.txtFirstName.Clear()
Me.txtFirstName.Focus()
InputError = True
' Is number of units entered properly
ElseIf Me.txtLastName.TextLength < 1 Or _
Me.txtLastName.Text < "A" Then
MessageBox.Show("Please enter your last name in the Last Name box", "Error")
Me.txtLastName.Clear()
Me.txtLastName.Focus()
InputError = True
' Is number of units entered properly
ElseIf Not IsNumeric(Me.txtNumberOfDays.Text) Then
MessageBox.Show("Enter the units in the Number of Units box", "Error")
Me.txtNumberOfDays.Clear()
Me.txtNumberOfDays.Focus()
InputError = True
' Has 1-4 units been entered
ElseIf Convert.ToInt32(Me.txtNumberOfDays.Text) < 1 _
Or Convert.ToInt32(Me.txtNumberOfDays.Text) > 4 Then
MessageBox.Show("Units must be 1 - 4", "Error")
Me.txtNumberOfDays.Clear()
Me.txtNumberOfDays.Focus()
InputError = True
End If
' If no input error, process the registration costs
If Not InputError Then
If Me.radPreConferenceCourse.Checked = False Then
objCourse = New Course(txtCorporateID.Text, txtFirstName.Text, txtLastName.Text, txtNumberOfDays.Text)
Me.lblCosts.Visible = True
Me.lblCosts.Text = "Total Conference Costs Are: " & (objCourse.ComputeCosts()).ToString("C2")
Else
objCourse = New Course(txtCorporateID.Text, txtFirstName.Text, txtLastName.Text, txtNumberOfDays.Text, g)
Me.lblCosts.Visible = True
Me.lblCosts.Text = "Total Conference Costs Are: " & (objCourse.ComputeCosts()).ToString("C2")
....
Receiving the error:
Handles clause requires a WithEvents variable defined in the
containing type or one of its base types.
Where is btnCalculateCosts defined? – SLaks 14 hours ago