plaidshirt
plaidshirt

Reputation: 5681

Random string split into characters

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

Upvotes: 1

Views: 296

Answers (1)

Mathieu Guindon
Mathieu Guindon

Reputation: 71217

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

Upvotes: 1

Related Questions