Dynamic Array

  • Thread starter Thread starter Mili
  • Start date Start date
M

Mili

Hi,

How to add three String elements in a dynamic array of
strings, and display the same in the msg box.

Array is dynamic. i.e

dim msgs () as String

now I want to add three different string in this array.

and I want to display theh same in the msg box.

Thanks

Regards

Mili.
 
Hi Mili,

The following code snippet should help you get started:

---
Sub ThreeStrings()
Dim Msgs() As String
Dim Msg As String
Dim I As Long

ReDim Msgs(1 To 3)
Msgs(1) = "Hello World"
Msgs(2) = "How are you?"
Msgs(3) = "I am fine"

For I = LBound(Msgs) To UBound(Msgs)
Msg = Msg + vbCrLf + Msgs(I)
Next
Msg = Right(Msg, Len(Msg) - 2)
MsgBox Msg
End Sub
---

- Chirag

PowerShow - View multiple shows simultaneously
http://officerone.tripod.com/powershow/powershow.html
 
Depending on whether there's already stuff in the array, you may need to
preserve the existing contents.
To do that, you can use this instead of the Redim line in Chirag's example:

Redim Preserve msgs(1 to Ubound(msgs) + 1) as String
(assuming 1-based arrays)

That adds an empty blank element to the array
 
Back
Top