Sign in to follow this  
Followers 0

create if...elseif statement Visual basic


59 posts in this topic

Posted

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

 

decTicketPrice                   

Share this post


Link to post
Share on other sites

Posted

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

2 people like this

Share this post


Link to post
Share on other sites

Posted

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?

Share this post


Link to post
Share on other sites

Posted

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

especially online programming class.

 

soo...bout the question?

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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.

7 people like this

Share this post


Link to post
Share on other sites

Posted

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

3 people like this

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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.

4 people like this

Share this post


Link to post
Share on other sites

Posted

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.

4 people like this

Share this post


Link to post
Share on other sites

Posted

Is your teacher the same one who issues a programming assignment with fill in the blank spots?

Share this post


Link to post
Share on other sites

Posted

Fill in the blank coding... Is that even real? LOL.

Share this post


Link to post
Share on other sites

Posted

You didn't actually ask a question. You just posted your assignment. What are we supposed to help you with?

 

If you cannot be bothered to formulate a clear question, don't expect anyone to formulate a clear answer.

1 person likes this

Share this post


Link to post
Share on other sites

Posted

I need help creating that code

Share this post


Link to post
Share on other sites

Posted

If you can't figure out something this elementary, you need to start over. This time, at the beginning.

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

There isn't even a problem here. The question itself is literally the pseudocode for the solution.

 

 

Here, this is as much as I'm willing to provide:

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

1 person likes this

Share this post


Link to post
Share on other sites

Posted

I need help creating that code

That's not a question either. What is it you don't understand?

Share this post


Link to post
Share on other sites

Posted

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;

Share this post


Link to post
Share on other sites

Posted

please do your own homework.

1 person likes this

Share this post


Link to post
Share on other sites

Posted

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

 

Why blame the teacher?

1 person likes this

Share this post


Link to post
Share on other sites

Posted

Why blame the teacher?

I guess sarcasm doesn't work too well in written form :p 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.