Visual Basic Program

You're multiplying by the number of lunches twice, so the figure you end up with is the cost multiplied by the square of the number of lunches.
 
I've moved the first 5 lines but when I run the program and enter a number for example 2, it will then show 12 and if I enter 3, it will then show 27,

Remember, all the computer is doing is running through each line of code in order and doing what that line says. There isn't anything magical going on - you can predict what the computer can do by reading the code.

If the calculation is incorrect then grab a piece of paper and a pen and run through the code by hand. Pretend you are the computer running each line and keep track of the values on the paper. See what result you get, and then you will uncover where the calculation is wrong.
 
Remember, all the computer is doing is running through each line of code in order and doing what that line says. There isn't anything magical going on - you can predict what the computer can do by reading the code.

If the calculation is incorrect then grab a piece of paper and a pen and run through the code by hand. Pretend you are the computer running each line and keep track of the values on the paper. See what result you get, and then you will uncover where the calculation is wrong.

Or just use the debugger :p
 
Set This up.
You need 2 text boxes one called txtNumLunches and one called txtLunchCost
Code:
Private Sub txtNumLunches_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumLunches.KeyPress
        'Accepts only numeric input
        If (Not (Char.IsDigit(e.KeyChar))) And (Not (Char.IsControl(e.KeyChar))) Then
            e.Handled = True
            Beep()
        End If
    End Sub

    Private Sub txtNumLunches_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNumLunches.TextChanged
        Dim numlunches As Integer
        Dim lunchCost As Decimal = 0

        If IsNumeric(txtNumLunches.Text) Then
            numlunches = txtNumLunches.Text
        Else
            numlunches = 1
        End If

        If numlunches >= 10 Then
            lunchCost = numlunches * 2.5
        Else
            lunchCost = numlunches * 3
        End If

        txtLunchCost.Text = lunchCost
    End Sub
 
Last edited:
You have to work out what you want to happen when the Yes option is selected.
Do you want the delivery section to be disabled?
What you are writing may not be filled in the way you expect by the final user.

What happens if the user clicks on the Other radio option then clicks on the Yes radio option, then fills in the number of lunches?

Oh and if that code I posted for the KeyPress event worked, then you are using VB.Net.
 
If the user select Yes, then if possible I want the Delivery column to be disabled or hidden
You could put the controls into a frame and then disabling the frame locks the controls. Or you could disable them individually remembering to re enable them when the user clicks on the No.

That's a good question, if the user select No in the Collect column, is it possible to disable the Collect column
Yes, but you wouldn't want to. What happens if they accidently click on No and change their mind? You've just disabled the control with no way of putting it back.

Also in the Number of Lunches, Delivery and Total Cost textbox where it display the amount, is it possible to lock the textboxes which can only display but no input allow?
Text boxes are for data collection. You can disable them, but they go grey.
For displaying information like costs, turn them into Labels.
 
You could put the controls into a frame and then disabling the frame locks the controls. Or you could disable them individually remembering to re enable them when the user clicks on the No.
How do I do that?

Yes, but you wouldn't want to. What happens if they accidently click on No and change their mind? You've just disabled the control with no way of putting it back.
Good thinking, what would be the best way to do it?

Text boxes are for data collection. You can disable them, but they go grey.
For displaying information like costs, turn them into Labels.
Thanks, I'll change them to Labels
 
How do I do that?

Look for a property of the controls which might help.

The frame is called a GroupBox and should be in your toolbox. Drag it onto the form and then drag the controls you want to group into it.

You will still have to look for the relevant property to set yourself though.


As I said before I'd have the collect option in a drop down list with all the other delivery options. However if you want to stick with one set of options for collection/delivery and one for delivery code then I would use the click event of each of the collection/delivery radio controls to change whether you can click on the delivery code controls. It might even be a good idea to clear the selected delivery option if they select collection.
 
As I said before I'd have the collect option in a drop down list with all the other delivery options. However if you want to stick with one set of options for collection/delivery and one for delivery code then I would use the click event of each of the collection/delivery radio controls to change whether you can click on the delivery code controls. It might even be a good idea to clear the selected delivery option if they select collection.
I've thought about it and have gone with your decision, I've changed it to one section with ComboBox,

vzE.jpg


If user select Collect or Delivery Code C then delivery price will be FREE which is 0, but if user select Other and depending on how many lunches is ordered, if less than 10 lunches, it will cost £2.50 delivery but if 10 or more lunches ordered, it will be FREE which is 0
 
Sorry, I kind of forgot about this thread.
How far have you got now?
I've changed the Delivery option to ComboBox with selection,

vzE.jpg


If user select Collect or Delivery Code C then delivery price will be FREE which is 0, but if user select Other and depending on how many lunches is ordered, if less than 10 lunches, it will cost £2.50 delivery but if 10 or more lunches ordered, it will be FREE which is 0

Also I've changed Textboxes to Labels, how do I make the Label visible so I can click on them and change them as I can't change them when I don't name them
 
Not sure what you mean about making them visible.
Drag a label onto the form, click on it and select properties. Name it properly and there you go.
You won't be able to see them when you run the program until their value is set.
 
I've changed the Delivery option to ComboBox with selection,

vzE.jpg


If user select Collect or Delivery Code C then delivery price will be FREE which is 0, but if user select Other and depending on how many lunches is ordered, if less than 10 lunches, it will cost £2.50 delivery but if 10 or more lunches ordered, it will be FREE which is 0

Also how do I put currency on the Cost label?
 
Back
Top Bottom