Visual basics Describe which messages display when the code

Visual basics


Describe which messages display when the code runs if the user enters -5 into textbox1 and 5 into textbox2.

Indicate which tests were attempted and the result of each.

Explain how the AndAlso and OrElse operators work.

Dim a, b as Integer

a = CInt(textbox1.text)
b = CInt(textbox2.text)

If a >= 0 AndAlso b < 0 Then   \' *** note there are two tests here
     MessageBox.Show((a+b).ToString)
End If

If a < 0 OrElse b >= 0 Then    \' *** and two tests here
     MessageBox.Show((b-a).ToString)
End If

Solution

Steps are below

If use enters -5 into textbox1 and 5 into texbox2 then

value of a will be a =-5

value of b will be b = 5

next there is if statement

a is not greater than 0 , since there is logical and it will not test b < 0 so next if statement will be executed

here it checks a < 0 evaluates to true and there is logical or so it evaluates to true irrespective of value of b

so MessageBox.Show((b-a).ToString) line will be executed

it evaluates to 5-(-5)=5+5 =10

So it displays 10

Visual basics Describe which messages display when the code runs if the user enters -5 into textbox1 and 5 into textbox2. Indicate which tests were attempted an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site