|
-
October 8th, 2011, 09:08 AM
#1
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......!!!!!!!!
-
October 9th, 2011, 03:24 PM
#2
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...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
October 9th, 2011, 03:39 PM
#3
Re: Visual Basic Beginner Programming with If then Else statements?
That will get at least a C...
-
October 10th, 2011, 01:52 AM
#4
Re: Visual Basic Beginner Programming with If then Else statements?
 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...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
October 11th, 2011, 05:19 PM
#5
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
-
November 16th, 2011, 11:51 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|