Exam coming up, I have questions I need help answering.

I have an upcoming exam and I don't have access to my professor and I have questions that the book is not clarifying for me.  The book that the class is using is Murach's Visual Basic 2008.

iI will list the questions will by numbers.  I understand that there are alot of questions here but I really need a good grade on this exam and these are the areas that I am still unsure of.  Some of the questions, I have tried to answer and I posted a comment in (), it my guess is correct could you annotate so.  If not could you help me get on base.

I am taking the exam tomorrow at 11.  I have been buried in this book for a couple of days now and I need help.  I am using this site as a last resort.  I figured individuals on here are much more proficient than myself so I mine as well ask the experts.  

I want to thank anyone in advance that is willing to answer any of these questions for me.  God Bless and Happy Veterans Day.  I myself am an "Iraq Veteran" in 2003.

1.  Here is the code, I understand what it does but I don't know how to apply it.  (example inputing in numbers).  I realize that default is 0.  But on the questions the professor will have this code and say input a number what would the answer be?  I don't know how to do that.

Input 3 as an example:

Dim sum As Integer
Dim i As Integer
For i = 0 to 4
      sum += i


Same problem but different format.

Dim sum As Integer
Dim i As Integer = 2 to 12 Step 2
      sum += i


Same problem but different format.

Dim sum As Integer
Dim i As Integer = 25 to -15 Step -10
    iSquared = i ^ 2      
    sum += iSquared


For loop that calculates a future value
im monthlyInvestemnt As Decimal = 100
Dim monthlyInterestRate As Decimal = .01D
Dim months As Integer = 120
Dim futureValue As Decimal

For i As Integer = 1 To months
      futureValue = (futureValue + montlyInvestemnt) _
                      * (1 + monthlyInterestRate)
      Next i


2. How to code and call procedures/functions?
                - What is the difference between a function and a sub procedure?  
                     - I understand that a sub procedure doesn't return any data and a function returns a value.  
                              -What does a value mean?
-      how to code sub procedures?
          - I understand based on the book how to code a sub procedure.
-      how to call sub procedures?
          - I understand based on the book how to call a sub procedure.
-      What I dont understand nor does it show is the two together in code.  
       Are you able to put the two together and if so what does it look like?  The book gives me these
       examples for each.  Can you put the two together and define it for me?

Procedure with two parameters:
Private Sub GetDiscountPercent (ByVal subtotal As Decimal, ByRef discountPercent As Decimal)
       If subtotal >= 500 Then
           discountPercent = .2m
           discountPercent = .1
       End If
End Sub

A statement that passes two arguments

Me.GetDiscountPercent (subtotal, discountPercent)

3. When and how to pass arguments by reference and by value?
       - The book says this.  I dont understand what it is saying at all:

Arguments are passed by value.  Because of that, the procedure can change the value of the parameter without affecting the value of he variable in the calling procedure.

In some cases, though, you will want to be able to change the value of the variable in the calling procedure from the called procedure.  To do that, you can pass the argument by reference.
When you call the procedure, a reference to that variable is passed to the procedure.  As a result, if that called procedure changes the value of the parameter, it also changes the value of the variable in the calling procure.  

If you pas a reference type by reference, you still cant change its value (the reference), but you can change the values of members of the object it refers to.  In contras if you pass a reference type by value, you can change both its value and the values of its members.

Can you explain this in laymen terms?

4. How to throw an exception.
         - Why would you want to throw an exception?

5. How to work with Arrays
-      How to assign values to the elements of an array
          - Does this mean when I code:
                 Dim totals (3) As Decimal
                 totals (0) = 14.95D
                 totals (1) = 12.95D....ect
            The values are the 0, 1, 2, 3?  
            Or are the values the 14.95, 12.95....ect?

6. How to use LOOPs to work with array:

I know the code below is putting the numbers 0 through 9 into an array.  But what exactly is this telling me?     Can show an example?
    Dim numbers (9) As Integer
    For i As Integer = 0 To numbers.Length - 1
          numbers (i) = i

7. How to refer to and copy arrays
My professor had this example on his slide.  I dont understand how this works at all!

Code that creates a reference to another array
Dim inches1() As Double = {1, 2, 3}
Dim inches2() As Double = inches1
inches2(2) = ???  ({3})            
inches2(1) = 5  

then inches1(1) = 5  

8. Code that copies some of the elements of an array:
-      I don't understand how this works as well.  How does it reference each other.

Dim names() As String = {"Boehm", "Murach", "Vasquez"}
Dim lastTwoNames(1) As String
Array.Copy(names, 1, lastTwoNames, 0, 2)

What are the values of lastTwoNames array???  Murach Murach (how does this happen?)

9. How to return an array from a procedure
A Function procedure that returns an array
Private Function RateArray(ByVal elementCount As Integer) As Decimal()

    Dim rates(elementCount - 1) As Decimal
    For i As Integer = 0 To rates.Length - 1
        rates(i) = (i + 1) / 100D
    Return rates
End Function
A statement that calls the procedure
Dim rates() As Decimal = Me.RateArray(4)

 what are the vales in the rates( )???  

Dim rates(elementCount - 1) As Decimal
    For i As Integer = 0 To rates.Length - 1
        rates(i) = (i + 1) / 100D

-   I have no idea what this is doing, the book doesn't explain this well enough for me to be able to answer the question.

10.  A Sub procedure that converts an array of inches to an array of centimeters
Private Sub ConvertToEven( _
        ByRef measurements() As Double)
    For i As Integer = 0 To measurements.Length - 1
        measurements(i) *= 2
End Sub

' Statements that declare an array and call the procedure
Dim measurements() As Double = {1, 2, 3}

What are the values of measurements()???  

-  Again, I have no idea how to work this?

10.  Code that uses an index to access a character in a string
Dim chars As String = "abcdefg"
Dim a As Char = chars(0)               ' a = "a"
Dim b As Char = chars(1)               ' b = "b"
Dim c As Char = chars (4)               c = ??? (2)  Is this correct, 4 would be "e"?
       String must be an array??? Yes or NO, why?
       -  I don't understand the question.

11. Code that uses a For Each loop to access each character in the string
Dim chars As String = "abcdefg"

Dim charsAndSpaces As String = ""
For Each c As Char in chars                      (WHAT DOES THE "c" MEAN IN THIS STATEMENT?)
    charsAndSpaces &= c & " "
MessageBox.Show(charsAndSpaces, "String Test")

12. Insert(startindex, string)
Returns a string with the specified string inserted beginning at the specified position.

-  There isn't an example of this, can someone code an example?

Dim companyName As String = "Mike Murach and Associates"
Dim index1 As Integer = companyName.IndexOf(" ")     ' 4 (IS THIS NOTING WHERE THE FIRST SPACE IS
                                                                                              AND REFERERENCING IT'S POINT AS INDEX1?)
Dim index2 As Integer = companyName.IndexOf("Inc.")  ' -1 (THIS ISN'T IN THE COMPANY NAME AT THIS
                                                                                                 POINT SO I AM CONFUSED?)
Dim index3 As Integer = companyName.LastIndexOf(" ") ' 15 (THIS IS REFERENCING THE THIRD SPACE
                                                                                                   AFTER THE AND?)

Dim index4 As Integer = companyName.IndexOf(a)   ??  (THIS IS REFERENCING THE FIRST LETTER A?
                                                                                               WHAT ANNOTATES IF ITS NOT THE FIRST  
                                                                                               LETTER A, AND IS REFERING TO THE FIRST
                                                                                               WORD WITH FIRST LETTER A? )
Dim index5 As Integer = companyName.LastIndexOf(a) ?? (BASED ON THE FIRST REFERENCE I AM
                                                                                                  GUESSING THAT IT IS REFERRING TO THE
                                                                                                  LAST WORD WITH THE FIRST LETTER A IN
                                                                                                  THE STRING?)

Code that uses the Remove, Insert, and Replace methods
companyName = companyName.Remove(0, index1 + 1)  ?? (DOES THIS SAY REMOVE THE FIRST
                                                                                                 WORD, "MIKE"?)

   = companyName.Insert(companyName.Length, ", Inc.") ??   (DOES THIS SAY INSERT "Inc." AT THE
                                                                                                    END OF THE COMPANY NAME?)

companyName _
    = companyName.Replace("and", "And")
                            ' Murach And Associates, Inc.                       (THIS CODE IS JUST SAYING REPLACE
                                                                                                    ONE DESIGNATED WORD FOR

companyName = companyName.Insert(companyName.IndexOf(and),  JJ)   ??  (THIS CODE IS SAYING
                                                                                                                                    INSERT "JJ" IN THE
                                                                                                                                   PLACE OF "and"?)

14.  Code that copies one string to another string
Dim s1 As String = "abc"
Dim s2 As String = s1
         ' This creates a new string with the value "abc"
s2 = "def"
         ' This doesn't change the value stored in s1
          s1 ??  

Answer: (abc?)

15.  Application Examples: (1) Code that parses a first name from a name string

Dim fullName As String = " Edward C Koop   "         

fullName = fullName.Trim   'fullname ??      

Answer:     ( "Edward C Koop"?)

Dim firstSpace As Integer = fullName.IndexOf(" ")   ' 6          (FIRST SPACE?)
Dim firstName As String = ""     

If firstSpace = -1 Then
    firstName = fullName        ??  (THIS STATEMENT COMPLETELY CONFUSES ME?)
    firstName = fullName.Substring(0, firstSpace)  ??  (THIS STATEMENT IS SAYING REMOVE THE FIRST
End If

16.  Examples (2): Code that uses the Split method to parse the name string
Dim fullName As String = " Edward C Koop   "
fullName = fullName.Trim  

Dim names As String() = fullName.Split(CChar(" "))                           names ??  (EDWARD, C, KOOP?)
                                                                                                            'how many elements in
                                                                                                             this names array? (6?)
                                                                                                            why CChar method is needed??  (I
                                                                                                             HAVE NO IDEA?)

Dim firstName As String = names(0)            ' "Edward"

17. Examples (3): Code that uses the Split method to parse the address string
Dim address As String = " |805 Main Street|Dallas|TX|12345|
address = address.Trim
If address.StartsWith("|") Then                                ?? Why do this?    (DESIGNATES LOCATION?)
    address = address.Remove(0, 1)                          address = ?? 805 Main Street Dallas TX 12345
End If
Dim columns As String() = address.Split(CChar("|"))  ???     (I DONT UNDERSTAND?)

Dim street As String = columns(0)       ' 805 Main Street
Dim city As String = columns(1)         ' Dallas
Dim state As String = columns(2)        ' TX
Dim zipCode As String = columns(3)      ' 12345

18. A procedure that tests whether a string contains a decimal value (or numbers?)
Public Function IsDecimal(ByVal textBox As TextBox, _
        ByVal name As String) As Boolean
    Dim s As String = textBox.Text
    Dim decimalCount As Integer = 0
    For Each c As Char In s
        If Not (c = "0" Or c = "1" Or c = "2" Or c = "3" _
             Or c = "4" Or c = "5" Or c = "6" Or c = "7" _
             Or c = "8" Or c = "9" Or c = "." Or c = "," _
             Or c = "$" Or c = "%" Or c = " ") _  what does it do?? (REFERENCE EACH CHARACTER TO SEE
                                                                                                     IF IT IS PRESENT, IF IT IS THEN ITS TRUE
                                                                                                    IF ITS NOT THEN IT THROWS AN
                                                                                                    EXCEPTI0N AND ITS FALSE)
            Return False
        End If
        If c = CChar(".") Then          what does it do???     (I DONT UNDERSTAND THIS STATEMENT?)
            decimalCount += 1
        End If
    If decimalCount <= 1 Then           why ???  (BECAUSE IT IS SAYING THAT IT IS IN FACT A DECIMAL?)
        Return True
    Else                                                               (THIS IS SAYING IF ITS NOT LESS THAN 1 ITS FALSE?)
        Return False
    End If
End Function

19.  A procedure that strips formatting characters from a numeric string  
Public Function Strip(ByVal s As String) As String
    Dim i As Integer
    For Each c As Char In s
        If c = "$" Or c = "%" Or c = "," Or c = " " Then
            i = s.IndexOf(c)        what does it do??                  (CHECKS TO SEE IF THESE CHARACTERS
                                                                                             ARE PRESENT?)
            s = s.Remove(i, 1)      what does it do??                (IF THEY ARE PRESENT THEN IT SAYS TO
                                                                                             REMOVE THEM?)
        End If
    Return s
End Function

Who is Participating?
MoreHeroicConnect With a Mentor Commented:
Just so you know, I doubt anyone is going to answer all of these questions together.  Your best bet is to break out each question you have as a question for the experts.  Individual questions are far more likely to be answered than a barrage of questions in a single EE Question.
nosurf2dayAuthor Commented:
I will do that then.  Thanks
nosurf2dayAuthor Commented:
thanks for the advice
All Courses

From novice to tech pro — start learning today.