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.
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
Or just use the debugger![]()
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.If the user select Yes, then if possible I want the Delivery column to be disabled or hidden
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.That's a good question, if the user select No in the Collect column, is it possible to disable the Collect column
Text boxes are for data collection. You can disable them, but they go grey.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?
How do I do that?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.
Good thinking, what would be the best way to do it?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.
Thanks, I'll change them to LabelsText boxes are for data collection. You can disable them, but they go grey.
For displaying information like costs, turn them into Labels.
How do I do that?
I've thought about it and have gone with your decision, I've changed it to one section with ComboBox,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 changed the Delivery option to ComboBox with selection,Sorry, I kind of forgot about this thread.
How far have you got now?