Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

Im working on a study guide for my Visual Basic final and im stuck up on this question. Which of the following code segments will copy the values of a 5 element array named intOldValues into another 5 element array named intNewValues? A) intIndex = 1 Do While intIndex <=5 intNewValues = intOldValues intIndex += 1 Loop B) intIndex = 0 Do While intIndex < 5 intNewValues = intOldValues intIndex += 1 Loop C) For intIndex = 1 To 5 intNewValues = intOldValues Next intIndex D) For intIndex = 0 To 4 intOldValues = intNewValues Next intIndex Any feedback would be appreciated

OpenStudy (anonymous):

It's C or D, I just can't remember if VB is array base 0 or 1, let me check for you, hold on.

OpenStudy (anonymous):

According to a quick search, VB has base 0 array indexes (unless overridden). So the answer is D. If you need an explanation, let me know.

OpenStudy (anonymous):

I thought it was D too but I was unsure since it says intOldValues = intNewValues. I figured that since we want to copy it to NewValues it would have to be intNewValues = intOldValues

OpenStudy (anonymous):

Oh, I didn't even see that at first. You may be right, it could be C. I remember VB being weird with arrays, and they start at 1 instead of 0. I'm actually going to change my answer to C. Do you have any more code that accompanies this question?

OpenStudy (anonymous):

Yeah because it says intOldValues = intNewValues, that doesn't make any sense.

OpenStudy (anonymous):

Okay, I'm looking on the MSDN, and yes VB arrays *DO* start at 1 when looping. So yes, the answer is in fact C http://msdn.microsoft.com/en-us/library/5z06z1kb.aspx

OpenStudy (anonymous):

Thanks Im glad we caught that trick.

OpenStudy (anonymous):

Yes, sorry if I mislead you. I apologize for not seeing it at first.

OpenStudy (anonymous):

Not a problem. Are you good with VB? I might have a few more questions.

OpenStudy (anonymous):

I've programmed in VB for years, and I have never once been happy doing so :)

OpenStudy (anonymous):

Haha, yes I am. Ask away, I'm just doing physics homework.

OpenStudy (anonymous):

That'd be awesome. And just to clarify this isnt my homework. Its a study guide for my final so its not for a grade. I know some people get weird about giving answers to homework.

OpenStudy (anonymous):

Yeah, if you need an explanation let me know. VB's not like other languages it's .... different (read: "frustrating"). So even if you just need clarification on just the answer, that's fine. :)

OpenStudy (anonymous):

But feel free to ask away, I'll be up for another 20 or 30 minutes.

OpenStudy (anonymous):

ok. Which of the following is the correct definition for a procedure that accepts a String array as an argument? So the professor didnt give us options for some of the questions. I looked this up in the book and all I could find is to use a function but im not sure if thats what the answer would be

OpenStudy (anonymous):

So, an array of strings?

OpenStudy (anonymous):

Let me see....

OpenStudy (anonymous):

MSDN Link: http://msdn.microsoft.com/en-us/library/vstudio/63y5ksfs(v=vs.100).aspx Public Function PrintMyMessages(messages() As String) As Double ' ... End Function

OpenStudy (anonymous):

Oh ok so basically I need to just add the As String

OpenStudy (anonymous):

You need to add the () after "messages" That lets the function know it is an array

OpenStudy (anonymous):

The As String is used to tell the function it is a string array

OpenStudy (anonymous):

For example, if you had an array of doubles, "myDoubles() as Double"

OpenStudy (anonymous):

Ok that makes sense and lines up with the book

OpenStudy (anonymous):

Which of the following statements defines a two-dimensional Integer array named intTwoDArray with 6 rows and 4 columns? Dim intTwoDArray(5,3) Is that right?

OpenStudy (anonymous):

I believe it should be (6,4) (just like in any other language). Let me verify.

OpenStudy (anonymous):

I think 0 counts as a column

OpenStudy (anonymous):

See ... yeah VB always has to be the weird one. (5,3) declares the array indexes 0 through 5 as the col, and 0 through 3 for each row.

OpenStudy (anonymous):

In any other language (like C), if you declare arr[4][3], it declares arr[0 through 3][0 through 2]

OpenStudy (anonymous):

So you are correct.

OpenStudy (anonymous):

Dim intTwoDArray(5,3)

OpenStudy (anonymous):

MSDN: http://msdn.microsoft.com/en-us/library/02e7z943.aspx

OpenStudy (anonymous):

Nice. Do have any idea what to make of this question? Which of the following could be used to iterate through each element of a two-dimensional array.

OpenStudy (anonymous):

"Which of the following" -> Does it give any multiple choice answers? I should know which one if you can provide them.

OpenStudy (anonymous):

No it doesnt. Unfortunately.

OpenStudy (anonymous):

I found options on google. . A single Do While loop A single Do Until loop A single For Next loop Nested loops For Next loops

OpenStudy (anonymous):

Well what you normally do is this: Say you have the array Dim intTwoDArray(5,3) For the columns, we use the variable "i", and for the rows we use the variable "j" Loop i from 0 to 5 Loop j from 0 to 3 'Do code Next Next

OpenStudy (anonymous):

So is that D?

OpenStudy (anonymous):

So the program would access the array like this: Column 0, row 0 Column 0, row 1 Column 0, row 2 Column 0, row 3 Column 1, row 0 Column 1, row 1 Column 1, row 2 Column 1, row 3 Column 2, row 0 Column 2, row 1 Column 2, row 2 Column 2, row 3 ...etc

OpenStudy (anonymous):

Yes, D

OpenStudy (anonymous):

Nice. I found some options for that As String question if you want to make sure i have the right answer. . Private Sub ArrayParam(ByVal strStudents As String) Public Sub ArrayParam(ByVal strStudents()) Sub ArrayParam(ByVal strStudents() As String) Private Sub ArrayParam(ByRef strStudents As String)

OpenStudy (anonymous):

Let me do a search. Normally in any language, arrays are automatically passed by reference (ByRef) regardless of type. But VB is .... special :) brb.

OpenStudy (anonymous):

Oh wait I don't even have to look it up. A and D don't have the parenthesis.

OpenStudy (anonymous):

So C im guessing?

OpenStudy (anonymous):

Yes it's C. I wanted to make sure. MSDN (see "example"): http://msdn.microsoft.com/en-us/library/dz1z94ha.aspx

OpenStudy (anonymous):

btw in case you need to know, ByVal means it makes a copy to the array. That means that anything you do to that array does not affect the original array. On the other hand, if you pass ByRef, you are passing "By Reference", meaning you are referencing the original array. If you make any changes, they WILL affect the original array.

OpenStudy (anonymous):

ByVal means it makes a copy of that array*

OpenStudy (anonymous):

Oh ok so you can change values with by reference.

OpenStudy (anonymous):

Right

OpenStudy (anonymous):

So like, say for every value in the array I wanted to subtract 1. I would pass it by reference.

OpenStudy (anonymous):

But say I REALLY don't want to affect any values in the array, I would pass by copy (ByVal)

OpenStudy (anonymous):

Almost any language passes an array by reference, because it costs memory and time to make a copy of an array. But VB you must explicitly state which one you want every time.

OpenStudy (anonymous):

Ya VB is killing me. Im taking C++ at the same time so you can only imagine the confusion

OpenStudy (anonymous):

Would this one be B? Which statement is the best solution for the following problem? Write a statement that initializes a two dimensional array of Integers named intGrades. The array will have 2 rows, with 93, 91, and 84 in the first row and 85, 89, and 91 in the second row. Dim intGrades(2,3) As Integer = { {93, 91, 84}, {85, 89, 91} } Dim intGrades(,) As Integer = { {93, 91, 84}, {85, 89, 91} } Dim intGrades() As Integer = { 93, 92, 84,85, 89, 91} Dim intGrades(1, 2) As Integer = { {93, 91, 84}, {85,89, 91} }

OpenStudy (anonymous):

I don't even know what school would still offer VB as a language - it's nearly a dead language. C# and VB.NET are its replacements.

OpenStudy (anonymous):

I took Java in highschool and I have to take VB C++ and C++ II as far as coding goes

OpenStudy (anonymous):

D intGrades(0,0) = 93 intGrades(0,1) = 91 intGrades(0,2) = 84 intGrades(1,0) = 85 intGrades(1,1) = 89 intGrades(1,2) = 91

OpenStudy (anonymous):

ok. What would happen if i coded B?

OpenStudy (anonymous):

I think it would give you a syntax error. I don't think that's legal to let the compiler assume the size of the array based on the right hand side. Although, I could be wrong.

OpenStudy (anonymous):

They do it in the book but they declare MAXRows and MAXColumns

OpenStudy (anonymous):

It seems like it's only either Dim intGrades(1, 2) As Integer = { {93, 91, 84}, {85,89, 91} } or Dim intGrades = { {93, 91, 84}, {85,89, 91} }

OpenStudy (anonymous):

They use (,) in the book?

OpenStudy (anonymous):

For one of the example problems it goes. Const intMAX_ROW = 5 Const intMAX_COL = 3 Dim decPrices( , ) = {{10D, 10D, 10D, 10D}, {20D, 20D, etc......

OpenStudy (anonymous):

I just compiled all of these online, and they all work.

OpenStudy (anonymous):

I know for certain it's not C

OpenStudy (anonymous):

A is also incorrect, because (2,3) will give you 0-2 (3 columns) and 0-3 (4 rows)

OpenStudy (anonymous):

Does the way the array is written define how many rows and columns it needs maybe?

OpenStudy (anonymous):

It is (,) when you're specifying values. MSDN: http://msdn.microsoft.com/en-us/library/y13tek7e.aspx

OpenStudy (anonymous):

Always trust the MSDN, lol.

OpenStudy (anonymous):

I have to head to bed, good luck on your final! (Please choose "best answer" if you thought I was helpful)

OpenStudy (anonymous):

So is it B then? And i definetly will you were really helpful

OpenStudy (anonymous):

It is B according to the MSDN... but I would write a quick program to check if both B and D work.

OpenStudy (anonymous):

Ok Will do. Thanks for all your help

OpenStudy (anonymous):

No problem at all :) Anything to lessen the suffering of VB upon others, haha.

OpenStudy (anonymous):

Haha right?! Night! Thanks again

OpenStudy (anonymous):

It would seem that testing the options would be the best way to be 100% sure of the correct solution, and it would be fairly quick also

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!