66 951
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #50515 in Visual Basic for Bender

Question #50515
Given the following code, what are the first four lines displayed in the text box when the code is executed?

Dim arrSales(11, 2) As Double
Dim i As Integer
Dim j As Integer
Dim strLine As String
Dim strDisplay As String

strDisplay = "Output is ..." + vbCrLf
For i = 0 To 11
For j = 0 To 2
arrSales(i, j) = i + j
strLine = vbTab + arrSales(i, j).ToString()
strDisplay += strLine
Next
strDisplay += vbCrLf
Next
TextBox1.Text = strDisplay
Expert's answer
Given the following code, what are the firstfour lines displayed in the text box when the code is executed?
Dim arrSales(11, 2) As Double
Dim i As Integer
Dim j As Integer
Dim strLine As String
Dim strDisplay As String

strDisplay = "Output is ..." + vbCrLf
For i = 0 To 11
For j = 0 To 2
arrSales(i, j) = i + j
strLine = vbTab + arrSales(i, j).ToString()
strDisplay += strLine
Next
strDisplay += vbCrLf
Next
TextBox1.Text = strDisplay

 
Answer: in text box displayed:
Output is ...
            0          1          2
            1          2          3
            2          3          4
 
Causes:
In textbox1shown text, which accumulate in variable strDisplay(look at last line in program). In the begin of program (after description
variables) the variable strDisplay is set "Outputis ..." + vbCrLf, where vbCrLf is generate new line in textbox. So,first line of strDisplay is “Output is…”. Next in program is cycle by i and j. In innercycle calculates sum of indexes i and j, and this sum is adding to strDisplay, separated by tabulation.So, in second line we have i=0, j=0, sum=i+j=0; i=0, j=1; sum=1; i=0, j=2,
sum=2, and the end of cycle by j. Total, in second line we have 0 1 2. After
cycle we add to strDisplay symbol ‘end of line’.
The thirdline generate by i=1 and j=0, 1, 2. Similarly calculate sum of i and j, and receive line: 1,2, 3. In the next line we have for i=2; and j=0, 1, 2, so line have value: 2,
3, 4.
Thus, thefirst 4 lines have text:
Output is...
            0          1          2
            1          2          3
            2          3          4
as inanswer supra.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions