Heres some quick and nast code i've put together - if it doesn't exactly do what you meant then it might at least go close...
Code:Private Sub Command1_Click() Dim TempStr As String Dim i As Integer Dim myArray() As String 'Get the string from the textarea (textbox) TempStr = Text1.Text 'Create MyArray by delimiter cariiage return line feed myArray = Split(TempStr, vbCrLf) 'Num elements in the new array Dim NumberOfElements As Integer NumberOfElements = UBound(myArray) + 1 If NumberOfElements < 4 Then 'Not enough lines entered in textbox ReDim Preserve myArray(3) 'extend array to 4 elements (0 to 3) For i = NumberOfElements To 3 myArray(i) = "" 'initialise to 0-length string the new elements Next i ElseIf NumberOfElements > 4 Then 'too many lines entered in textbox For i = 4 To UBound(myArray) 'Add all the extral lines to the 4th line myArray(3) = myArray(3) & " " & myArray(i) Next i ReDim Preserve myArray(3) 'Reduce the array back to 4 elements End If 'Put the string back together TempStr = myArray(0) & vbCrLf & _ myArray(1) & vbCrLf & _ myArray(2) & vbCrLf & _ myArray(3) 'Reassign it to the textbox Text1.Text = TempStr End Sub




Reply With Quote