Consider the following code:

Result= input_number Mod 7
If (Result > 0) Then
Cells(1,1).Value = 3
Else
NextResult = input_number Mod 5
If (NextResult > 0) Then
Cells(1,1).Value = 2
Else
Cells(1,1).Value = 1
End If
End If


What will be the content of cell A1 if input_number equals 56?
a. 3
b. 2
c. 1
d. 6

I picked A, am I right??

Consider the following custom function:

Public Function Discount(quantity As Integer) As Single
IF (quantity <= 5) Then Discount = 0
Else
IF (quantity <= 10) Then Discount = 0.1
Else
Discount = 0.15
End IF
End IF
End Function

Suppose you enter the following formula in B1: =Discount(12). What will be the result in B1?
a. 5
b. 0.1
c. 0.15
d. 0

I picked C, am I right?


Consider the following code segment:

SumTotal = 1
IF (SumTotal < 5) Then
SumTotal = SumTotal + 3
End IF
What will be the value of SumTotal when the program comes out of the loop?
a. 5
b. 7
c. 3
d. 10

I picked B, am I right??

thanks for all your help

Result= input_number Mod 7
If (Result > 0) Then
    Cells(1,1).Value = 3
Else
    NextResult = input_number Mod 5
    If (NextResult > 0) Then
        Cells(1,1).Value = 2
    Else
        Cells(1,1).Value = 1
    End If
End If

56 mod 7 is 0. hence Else part is executed.
In the else part again 56 mod 5 is 1. so the NextResult>0 holds true, by which Cells(1,1).Value = 2 is executed.
Answer B is correct.

Public Function Discount(quantity As Integer) As Single
    IF (quantity <= 5) Then
        Discount = 0
    Else
        IF (quantity <= 10) Then 
            Discount = 0.1
        Else
            Discount = 0.15
        End IF
    End IF
End Function

Here the Discount(12) will result in execution of the Discount = 0.15 statement. So your answer C is correct.

SumTotal = 1
    IF (SumTotal < 5) Then
        SumTotal = SumTotal + 3
    End IF

Since SumTotal is Less Than 5 and true, the statement SumTotal = SumTotal + 3 will be executed and the resulting value of
SumTotal = 1 + 3 = 4. i think none of the answers is right. A small clarification. You said it is a loop, but the code u gave is a condition statement not a loop. is the question typed correctly. if the question u typed is correct then none of the answers is correct because the correct answer is 4.

May I ask U What are all the Questions actually for? Are U Preparing for any Competitive Exams?

Regards
Shaik Akthar

May I ask U What are all the Questions actually for? Are U Preparing for any Competitive Exams?

Regards
Shaik Akthar

actually this is the last assignment in an excel/VBA class and is definitely the toughest one. Thanks for all your help. By the way the last question was typed correctly. Is the answer not 7? my rationale is, the sum once you go thru the first procedure would be 4, so since this is still <5, the procedure would repeat again and so 4 (+3)=7?!?!?!

SumTotal = 1
IF (SumTotal < 5) Then
    SumTotal = SumTotal + 3
End IF
What will be the value of SumTotal when the program comes out of the loop?
a. 5
b. 7
c. 3
d. 10

It is not a loop to go back as it does in
While...Wend or For...Next . Once the Conditional Statements end they continue with the statements following afterwards. The only way to get back is to issue a 'GoTo' Statement with a condition and with some label defined above the if statement like

SumTotal = 1
CheckAgain:
    IF (SumTotal < 5) Then
        SumTotal = SumTotal + 3
    End IF

    If SumTotal < 5 Then
        GoTo CheckAgain
    End If

Regards
Shaik Akthar

OR

as you inferred it would have been like this

SumTotal = 1

    While (SumTotal < 5) 
        SumTotal = SumTotal + 3
    Wend

Here in this case 7 will be the correct answer.

Regards
Shaik Akthar

SumTotal = 1
IF (SumTotal < 5) Then
    SumTotal = SumTotal + 3
End IF
What will be the value of SumTotal when the program comes out of the loop?
a. 5
b. 7
c. 3
d. 10

It is not a loop to go back as it does in
While...Wend or For...Next . Once the Conditional Statements end they continue with the statements following afterwards. The only way to get back is to issue a 'GoTo' Statement with a condition and with some label defined above the if statement like

SumTotal = 1
CheckAgain:
    IF (SumTotal < 5) Then
        SumTotal = SumTotal + 3
    End IF

    If SumTotal < 5 Then
        GoTo CheckAgain
    End If

Regards
Shaik Akthar

So what would you suggest I put for my answer?? perhaps 7 but a note that really it is not written correctly??

Just place a note explaining the reason for why none of the answers is right. It may actually be a test for u in the assignment whether u can analyse logic or not.

Regards
Shaik Akthar

I have attached the VBA help for excel. i think u can find some information for ur assignment.

Regards
Shaik Akthar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.