Visual Basic Beginner Programming with If then Else statements?
I am trying to create a program that calculates the prices of different payment methods of a buffet. I have started it but has run into some unknown problem and hoping someone could guide me.
The program requirements are simple. The buffet start in 1/7/2011 and ends 31/8/2011. Payments methods are online, cash and coupon. coupon is only valid from 1/8/2011 to 31/8/ 2011. 1 child is free for every 2 adult that pay. There are different prices for weekends (sat and sun) and different prices for weekdays.
So my program is like this so far: Please assume all variables are declared
If scheduleDate < #7/1/2011# Or scheduleDate > #8/31/2011# Then
MessageBox.Show("Beyond promotion period")
Exit Sub
ElseIf adult <= 0 And senior <= 0 And childlow <= 0 And childhigh <= 0 Then
MessageBox.Show("Please enter at least one person")
Exit Sub
to deduce the number of child paying, I came up with this:
ElseIf CInt(txtAdult.Text) \ 2 < CInt(txtChildLow.Text) Then 'adult number < child number
payingChild = CInt(txtChildLow.Text) - _
CInt(txtAdult.Text) \ 2
Else
payingChild = 0
And then I don't know how to carry on. Please help......!!!!!!!!
Re: Visual Basic Beginner Programming with If then Else statements?
Nested IF THEN ELSE can and will get very confusing and difficult if changes need be done.. also I find using Select case for conditions that have more than two options is better.
Break it down to steps and Later do all the calculations..
IE
Code:
Adults = Cint(txtAdult.Text)
Child = CInt(txtChildLow.Text)
'Select the price for the day
Select case DayOfWeek
case "Monday", "Tuesday", "Wednesday", "Thursday"
AdultPrice = 10
ChildPrice = 8
case "Friday"
AdultPrice = 15
ChildPrice = 8
case "Saturday"
AdultPrice = 20
ChildPrice = 15
case "Sunday"
AdultPrice = 20
ChildPrice = 10
End Select
'Calculate max free Child meals..
Freechild = Cint(Adults / 2)
'Work out paying child meals
If Freechild >= Child then
PayChild = 0
Else
PayChild = Child - Freechild
End If
'Now calculate final Price..
Total = Adults * Adult Price + Paychild * Child Price
So here I've shown you how to calculate According to the day of the week, you can aplly the same logic to use promotions...
Re: Visual Basic Beginner Programming with If then Else statements?
That will get at least a C...
Re: Visual Basic Beginner Programming with If then Else statements?
Quote:
Originally Posted by
dglienna
That will get at least a C...
and if he follows this simple format to the complete project, i could see at minimum a B+...
Unless the the task specifically says 'Using only Nested If then Else', use every tool in the VB box...
Re: Visual Basic Beginner Programming with If then Else statements?
In that case, use Case TaskCtr
Code:
select 1
...
TaskCtr += 1
select 2
...
TaskCtr += 1
select 3
...
TaskCtr += 1
select 4
...
TaskCtr += 1
end select
Re: Visual Basic Beginner Programming with If then Else statements?
Question basically comes from the Marketing and research.But this is important that coding also helps a lot when marketer do some research on any topic.