Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Custom MsgBox 8    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Dynamic Prompt Sizing
Chris Bezant 
      
3 years ago
Hello Rick
Following your uDialog videos some time ago I produced my own version based on your teaching.
I didn't think about named parameters at the time so instead of all those commas I used a user defined type so that the options are passed using a data structure.
The one thing that I have not got right for all situations is to dynamically adjust the height of the prompt depending on its amount of text.
Some of my messages contain text built on the fly, like file paths and names for example.
And these contain vbnewlines for readability.
If you could include dynamic sizing in this design then I would abandon mine for yours.
Richard Rost  @Reply  
           
3 years ago
Yeah, I thought about that and that's going to be tricky because if you're using a variable font size or even font type, for example, you would have to change the calculations for the height and width. So, the only way to really get a good size for the box would be to use a standardized monospace font like Courier New and a specified font size like 16. At those things changes, you can adjust up and down, but a lot of it would be trial and error. I've added it to my list, and I'll take a look at it for a future video if I can come up with something halfway decent.
Kevin Yip  @Reply  
     
3 years ago
I was just tackling this issue in my own project.  The methodology I came up with:

STEP 1: Create a textbox that is, say, 3.25 inches wide and 3 inches tall (Figure 1 below).

STEP 2: Fill the textbox completely with characters.  With Calibri size 14, I can fill 12 lines of text comprising of 358 characters of ASCII code 33 to 126, including word wraps caused by the minus sign.  See Figure 1 below.  

STEP 3: Calculate approx. number of characters per line in the textbox.  From the above info, it is 358 / 12 = 29.8333.

STEP 4: Count the number of line breaks (vbCrLf) in the text.  Each line break adds a line in the textbox.  Richard has a video on finding how many substrings occur within a string.

STEP 5: Calculate the number of lines needed to be shown in the textbox to accommodate the message.  This equals to the length (in chars) of the message, divided by chars per line (Step 3), plus 1 (making sure the minimum is 1), plus the number of line breaks (Step 4).  You need to round down to the nearest integer.  E.g. 9.7537 lines = 9 lines.

STEP 6: Here is my special sauce.  For every 100 characters (an arbitrary number), I deduct the number of lines by 1.  This is to compensate for the inexact nature of this methodology -- the same way we compensate leap year and leap century with one extra day, because each year is not exactly 365 days, but 365.2437... something.

STEP 7: Convert the number of lines to "twips", the unit of height used by Access in VBA.  One inch equals 1440 twips (which stands for "twentieth of an inch point").  The textbox is 3" tall, so it is 3 x 1440 = 4320 twips in height.  The textbox has 12 lines, so each line is 4320 / 12 = 360 twips in height.  Multiply the number of lines (Step 5) with 360 to get the number of twips that should be the textbox's height.

The main challenge is really the math.   The resulting VBA code is only a few lines.
Kevin Yip  @Reply  
     
3 years ago

Alex Hedley  @Reply  
           
3 years ago
Could WizHook help here?
Richard Rost  @Reply  
           
3 years ago
I love your algorithm, and yeah, that's about something along the lines of what I would do.
Kevin Yip  @Reply  
     
3 years ago
Hi Alex, I've tried using WizHook, but it can only adjust the width of a textbox that contains only single-line text.  It doesn't adjust the height to auto-fit multi-line text.  The line breaks caused by word-wrapping can be unpredictable, as shown in my picture ("-" and space, as well as justification can affect where word-wraps occur).  The WizHook function can figure out the widths of the alphabet of varying font styles and sizes, but apparently not where the line breaks are (which is the key), both soft and hard.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Custom MsgBox 8.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 6:00:05 PM. PLT: 0s