|
-
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.
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
|