Is there any way through which I can split a single string into substrings with 20 characters each.
The first string should contain first 20 characters.
The seconds string should contain the next set of 20 characters and so on.
Is it possible to do what I'm thinking?

Recommended Answers

All 3 Replies

can you try this one
you can set the multiline property of text2 to True

Dim strx As String
Dim cntr As Integer
Dim xstart As Integer
Dim sellen As Integer
Dim num As Integer
Dim storex(0 To 20) As Variant
Dim xlen As Integer
Dim xnewstr As String

Private Sub Command1_Click()

sellen = Text3.Text
strx = Text1.Text
xlen = Len(Text1.Text)
num = xlen / sellen
xnewstr = Left(strx, sellen)
xstart = 1
cntr = 0

Do Until cntr = num
    xnewstr = Mid(strx, xstart, sellen)
    storex(cntr) = xnewstr
    xstart = xstart + sellen
    cntr = cntr + 1
    Text2.Text = Text2.Text & vbCrLf & xnewstr
Loop

End Sub

you just need to write a simple loop by using an array and some string functions.

I think that the Mid Function would be your best option.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.