|
-
Jun 15th, 2006, 11:25 AM
#1
Thread Starter
Addicted Member
Resolved[Commas in a text box]
Is it possible to modify a text box in order that while you are filling it with numbers, they get separated by a comma? Not for a later print, just while you fill it.
Last edited by Fonty; Jun 15th, 2006 at 12:22 PM.
-
Jun 15th, 2006, 11:54 AM
#2
Re: Commas in a text box
You can do it from either the Change, Enter, or KeyPress events. Probably the change event will be best. Just use the Replace function and replace the comma with a vbnullstring.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 15th, 2006, 11:59 AM
#3
Thread Starter
Addicted Member
Re: Commas in a text box
What I meant was that I use Format function to format it with a comma for a later print. That's working fine. But I think it would be freindlier for the user if instead to entering 230000 and then seeing printed 230,000; the comma appeared instantly after filling the fourth character, between it and the third.
-
Jun 15th, 2006, 12:12 PM
#4
Re: Commas in a text box
Is this a currency value? If it is then you can apply formatting for it in the Exit event then.
VB Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.Text = Format(TextBox1.Text, "###,###,###")
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 15th, 2006, 12:23 PM
#5
Re: Commas in a text box
 Originally Posted by Fonty
What I meant was that I use Format function to format it with a comma for a later print. That's working fine. But I think it would be freindlier for the user if instead to entering 230000 and then seeing printed 230,000; the comma appeared instantly after filling the fourth character, between it and the third.
What if the 4th character was the last character with the 2300 being entered instead of 23000 or 230000? How is the program supposed to know, before hand, that what the number will be?
I think the way you are doing is the best. Unless, of course, the numbers being entered will ALWAYS be six characters in length.
-
Jun 15th, 2006, 12:40 PM
#6
Re: Resolved[Commas in a text box]
Hack, have you tried my code? It will format it from right to left. so if you enter in 1234 it weill be 1,234. 
The format mask is the solution here.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 15th, 2006, 01:13 PM
#7
Re: Resolved[Commas in a text box]
-
Jun 15th, 2006, 06:01 PM
#8
Re: Resolved[Commas in a text box]
I can see from the thread being resolved that the event didnt matter 
But for others you can do like this to format as you type. 
VB Code:
Private Sub TextBox1_Change()
TextBox1.Text = Format(TextBox1.Text, "###,###,###")
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|