I need help writing this function! Visual Basix This program illustrates using a
ID: 3764290 • Letter: I
Question
I need help writing this function! Visual Basix
This program illustrates using an array to hold sums. The array will hold the sums of the sales for each month. The arrays will use indexes 0 to 11 where index 0 corresponds with month Jan, index 1 with month Feb, etc.
Dim sums(11) As Integer ‘ array of month sales
Write a Function name Convert which is passed a String month name (ex. “Jan”) and returns the matching index (ex. 0).
Month Name Index
Jan 0
Feb 1
Mar 2
Apr 3
May 4
Jun 5
Jul 6
Aug 7
Sep 8
Oct 9
Nov 10
Dec 11
Explanation / Answer
Function convert(month As String) As Integer
Dim months(0 To 11) As String
months(0) = "Jan"
months(1) = "Feb"
months(2) = "Mar"
months(3) = "Apr"
months(4) = "May"
months(5) = "Jun"
months(6) = "Jul"
months(7) = "Aug"
months(8) = "Sep"
months(9) = "Oct"
months(10) = "Nov"
months(11) = "Dec"
For Index = LBound(months) To UBound(months)
convert = -1
If (StrComp(months(Index), month, vbTextCompare) = 0) Then
convert = Index
Exit Function ' to exit
End If
Next
End Function