• 0

create if...elseif statement Visual basic


Question

Write an If..ElseIf  statement (or Select Case if you prefer) given the following:

 

decTicketPrice                    ?ticket price

intAge                                  ?age of customer   

 

If customer's age is less than 6, ticket price is Free

 

If customer's age is 6 to 12, ticket price is $3.50

 

If customer's age is 13 to 19, ticket price is $4.50

 

If customer's age is over 62, ticket price is $5.50

 

Otherwise, ticket price is $7.50

Recommended Posts

  • 0

Do the teachers these days throw assignments at students without teaching them anything, nor equipping them with textbooks?

I'm sure they do, but the student would need to pay attention...But, why pay attention when all you have to do is ask on a forum?

  • 0

Google would show you quite clearly how to do If and ElseIf statements in VB.NET just so you know. MSDN is a great resource as well, I came to learn this rather quickly. As for your question;

http://msdn.microsoft.com/en-us/library/752y8abs.aspx

  • 0

what we need to start doing is writing the most convoluded and syntatically poor way of answering the homework questions as possible.  And whenever someone asks for help we need to write something that the teacher would look at and say WTF.

  • 0

I do know how to do them I just need to do them quickly and I take awhile when I write my code

Wouldn't it be better to learn how to do it more quickly yourself rather than having others write it up for you? How do you intend to function in job that revolves around this language? You can't just turn to your co-worker and say "Hey could you write up this elseif statement for me?".

  • Like 3
  • 0

Wouldn't it be better to learn how to do it more quickly yourself rather than having others write it up for you? How do you intend to function in job that revolves around this language? You can't just turn to your co-worker and say "Hey could you write up this elseif statement for me?".

 

Im taking this class for fun and credits

  • 0

Im taking this class for fun and credits

Either way you should still learn to do it yourself. No one is going to write up your code for you. In the time you've sat here and tried to get someone to do so you should have been able to write it up yourself which even if it is slow, you improve with each time you do it. It becomes more second nature to you.

Ask to learn, not to be lazy.

  • 0

It's also important to remember that when you post a question you are asking volunteers to spend their free time trying to help you. Most of the time people don't mind doing that - it is why the majority of us joined Neowin after all - but posting mundane questions that you could easily lookup in your text book or elsewhere online feels like abusing those same people's good will. Not to mention the fact that posting many of this type of question in a short time period is likely to burn people out. As others have already offered, I would be happy to offer my advice to help you solve, and more importantly understand, a nontrivial programming problem, but just seeing the sheer volume of these threads you have posted in the last week has already made me leery of investing my time.

  • 0

I need help creating that code

You clearly are not trying to help yourself in that regard. You should be attempting it yourself instead of getting others to write it up. If you really hit a roadblock and not a physical (lazyness) one then feel free to post a question.

  • 0

Your problem seems to be primarily with programming logic - which is not specific to any language - and very little with VB syntax. Nothing will help you more than reading the documentation and working through the logic yourself. Once you do that a few times you will start to develop an aptitude and be able to write programs much more quickly. Although you will likely need to learn more useful languages at some point in your programming career, probably sooner rather than later, this course is trying to teach you how to program much more than Visual BASIC syntax. If you can get into the programming mindset - the how to program I just mentioned - learning the syntax for other languages becomes much easier. Ask us specific questions when you get stuck, but not just for whole answers to your homework problems. Like I am trying to explain, that won't help you in the long run anyway.

 

The question of syntax for this specific problem is more-or-less explicitly solved by the MSDN article Lord Method Man linked to a couple posts above mine. As for the logic, I have already stated that I don't believe directly giving you the answer will help you learn. Not only that, but I don't know Visual BASIC, nor do I have any intention of learning it. As a compromise I implemented the program you need in Perl. It is heavily commented to explain my logic, and you will need to think it through, at least to some degree, to combine it with the MSDN instructions above to create a valid Visual BASIC program. I hope that helps.

#!/usr/bin/perl

# Given age of a customer print the ticket price.
#
# Arguments:
#   age [in]        Age of customer
#
# Return Value:
#   The price of the customer's ticket will be returned.
sub ticket_price_by_age
{
    # Declare variables used in this function along with a succinct description of each.
    # This is not strictly necessary, but it is generally considered good practice.
    my $age; # Age of the customer
    my $price; # Price of the customer's ticket
    
    # Check to make sure that the customer's age was given as an argument,
    # and that the argument makes sense. If no age was given or the age is not
    # a natural number we need to exit the script with a brief error message.
    $age = $_[0] or die "Customer's age must be given!\n";
    $age =~ /^[0-9]+$/ or die "Customer's age must be a positive integer!\n";
    
    # Use a simple if..else statement to implement the core logic of the script.
    # Since each statement is evaluated in order, it makes sense to evaluate the
    # customer's age from least to greatest so we only need to implement one
    # check per branch. For example, when evaluating the second if statement
    # ("elsif ($age <= 12)") we know that the customer is at least 7 years old
    # because we would not have reached this statement if that were not the case.
    # Similarly we know that the customer is at least 13 years old when we reach
    # the third if statement ("elsif ($age <= 19)") for the same reason.
    if ($age <= 6)
    {
        $price = 0.0;
    }
    elsif ($age <= 12)
    {
        $price = 3.50;
    }
    elsif ($age <= 19)
    {
        $price = 4.50;
    }
    elsif ($age <= 62)
    {
        $price = 7.50;
    }
    else
    {
        $price = 5.50;
    }
    
    # Display the price of the customer's ticket on the screen.
    #
    # Digression: There are a few things in this statement that are specific to
    # Perl syntax, and therefore probably make it somewhat less clear from a VB
    # programmer's perspective. The "\$" is just escaping the "$" so only "$"
    # will print. The sprintf() function is used to print two decimal places in
    # the price, as is customary for fiat currency. The "." on either side of the
    # sprintf() is merely concatenating it as part of the string being passed
    # to the print() function.
    #
    # The important thing to take away from this statement is that something
    # like the following will be displayed on screen:
    #   Customer's ticket price: $4.50
    print "Customer's ticket price: \$" . sprintf("%.2f", $price) . "\n";
    
    # The return value is not actually used in this script.
    # You can safely ignore it (or remove it) if you so choose.
    return $price;
}

# Take the customer's age as a command line argument.
# If an age is specified call the ticket_price_by_age() function,
# otherwise print basic invocation syntax for the script.
if ($ARGV[0])
{
    ticket_price_by_age ($ARGV[0]);
}
else
{
    print "Syntax: $0 AGE_OF_CUSTOMER\n";
}

exit 0;
  • Like 1
  • 0

This will answer all your questions: http://msdn.microsoft.com/en-us/library/752y8abs.aspx I suggest you use this site as your primary reference/resource. In an exam, you may not even have access to documentation, so it's worth learning code off by heart! The best way to learn is by troubleshooting.

 

You're fortunate with how easy Visual Basic has become - if you were taking a course 15-20 years ago, you wouldn't have all the in-app support there is today (or the internet).

This topic is now closed to further replies.
  • Posts

    • I bought one of these last year. I really hope I won't have to deal with this crap. My drive is in good condition at the moment.
    • Umm, read my answer again! If you have something to add or contribute, feel free. Otherwise my point was that you apparently dont want faster updates... so you want slower updates by process of elimination. If you have something to contribute, meaningful answers are better.
    • These features described above are good, but far from what developers will like the most. The main feature that developers will care and love the most it's called "Bring Your Own Models". It gives us the ability to connect to LOCAL AI models running on Ollama. The feature it's located on GitHub Copilot tab -> On the model picker where you can select "manage models" instead of paid models and then it will show you the "Bring your own models" window where you can now select Ollama and the endpoint of your local server. So if you have a beefy spec machine you can now use your own model 100% local inside Visual Studio 2026 18.7.0
    • Microsoft Teams is getting a controversial location tracking feature that users may hate by Usama Jawad Image generated with Microsoft Copilot Earlier this year, Microsoft planned to roll out a controversial location tracking feature in Teams, but following customer feedback, it decided to delay its release. The bad news is that the company has decided to launch it later this year, but it's based on roughly the same design that was shared earlier, which means that many users still have good reason to worry. Basically, Microsoft Places and Teams have received workplace check-ins via Wi-Fi. The idea is that if an employee arrives at the office and connects to their enterprise network, their profile status indicator will show them as being present in the office. For example, if you arrive at work, open Teams on your PC, and connect to the "Studio B" company Wi-Fi network, your Teams profile will indicate that you are present in "Studio B", as shown below: Microsoft says that this feature is basically a replacement for physical workplace check-in peripherals, it reduces the need to manually update your status, and it also enables co-workers to know that you're at work so that they can coordinate in-person meetings with you. IT admins can enable this workplace check-in capability at a tenant level, and users have the ability to control whether they want to enable it or not. Of course, all of that sounds great on paper, but naturally, many Teams customers may still have concerns, as they did before. This is because it enables your reporting manager and other members of the organization to track if you are at the office, when you arrive at the office, and where you are right now. This could be problematic for people who work in what they consider to be flexible work environments or hybrid setups, and this kind of location tracking could be considered an invasion of privacy. Microsoft has tried to alleviate some of these concerns by letting users know that they can manually set their location easily, which essentially overrides workplace check-in if they feel uncomfortable with it. However, that doesn't really solve the problem because your organization could enforce a workplace policy that mandates that this feature remains enabled. The Redmond tech giant has also assured users that this capability does not store historical data and is only a real-time indicator of location. Finally, it only generates a signal when you connect to a corporate network, which means that if you are working from home and connect your PC to your personal Wi-Fi, it won't broadcast your location to your employer; you will simply be shown as "Remote". Microsoft has encouraged IT admins to prepare for this change and begin informing users so they know what to expect once it begins rolling out later this year.
  • Recent Achievements

    • Very Popular
      AndrewSteel earned a badge
      Very Popular
    • Veteran
      Taliseian went up a rank
      Veteran
    • One Month Later
      Clizby earned a badge
      One Month Later
    • One Month Later
      Timaximus earned a badge
      One Month Later
    • Week One Done
      Timaximus earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      516
    2. 2
      +Edouard
      162
    3. 3
      PsYcHoKiLLa
      157
    4. 4
      Steven P.
      82
    5. 5
      ATLien_0
      81
  • Tell a friend

    Love Neowin? Tell a friend!