CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2011
    Posts
    1

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

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Visual Basic Beginner Programming with If then Else statements?

    That will get at least a C...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Visual Basic Beginner Programming with If then Else statements?

    Quote Originally Posted by dglienna View Post
    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Nov 2011
    Posts
    1

    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
  •  





Click Here to Expand Forum to Full Width

Featured