Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limiting number of lines in a Text box 2

Status
Not open for further replies.

Asspin

Technical User
Jan 17, 2005
155
US
Does anyone know how to do this? I need to limit the number of lines to 6. I have tried the MaxLength property, and it doesn't work because of words dropping to the next line due to their length. I am losing my mind on this. I tried posting about it before here: I am using VB 6.3. Any help would be great!
 
I don't know that I can help you programmatically, but logically, the word is wrapping to the next line because they are longer than the space on the line will allow.

So, In my mind, you need to force the word to fit on the existing line in one of three ways:
1 - truncate the word to only the characters the line can hold
2 - expand the width of the line (margins, or column width depending on how you have it set up)
3 - decrease the font size so that the longest word you have never takes up more line space than you have available.

I have no clue what code you need to add to conditionally do one of these steps if your # of lines exceeds six but I would hazard a wild guess that something like this is what you need to do and that just finding a VB command isn't going to help you in this situation. Maybe you need maxlength and then case statements for special situations (for instance, you could provide acceptable abbreviations for standard long words Ex: Miscellaneous = Misc.)

HTH, or at least gives you some new ideas for solving this problem!

Lynette
 
Hmm, I guess I may just set the max a little less then the actual limit, then have some error trapping in case it runs over.
 
Hi.
That's very simple by using "Curline" property (don't set any limit to length).

Put following code in your TextBox "Change" event.

.......
If UserForm1.TextBox1.CurLine > 6 then
.........
end if



Hope this helps.
Regards.
Nick
 
This is me again.
I had forgotten that the number of first line is zero, so the correct code is:

.......
If UserForm1.TextBox1.CurLine > 5 then
.........
end if


Bye.
Nick
 
CurLine suffers from the problem that it only works if the insertion point is actually in the last line ...
 
Hmm, It looks like that will work. One more question. I need to take each line and put it into a string. Anyone know an easy way to do this?
 
Perhaps the Split function ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I think that's what I am looking for. Looking at VB help, I see Split(expression[, delimiter[, limit[, compare]]]). I am guessing something like strLine1 = Split(txtMessage.Text, ?, 6)
Not quite sure. I am sure PHV knows... cause he knows VB like the back of his hand!
 
Please excuse me, I very well may have lost my mind...
I am trying this... does it look right? Also what else do I need to break it into 6 strings?

Split(txtMessage.Text, vbNewLine)
 
Something like this ?
arrLine = Split(txtMessage.Text, vbNewLine) ' or vbLf
MsgBox "Line 3 is '" & arrLine(2) & "'"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
The following should suffice:
Dim arrLine

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Just so everyone knows... PHV is my freakin hero. I will give this a try!
 
Ok... one last question I hope. How do I test to see if there is some text in the array for that line?
I tried this but I get an error (Variable Required).

If Not arrLine(0) Is Nothing Then
 
If Trim(arrLine(0) & "") <> "" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hmm that gave me subscript out of range. Here is what I am using.

For intCount = 0 To 5
If Trim(arrLine(intCount) & "") <> "" Then
Session.Transmit arrLine(intCount)
Else
Session.TransmitTerminalKey rcHpTabKey
End If
intCount = intCount + 1
Next
 
For intCount = 0 To UBound(arrLine)
If Trim(arrLine(intCount) & "") <> "" Then
Session.Transmit arrLine(intCount)
Else
Session.TransmitTerminalKey rcHpTabKey
End If
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Someone give this man a star (or another one)!
 
Ok... I have one more problem... I am tring to find a better place to split these lines. vbNewLine works fine if someone actually makes a new line, but in most cases the message just wraps to the next line. Is there any way to do what I want to do? Hopefully I make some sense! See my exaple below.

Typed Text:
This is a test of the claim messaging system, this is only a test. Had this been an actual test, actual information would have followed.
End Test.

Text as broken down when wrapped:
This is a test of the claim messaging system, this is only a test. Had this b
een an actual test, actual information would have followed.
End Test.

I am wanting to have:
Line 1: 'This is a test of the claim messaging system, this is only a test. Had this '
Line 2: 'been an actual test, actual information would have followed.'
Line 3: 'End Test.'

My current code:
Code:
Public Sub LogClaim()
    Dim intCount As Integer, arrLine
    arrLine = Split(txtMessage.Text, vbNewLine, 6)
    Const NEVER_TIME_OUT = 0
    Dim ESC As String
    ESC = Chr$(rcESC)
    intCount = 0
    With Session
        .TransmitTerminalKey rcHpF1Key
        .WaitForString ESC & "b", NEVER_TIME_OUT, rcAllowKeystrokes
        .WaitForHostTrigger
        .TransmitTerminalKey rcHpF2Key
        .WaitForString ESC & "b", NEVER_TIME_OUT, rcAllowKeystrokes
        .WaitForHostTrigger
        .TransmitTerminalKey rcHpF6Key
        .WaitForString ESC & "b", NEVER_TIME_OUT, rcAllowKeystrokes
        .WaitForHostTrigger
        .TransmitTerminalKey rcHpF3Key
        .StatusBar = "Adding Log"
        .WaitForString ESC & "b", NEVER_TIME_OUT, rcAllowKeystrokes
        .WaitForHostTrigger
    End With
    For intCount = 0 To UBound(arrLine)
        If Trim(arrLine(intCount) & "") <> "" Then
            Session.Transmit arrLine(intCount)
            Session.TransmitTerminalKey rcHpTabKey
        Else
            Session.TransmitTerminalKey rcHpTabKey
        End If
    Next
    With Session
        .TransmitTerminalKey rcHpEnterKey
        .WaitForString ESC & "b", NEVER_TIME_OUT, rcAllowKeystrokes
        .WaitForHostTrigger
        .TransmitTerminalKey rcHpF1Key
        .WaitForString ESC & "b", NEVER_TIME_OUT, rcAllowKeystrokes
        .WaitForHostTrigger
        .StatusBar = ""
    End With
    End
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top