Assign text and variables into an array

  • Thread starter John in Toronto
  • Start date
J

John in Toronto

I'd like to assign a combination of string variables and text to an array,
but I'm doing something wrong and get a type mismatch error.

Here is part of the code:

Dim strMonth as String
Dim SearchArray As Variant
strMonth = "Februrary"
SearchArray(0) = "day, " + strMonth + " ^#^#"

What am I doing wrong?

Thanks,

John
 
G

Greg Maxey

I'd say the problem is that your array was never dimensioned and allocated:

Dim strMonth As String
Dim SearchArray As Variant
ReDim SearchArray(0)
strMonth = "Februrary"
SearchArray(0) = "day, " + strMonth + " ^#^#"
 
D

Doug Robbins - Word MVP

Use:

Dim strMonth As String
Dim SearchArray() As Variant
strMonth = "Februrary"
ReDim SearchArray(1)
SearchArray(1) = "day, " & strMonth & " ^#^#"
MsgBox SearchArray(1)


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top