Solved

Text longer than textbox

Posted on 2003-10-29
9
142 Views
Last Modified: 2010-05-03
How do I figure out if the text inside a textbox is longer than the textbox (all the text cannot be displayed)?
0
Comment
Question by:PLavelle
9 Comments
 
LVL 9

Assisted Solution

by:Dang123
Dang123 earned 150 total points
ID: 9643161
This should get you off to a good start

http://www.vb-helper.com/howto_size_textbox.html
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 350 total points
ID: 9643168
Hi PLavelle,

You can use the following method to achieve this.

Private Sub TestLength(ByRef TBox As TextBox)
    With TBox
        If Me.TextWidth(TBox.Text) > TBox.Width - 100 Then
            MsgBox "Uh oh"
        End If
    End With
End Sub

Shows how

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9643946
hearing...
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9643970
You could know in advance how many lines would be displayed in advance, doesn't it?
Then, just knowing how many lines has after the text box is populated and comparing with that data, you should know if text is completelt displayed or not.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9643989
Const WM_USER = 1024
Const EM_GETLINECOUNT = WM_USER + 10
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long


TotalLines = SendMessage(Text1.hWnd, EM_GETLINECOUNT, 0, 0&)
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9644001
Richie_Simonetti,
 Different fonts take differing amount of room for the same letters. The link I posted above uses TextWidth and TextHeight to take this into account.

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9644059
You are right but you know that when design the app and set the properties, isn't it?
Simply doing a test, you would know how many lines textbox would displays.
If font size is 24, maybe you will see only one line, if font size is 12 you would see 2 lines and so on, so it is easy to test it.
TextWidth and TextHeight would be usefull when you know nothing about YOUR textbox target but this is not the case.
0
 

Author Comment

by:PLavelle
ID: 9644481
Thank you.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9644533
wow! Besides VB, i have to learn to read minds!!!
:)))))))
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question