Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me Im having trouble getting my data validation to work. here is my code: Public Class Festival Dim OrderNum As Integer = 1000

Please help me Im having trouble getting my data validation to work.

here is my code:

Public Class Festival Dim OrderNum As Integer = 1000 'Declared orderNum as a class level variable Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click If DataOk() = False Then Return End If MessageBox.Show("Data Ok") Dim Hamburgers As String Dim nameRev As String Dim nameFor As String Dim OrderId As String Dim nameFirst As String Dim nameLast As String Dim nameFirstLetter As String Dim nameLastLetter As String 'Declare nameRev, nameFor, OrderId, nameFirst, nameLast, nameFirstLetter, nameLastLetter As String. Hamburgers = txtHamburgers.Text nameRev = txtName.Text 'displays the variable nameRev in the name textbox. nameFirst = nameRev.Substring(0, nameRev.IndexOf(" ")) 'Reverse nameFirst. nameLast = nameRev.Substring(nameRev.IndexOf(" ") + 1) 'Reverse nameLast. nameFor = nameFirst & & nameLast ' combines nameFirst and nameLast nameFirstLetter = nameFirst.Substring(0, 1).ToUpper 'Find the position of the first letter in nameFirst and capitalize it to find the value of nameFirstLetter. nameLastLetter = nameLast.Substring(0, 1).ToUpper 'Find the position of the first letter in nameLast and capitalize it to find the value of nameLastLetter. OrderId = nameFirstLetter & nameLastLetter & OrderNum 'Create the OrderId by adding nameFirstLetter, nameLastLetter, and orderNum. OrderNum += 1 'increases orderNum by 1 for each successful order. lstDisplay.Items.Add(nameFor) lstDisplay.Items.Add(OrderId) 'Display customer Name and OrderId in the listbox. End Sub Function DataOk() As Boolean If txtName.Text = "" Then MessageBox.Show("Name cannot be empty.") txtName.Focus() Return False End If 'If name textbox is empty display error message. If txtHamburgers.Text = "" Then MessageBox.Show("Hamburgers must have a value.") txtHamburgers.Focus() Return False End If 'If Hamburger textbox is empty display error message. If txtFries.Text = "" Then MessageBox.Show("Fries must have a value.") txtFries.Focus() Return False End If 'If Fries textbox is empty display error message. If txtCandy.Text = "" Then MessageBox.Show("Candy must have a value") txtCandy.Focus() Return False End If 'If Candy textbox is empty display error message. If txtDrinks.Text = "" Then MessageBox.Show("Drinks must have a value.") txtDrinks.Focus() Return False End If 'If Drinks textbox is empty display error message. If IsNumeric(txtHamburgers) = False Then MessageBox.Show("Hamburger textbox contains a non-numeric value") txtHamburgers.Focus() Return False End If ' If Hamburger textbox contains a nonnumeric value display error message. If IsNumeric(txtFries) = False Then MessageBox.Show("Fries textbox contains a non-numeric value") txtFries.Focus() Return False End If ' If Fries textbox contains a nonnumeric value display error message. If IsNumeric(txtCandy.Text) = False Then MessageBox.Show("Candy textbox contains a non-numeric value") txtCandy.Focus() Return False End If ' If Candy textbox contains a nonnumeric value display error message. If IsNumeric(txtDrinks) = False Then MessageBox.Show("Drinks textbox contains a non-numeric value") txtDrinks.Text = "" txtDrinks.Focus() Return False Else Return True End If ' If Drinks textbox contains a nonnumeric value display error message. End Function Function OrderId() As String Dim name As String Dim order As String name = "Daniel Thompson" order = OrderId(CInt(name)) MessageBox.Show(order) Return name End Function End Class

Here is my assignment:

image text in transcribed

Form 1: Spring Festival Snackbar Calculator Project: The purpose of this project is to calculate the total price that a customer needs to pay for the snacks that they want to purchase at this year's Spring Festival. Four items are offered for sale at this snack bar: Hamburgers - $3.00 each Fries - $1.00 each Candy - $1.00 each Drinks - $.50 each For each customer order, a unique order Id will be generated. This Id will be comprised of the first initial of the first name followed by the first initial of the last name and then a sequential number starting at 1000 and increasing by 1 for each order placed: for example - if the first customer is Daniel Young, his order ld will be DY1000. FYI: We won't store the order number in a file at this time, so each time you run the program, the order ld will start over at 1000. For this week's lab you need to write and test the following two functions: Data Validation - The following checks should be made as part of your data validation: . Make sure that text has been entered into the name textbox and that this name contains a space. Make sure that a value has been entered into at least ONE of the food item textboxes. (To place an order, the user enters the number of each item that they wish to buy.) . Make sure that any values entered into a food item textbox is a numeric value. Once the Data Validation function has been written, test your code. Check each situation that you test for to make sure the appropriate message is displayed. FYI: I used 7 conditions to check all requirements in my code. Don't forget to Return True if all of the input is found to be valid. To test to see if the program would continue to execute when my input data was valid (the DataOk function returned a True). I displayed a message box that simply let me know that the data was ok (see code sample below) Private Sub btnOrderTotal_Click(...) Handles btnOrder Total. Click If DataOko - False Then Return End If MessageBox.Show("Data Ok") End Sub Order ID - This function should generate and return the Order Id which will be created using the class-level order number variable (doesn't have to be passed) along with the event procedure's local name variable (does have to be passed). This variable will be comprised of the first initial of the first name followed by the first initial of the last name and then a sequential number starting at 1000 and increasing by 1 for each order placed; for example - If the first customer is Daniel Young, his order ld will be DY1000. FYI: We won't store the order number in a file at this time, so each time you run the program, the order ld will start over at 1000. To see if this function executes correctly. I once again used a message box. I also need to give a test value to the name variable within the code since the "GetInput sub has not yet been written. Below is the code that I added after my data validation to test this function. Create a test value for the name variable Dim name, order As String name = "Daniel Thompson order-Orderld(name) MessageBox.Show(order)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

5. Have you any experience with agile software development?

Answered: 1 week ago