473,789 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB6: formatting textbox (#,###.##) in every LostFocus

montzter
15 New Member
Hi evryone,

I'm having trouble in formatting the inputed data in the text box so that everytime user lost focus it will adjust its value to contain the format (#,####.##). ie user will input 1111.1 it will immediately be converted to 1,111.10 as its value.

I've tried using this code in every lost focus:
textbox.text = round(val(textb ox.text)), 2)

but the problem with this is I am not getting the comma and if the user enters an exact integer value (means without decimal) it will remain as is.... I've also tried changing the text box property data format to number and checked the box to separate thousands in coma, but its not working.

Can anybody help me.

Thanks
Oct 29 '07 #1
5 13531
Dököll
2,364 Recognized Expert Top Contributor
... I'm having trouble in formatting the inputed data in the text box ...
Go to Projects + Components + MS Masked Edit Control, see what that does...

I should perhaps mention you may need to add maskedtextboxes in place of the ones you now have. Perhaps there is another way of achieving this through regular textboxes, but I would go with masked ones :-)

In a bit!
Oct 29 '07 #2
Killer42
8,435 Recognized Expert Expert
A few things come to mind...
  • Try using "0" rather than "#" in the format to force a digit to be included. For example, I think Format(number, "#,###.00") might work.
  • The code you posted doesn't actually use the Format() function.
  • The problem with this sort of approach is that you will probably need to strip out the comma(s) in the GotFocus event, and trust the user not to type them. I don't think the Val() function accepts them. You could also create your own function which combines the comma-stripping and string->number conversion. So instead of just using Val() you'd use something like TextBox.Text = StringToNumber( TextBox.Text) which would handle removing commas and converting to a number.
  • The Round() function rounds a number up or down to the specified number of places. It has nothing to do with formatting the number for display. If you "round" 5.00 to two places, you still have 5.00, which is exactly the same number as 5.0, or 5.000000000.
  • I believe the DataFormat property only applies to displaying a database field in the textbox. Are you doing this?
  • I'm curious - where was the "separate thousands in coma" checkbox that you checked? I'm not familiar with it.
  • Have you considered using a Masked Edit control instead of a textbox? It gives you much better control over the format.
Well, I hope that is some help.
Oct 29 '07 #3
montzter
15 New Member
You guys do reply fast!!! I thought I can get the reply in a day or two!!!
anyway I have tried the first reply and I will go with it. Value of the maskedbox.text remains unchanged even if there were already commas being entered. this is cool compnent..


Thanks for pointing me to the right direction.
Oct 29 '07 #4
montzter
15 New Member
A few things come to mind...
Wow you have a lot of ideas but sound too complicated for me. I go with your last bullet. Actually I am using a database. There's no problem with the data in the database, it's just that the user wants it in this format to be displayed. So got a problem with the textbox.

Thanks again for the help.
Oct 29 '07 #5
Killer42
8,435 Recognized Expert Expert
Glad we could help. :)

As for the quick response, you were just lucky to catch a couple of us at the right time. It can sometimes take quite a bit longer.
Oct 29 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1630
by: Robert W. | last post by:
I'm developing a WinForms app and have a slight problem that I hope someone can help me with. There are a series of textboxes that the user can enter information into. The text in these boxes is only copied into the data model when the textbox's LostFocus event is fired. This has worked well so far. But I've just noticed that if the user enters some text into a textbox and then goes up to File-Save (on the parent form) that the newly...
1
1572
by: Carlo | last post by:
Hi How do I get textbox text to be formatted on the fly as entering. I have a textbox which will hold numerics larger than a million which I want to autoformat i.e FormatNumber, so that it makes it easier for the person inputting to visually see what they are entering i.e they could enter 100000000 - difficult to see on the fly how many millions. I would therefore like it to autoformat to 100,000,000 - lot easier to read I tried: dim...
5
1413
by: Jack | last post by:
Hell I have a few text boxes on my form and I need in one to allow only numbers and on the other only letters how to enforce that you can't enter numbers in a letters textbox and... Jack
7
1614
by: Localbar | last post by:
Hi all, In my form have more then 10 textbox. I would like to make all textbox when lostfocus backcolor is white, when gotfocus backcolor is yellow. But I don't want to write same code in the form. How to solve this problem. Is it can make a textbox class to control or some other method? Thanks
18
2509
by: obrienkev | last post by:
Hi, I have a multiline TextBox. Text contained in the TextBox will be stored in a SQL Server Database. How do I format the textBox correctly for database entry? e.g. How do I ensure that new lines will be added, etc? Thanks.
0
1256
by: massx | last post by:
I have a project iv'e been racking my brain on for a while heres the basics i have a textbox that gets populated with mp3's in an xml playlist that looks like this.. <?xml version='1.0' encoding='UTF-8'?> <player showDisplay='yes' showPlaylist='yes' autoStart='1'> <track URL="http://host.com/file/1.mp3" artist="Artist" songname="one" song_id="1" band_user_name="band" /><track URL="http://host.com/file/2.mp3" artist="Artist"...
6
30008
by: Andy B | last post by:
I need to take the value of a textbox and format it in a more readable date. How do you do this? I tried textbox.text.tostring("date format string") but the compiler doesnt like that idea... any ideas?
12
4848
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I want to plant an Easter Egg in our software. We have a TextBox that is multiline and used to display all sorts of messages on the screen for our operators based on database queries and such. The Easter Egg I want to create would send a dump of the data for a particular part number to the screen when a certain secret combination of characters is pressed. If it works out well, I can actually impliment it on our production floor.
3
2418
by: dougancil | last post by:
I have a web page that will be supplying data to a sql query and I want my users to type in dates as mm/dd/yyyy but my sql query needs the dates as yyyy/dd/mm. How can I reformat the textbox.text to reflect that re-formatting of the data? Thank you Doug
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10374
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10121
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5404
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.