Learning VB, need confirmation for questions.

riotcity90

New member
Joined
Dec 4, 2017
Messages
2
Programming Experience
Beginner
Hey guys, I recently just discovered this forum and its been helpful with learning VB. I'm trying to learn it more and I have a few questions that I'm not sure are correct or not, any help or confirmation for what I think the answers are would be appreciated!

Write an If ... Then statement that multiplies the variable decPayRate by 1.5 when intHours is greater than 40.

If intHours > 40 Then
decPayRate = decPayRate *1.5
End If
Is this the correct syntax for that statement? or would it be decPayRate *= 1.5 ?

List two VB.NET controls that can be used to collect input from the user

I know one would be a textbox, but not sure what the other would be, possibly label?

Write a complete If statement that assigns 20 to the variable, moneyOwed, if the CheckBox named, chkOptionOne, is selected.


If chkOptionOne.checked = True Then
moneyOwed.text = 20
End If
Not sure if I would have to do anything else for that to work?

Write an If..Then..Else statement that assigns the number 35 to the intCommission variable when the decSales variable contains a number that is less than or equal to $250; otherwise, assign the number 50.


If decSales <= 250 Then
intCommission = 35
Else intCommission = 50
Did I correctly use the Else there? and what would I have to do for the $ to be there, or would that just come back from a currency string statement?

Which of the following compound conditions can be used to determine whether the value in the variable, intQuantity, is outside the range of 0 - 500.

Honestly not sure what a compound condition is, can't find it online or in the book that I own.


Thanks a lot for reading this and sorry its so long. Any help would be immensely appreciated!
 
Write an If ... Then statement that multiplies the variable decPayRate by 1.5 when intHours is greater than 40.

If intHours > 40 Then
decPayRate = decPayRate *1.5
End If
Is this the correct syntax for that statement? or would it be decPayRate *= 1.5 ?
Both would be correct. The latter is simply a shorthand for the former.

One small point to note there is that 'decPayRate' is presumably a Decimal and that code is actually multiplying it by a Double literal. That would work fine with Option Strict Off, which it is by default, but if you set Option Strict On, as you should, then you would need to use a Decimal literal:
decPayRate = decPayRate * 1.5D

List two VB.NET controls that can be used to collect input from the user

I know one would be a textbox, but not sure what the other would be, possibly label?
TextBox is correct but Label is for display only. You can just look through the Toolbox with a Windows Form open in the designer and see what controls are there and determine which ones get information from the user. Remember that there's more to user input than entering text. Take a look at the very next question for an example.
Write a complete If statement that assigns 20 to the variable, moneyOwed, if the CheckBox named, chkOptionOne, is selected.


If chkOptionOne.checked = True Then
moneyOwed.text = 20
End If
Not sure if I would have to do anything else for that to work?
That's mostly right but the question says to set the 'moneyOwed' variable. Is that what you're doing? Look back at your own code for the first question where you're setting a variable.
Write an If..Then..Else statement that assigns the number 35 to the intCommission variable when the decSales variable contains a number that is less than or equal to $250; otherwise, assign the number 50.


If decSales <= 250 Then
intCommission = 35
Else intCommission = 50
Did I correctly use the Else there? and what would I have to do for the $ to be there, or would that just come back from a currency string statement?
What you've done is basically correct. Don't worry about the $ symbol. That's not actually part of a numeric value. That would only be added when formatting the number as a String for display.

That said, there is one small thing. It's not wrong to put the statement on the same line as the Else but you would normally do it like this for clarity:
If decSales <= 250 Then
    intCommission = 35
Else
    intCommission = 50
End If

As a point of interest, you can also do this for brevity:
intCommission = If(decSales <= 250, 35, 50)

Which of the following compound conditions can be used to determine whether the value in the variable, intQuantity, is outside the range of 0 - 500.

Honestly not sure what a compound condition is, can't find it online or in the book that I own.
It says "which of the following compound conditions" so presumably it gives you several choices. It doesn't matter what a compound condition is because I would assume that all the options provided are. It just matters which one of the options are correct.

That said, you can look at the words and work it out for yourself. What would you usually think if something was "compound"? It means that it's made up of multiple parts, right? Words don't change their meaning in programming. What is a condition? If I said that I would help under one condition, you'd know that that meant that something had to be true for me to help you. Again, "condition" means the same in programming as it does everywhere else. So, a compound condition is something made up of multiple parts that must be true. No programming experience or looking in books or online required.

By the way, notice how I have posted formatted code snippets? You can do that like this:

[xcode=vb]your code here[/xcode]

If you want to add extra formatting, e.g. bolding or colouring a specific line, then do this:

[code]your code here[/code]
 
Thanks a lot man, that helps tremendously. Was always wondering how to put the code snippets in as well. As with the final question, I was confused because it didn't supply any answer choices. Again, thanks a lot!
 
Back
Top