Hi All, I have a question here and need your advice, I have a textbox which enable multi-line, I have key key few line of the text but I want to program it maybe just capture the first line to field 1 and second line to field 2.
Dim strText As String
Dim arr() As String
strText = Text1.Text
arr() = Split(strText, vbNewLine)
first line = arr(LBound(arr)) ' arr(0)
second line = arr(1)
end line = arr(UBound(arr))
Always test the result of Split for Ubound. TThe rUbu8nd after a Split in VB6 can be -1 as in
Dim aryW() as String
aryW = Split("","," ' split Zero length string
Msgbox Cstr(Ubound(aryw)) ' = -1
Also there may be fewer elements that you expect.
arr() = Split(strText, vbNewLine)
Dim lngU as Long
lngU = Ubound(arr)
if lngU > -1 then
first line = arr(LBound(arr)) ' arr(0)
if lngU > 0 then
second line = arr(1)
End if
end line = arr(UBound(arr))
end if
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.