1

I have a procedure, that generates a random string without any delimiter. I store return value of this as a string, but I would like to split this text into characters and after that examine each characters. I try to use above code to split string into characters, but it gives Type mismatch error.

Sub gen()
    Dim s As String
    s = textgen(4000, 5)
    Dim buff() As String
    ReDim buff(Len(s) - 1)

    For i = 1 To Len(s)
        buff(i - 1) = Mid$(s, i, 1)
    Next

    MsgBox (buff)  ' type mismatch
End Sub
Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
plaidshirt
  • 5,189
  • 19
  • 91
  • 181
  • possible duplicate of [Split string into array of characters?](http://stackoverflow.com/questions/13195583/split-string-into-array-of-characters) – iDevlop Feb 25 '15 at 19:38

1 Answers1

1

The type of buff is string() - an array of strings (VBA doesn't have a Char type).

MsgBox wants a String message, not an array of these; you'll have to Join the elements:

MsgBox Join(buff) 'no error
Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235