Solved

Text longer than textbox

Posted on 2003-10-29
9
144 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Passing a Text Box name to a Sub 6 104
TT Auto Dashboard 13 104
Modify Text File with Excel Macro 13 47
Userform to show a range in excel. 3 33
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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