Previous in Forum: iPhone CR4 App   Next in Forum: WeldShop - Free Welding Software for Piping Welding (Carbon & Low Alloy Steel)
Close
Close
Close
5 comments
Rate Comments: Nested
Anonymous Poster

Displaying the Length of a String on the fly in VB

05/25/2010 7:27 AM

Hello Everybody,

I might not have phrased my title accurately but what I need is to input a string in VB (visual basic) and display its length as I type it. I have declared the string as follows:

DIM TextString As String

..............

TextString = InputBox("Feedback", "Enter your message Here.")

However, I can only determine the length of the input string after pressing OK, meaning that I cannot display the length as I type! The user must know how many characters he's typed AS HE TYPES, not find out once when he's pressed the return key.

I'd be very glad to receive any meaningful contributions.

Cheers,

Ben (Cape Town)

Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#1

Re: Displaying the Length of a String on the fly in VB

05/25/2010 7:44 AM

Inputbox (like msgbox) is rather limited - as I recall they're both application modal, so you can't do anything else 'til they're closed. You'll have to make your own version - either as a form in your project, or (if you want to get fancy) as an ActiveX object.

To do the length measurement & display, I'd suggest using the change event of the textbox into which the string is being typed. Remember to return the focus to the input textbox after updating the character count display.

[BWT - if you take a couple of minutes to register, and then subscribe to this thread, you can get e-mail notifications of when folk post here. It's worth the effort.]

__________________
"Love justice, you who rule the world" - Dante Alighieri
Reply
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#4
In reply to #1

Re: Displaying the Length of a String on the fly in VB

05/26/2010 4:20 AM

Update - don't need to return the focus - I've just tried it and the focus doesn't change (whether you're displaying the character count in a label or a textbox).

__________________
"Love justice, you who rule the world" - Dante Alighieri
Reply
Guru
Engineering Fields - Electromechanical Engineering - Technical Services Manager Canada - Member - Army brat Popular Science - Cosmology - What is Time and what is Energy? Technical Fields - Architecture - Draftsperson Hobbies - RC Aircraft - New Member

Join Date: Sep 2006
Location: Clive, Alberta, Canada
Posts: 5916
Good Answers: 204
#2

Re: Displaying the Length of a String on the fly in VB

05/26/2010 12:51 AM

1) don't use the inputbox.

2) create a form that matches it in style and appearance. (modal, textbox & ok button) (called by the main form using 'show' function)

3) use the len function, and a keypress or keydown function to count characters on the fly, or do other validation.

Chris

Reply
Power-User

Join Date: Jun 2007
Location: Oxford, UK
Posts: 145
Good Answers: 3
#3

Re: Displaying the Length of a String on the fly in VB

05/26/2010 3:57 AM

Use a label or textbox to display the number of characters.

Use the KeyPress event to count the number of characters remembering that if the Delete key is used to take 1 off the total.

You may also get an answer here http://www.vbforums.com/forumdisplay.php?f=1&order=desc

__________________
Tony Aston
Reply
Guru
Engineering Fields - Electromechanical Engineering - Technical Services Manager Canada - Member - Army brat Popular Science - Cosmology - What is Time and what is Energy? Technical Fields - Architecture - Draftsperson Hobbies - RC Aircraft - New Member

Join Date: Sep 2006
Location: Clive, Alberta, Canada
Posts: 5916
Good Answers: 204
#5
In reply to #3

Re: Displaying the Length of a String on the fly in VB

05/26/2010 5:48 AM

how do you put a label or textbox on a inputbox??

you first must instruct the OP not to use the inputbox. (like JohnDG and I did)

and after that, you are saying the same thing mentioned earlier...

Reply
Reply to Forum Thread 5 comments
Copy to Clipboard

Users who posted comments:

chrisg288 (2); JohnDG (2); Tony Aston (1)

Previous in Forum: iPhone CR4 App   Next in Forum: WeldShop - Free Welding Software for Piping Welding (Carbon & Low Alloy Steel)

Advertisement