Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21292

[RESOLVED] Subscript out of Range

$
0
0
Hi
I need to split data from a datagrid column say
Brown John E & Jane P
Code:

VB6
Option Explicit
Private sNamePart() As String  'array of strings
Private s As String

s = Brown John E & Jane P

Private Function mySplitName()
Dim i As Integer

sNamePart = Split(s, " ") 'split string up by spaces
    For i = LBound(sNamePart) To UBound(sNamePart)
      '  Debug.Print sNamePart(i) 'Testing Only
    Next i
s = vbNullString
End Function

Result
sNamePart(0) = "Brown"
sNamePart(1) = "John"
sNamePart(2) = "E"
sNamePart(3) = "&"
sNamePart(4) = "Jane"
sNamePart(5) = "P"

I can then add the parts to the textbox
txtA.Text = sNamePart(0) = "Brown"
txtB.Text = sNamePart(1) = "John"
But if sNamePart(3) = Out of range or Empty

How do I get around this I think it may be lBound\uBound but I could not get this to work.
How can I put this in an If Statement?
Can you help please?

Viewing all articles
Browse latest Browse all 21292

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>