Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Return string element from array given index

I have the following code:

     Dim CurrMonth As Integer
     Dim MonthPos As Variant
     Dim CurrPos As Integer
     
     
     CurrMonth = Month(Date) - 1
     MonthPos = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")

Could anyone provide guidance on how I would be able to get (in this case) the string element from the Array MonthPos given the index CurrMonth.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

https://www.softwaretestinghelp.com/vba-array-tutorial/#One_Dimensional_Array offers following example:

Private Sub arrayExample3()
Dim thirdQuarter(13 To 15) As String 'creates array with index 13,14,15
thirdQuarter(13) = "July"
thirdQuarter(14) = "Aug"
thirdQuarter(15) = "Sep"
MsgBox "Third Quarter in calendar " & " " & thirdQuarter(13) & " " &
        thirdQuarter(14) & " " & thirdQuarter(15)
End Sub

So for your case should be:

MonthPos(CurrMonth)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading