Characters-Textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,
I was wondering if it is possible to split a textbox into an array for every
500 characters.
What I was looking to do is to take the text in a textbox and split it up
for every 500 characters in the current box - the "split" up text would then
become an element in an array.

Thanks.
-Stats
 
hi,

State said:
I was wondering if it is possible to split a textbox into an array for every
500 characters.

Const lngLimit As Long = 500

Dim lngCount As Long
Dim lngSplits As Long
Dim strArray() As String
Dim strText As String

strText = "String to split..."
lngSplits = Len(strText) \ lngLimit

If Len(strText) Mod lngLimit = 0 Then
lngSplits = lngSplits - 1
End If
ReDim strArray(0 To lngSplits)

For lngCount = 0 To lngSplits
strArray(lngCount) = Mid$(strText, lngCount * lngLimit + 1, lngLimit)
Next lngCount


mfG
--> stefan <--
 
hi,

State said:
Thanks.
Works perfectly.
Is it possible to explain the code?
Your limit for the string length.
Determine the number of splits using integer division.

Example:
lngLimit = 3
strText = "AbcDefGh"
lngSplits = 8 \ 3 = 2 '3 * 2 + rest 2 = 8
If Len(strText) is multiple of lngLimit, then there is no rest. Cause we
are using a zero-based array, we have to decrease the number of elements
needed.

Example: see above.
We need 2 elements with lngLimit characters and on element for the rest.
Zero-based 0 to 2 are three elements.
See OH for Mid$().

mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top