Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

VB net I need help

karendkarend Posts: 2Member
Hi, I posted this before with no response, but maybe I put it in the wrong board. These are very basic questions, I am taking VB Net for a business degree and trying to do my midterm this weekend. If you feel generous to help I appreciate your time. I have 2 problems where I am suppose to correct the errors in the code given me.
For both problems assume intCounter is declared as an Integer for both a and b. Identify and correct the error(s) in each of the following.
1. this statement should display in a ListBox all numbers from 100 - 1 in decreasing order.
For intCounter = 100 To 1.
1stDisplay.Items.Add(intCounter)
Next

2. The following code should display in a ListBox the odd Integers
from 19 to 1 in decreasing order.
For intCounter = 19 To 1 By -1
1stDisplay.Add(intCounter)
Next

One other problem if you feel so stimulated is code I am working on to write a program that reads in five integers and determines and prints the oargest and smallest integers in the group. Create an appropriate GUI. I have the GUI and have declared variables, I don't know if I should use a loop or some kind of case declaration to print out the answer. If anyone feels helpful I would gladly like your input. Thanks, KarenD



Comments

  • kainsworthkainsworth Posts: 200Member
    Your honesty might create a small problem because many users of this board have strong views about providing answers to test questions, assignments, etc.
    So - in order to try and help you - but avoiding me getting flamed by those of strong views, here's a halfway house: clear pointers to some specific things you should look at in order to correct the examples.

    1. For intCounter = 100 To 1.

    a. Check out the word "Step" in your books/notes as the way to approach this.
    b. Be aware of any unwanted punctuation marks in code lines.

    2. For intCounter = 19 To 1 By -1
    a. Look up the word "Step" in your books/notes.

    3. the odd Integers
    a. Look up "MOD" as the way to do this.

    Hope these pointers help you find the answers.


    Ged

    ====================================================================



    : Hi, I posted this before with no response, but maybe I put it in the wrong board. These are very basic questions, I am taking VB Net for a business degree and trying to do my midterm this weekend. If you feel generous to help I appreciate your time. I have 2 problems where I am suppose to correct the errors in the code given me.
    : For both problems assume intCounter is declared as an Integer for both a and b. Identify and correct the error(s) in each of the following.
    : 1. this statement should display in a ListBox all numbers from 100 - 1 in decreasing order.
    : For intCounter = 100 To 1.
    : 1stDisplay.Items.Add(intCounter)
    : Next
    :
    : 2. The following code should display in a ListBox the odd Integers
    : from 19 to 1 in decreasing order.
    : For intCounter = 19 To 1 By -1
    : 1stDisplay.Add(intCounter)
    : Next
    :
    : One other problem if you feel so stimulated is code I am working on to write a program that reads in five integers and determines and prints the oargest and smallest integers in the group. Create an appropriate GUI. I have the GUI and have declared variables, I don't know if I should use a loop or some kind of case declaration to print out the answer. If anyone feels helpful I would gladly like your input. Thanks, KarenD
    :
    :
    :
    :

  • RelmanRelman Posts: 104Member
    For your first question, look at the second piece of code. Notice th "By"? Well, it would work - had you replaced "By" with "Step". If you want to iterate through a for loop using a "step" other than the default 1, then you must use the step keyword. The format is:
    [code]
    For [Iterater] = [Start] to [finish] Step [amount to jump between iterations]
    'The "Step" keyword is optional, defaulting to 1
    Replace "[]" with values.[/code]
    Now that you have this info, look back at your problem, you should be able to solve it now. Also, as Ged said, look out for unnecessary punctuation

    For the second problem, "Mod" tells you the remainder. So if you took a value "Mod 2", if the answer is 0 then it is even and if it is 1 then it is odd. with that in mind, make a for loop, and only when the "Counter Mod 2 = 1" (Ie. when it is odd), should you process it. Another method will be is to start at an odd number and just make your "Step" = -2. The second method is probably better.

    For your other problem, to find the smallest/largest number, all you need to do is iterate through all the numbers and compare your current largest with each one, making you current largest = the current value if the current value is greater (Or smaller to find the smallest) than it.
    Assuming that your number values are stored in an array called num (dim num(5) as integer) and using i as a counter:
    [code]
    Dim temp as integer = 0
    for i = 1 to 5
    if temp < num(i) then temp = num(i)
    next i
    'Temp now contains the largest number
    [/code]
    To get the smallest number, flip the "<".

    I hope that helps,

    Relman

    Notice that instead of just giving the answers or hinting where they might be found, I explained the concepts and gave you a tip of how to apply them.
Sign In or Register to comment.