473,320 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Textbox format

Alireza355
Deal all,

I have a textbox that I want to apply some formatting to the text:

I know that if the textbox contains only numbers, by selecting "Standard" format, I can have the thousands seperator: 1,245,000

but the textbox that I have includes both text and number. for example:

Hello 1245000

I want to apply the thousand seperator to it:

Hello 1,245,000

How? :(
Mar 26 '09 #1
8 1779
ChipR
1,287 Expert 1GB
Text parsing is a bit of a pain, but if you have to do it, try this.
Split() the text into separate words.
Check whether each word is a number with IsNumeric().
If the word is numeric, use FormatNumber() with the GroupDigits option.
Concatenate each of the words together again for the result.
Mar 26 '09 #2
NeoPa
32,556 Expert Mod 16PB
Good idea.

The Join() function can also be used to put the various elements back together. It is effectively the opposite of Split(), even with the same optional separator parameter.
Mar 26 '09 #3
ADezii
8,834 Expert 8TB
@Alireza355
Is the Format always TEXT & SPACE & NUMBER?
Mar 26 '09 #4
ADezii
8,834 Expert 8TB
@Alireza355
To expand on ChipR's explanation in Post #2, and assuming components are delimited by a Space (" ") then:
Expand|Select|Wrap|Line Numbers
  1. Public Function fFormatString(strSomeString As String) As String
  2. Dim varSplit As Variant
  3. Dim strBuild As String
  4. Dim intCounter As Integer
  5.  
  6. If Len(strSomeString) = 0 Then Exit Function
  7.  
  8. varSplit = Split(strSomeString, " ")
  9.  
  10. For intCounter = 0 To UBound(varSplit)
  11.   If IsNumeric(varSplit(intCounter)) Then
  12.     strBuild = strBuild & " " & FormatNumber(varSplit(intCounter), 0)
  13.   Else
  14.     strBuild = strBuild & " " & varSplit(intCounter)
  15.   End If
  16. Next
  17.  
  18. fFormatString = Trim$(strBuild)
  19. End Function
Expand|Select|Wrap|Line Numbers
  1. ? fFormatString("Help 12345 6792 me 656565656 Rhonda 989776 4434434 A B C 456") produces ==>
Help 12,345 6,792 me 656,565,656 Rhonda 989,776 4,434,434 A B C 456
Mar 26 '09 #5
Dear Adezii,

Thank you so much for your kind help.

Please tell me how I can use the code you have given. (Where to put it and what to change, and how to make it run)

And I also thought this might be useful: the textbox I am trying to format is a calculated textbox.

=IIf([text51]=[text49],0,IIf([text51]>[text49],[text51]-[text49] & " (Credit)",[text49]-[text51] & " (Debit)"))

Thanx a lot.
Mar 28 '09 #6
ADezii
8,834 Expert 8TB
@Alireza355
  1. Copy and Paste the entire Function Definition into the General Declarations Section of a Standard Code Module, the Function will then be contained within the Module and can be called from anywhere within the Application since it is Public.
  2. Create an Unbound Text Box, and set its Control Source to:
    Expand|Select|Wrap|Line Numbers
    1. =fFormatString(IIf([text51] = [text49], 0, IIf([text51] > [text49], [text51] - [text49] & _
    2. " (Credit)", [text49] - [text51] & " (Debit)")))
Mar 28 '09 #7
WOW!!!!!!!!!!!!!!!!

Thanx a loooooooooooooooooooooooooooooooooooooooooot
Mar 29 '09 #8
ADezii
8,834 Expert 8TB
@Alireza355
You are quite welcome, Alireza355.
Mar 29 '09 #9

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

Similar topics

1
by: Jose Gonzalez | last post by:
How to apply a numeric format to a textbox using xhtml? I know you have to use the "-wap-input-format" style tag in css. I can get this to work in a regular xhtml page, however, I've been...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
1
by: Rich | last post by:
Hello, I have some datefields in a dataset (ds1). I bind some textbox controls on a windows form to these date fields in ds1, but I only want to see 01/01/2004 instead of 1/1/2004 8:00:00 AM. ...
14
by: MLH | last post by:
I use A97. I've gotten used to reading values from textbox controls on forms, I've come to rely on it pretty heavily. My habit spills over into reports. I'm uncertain whether I can reliably read...
2
by: Adam Honek | last post by:
I have a form. It has serveral text boxes for user data entry. I could of course write code to check if each is empty before proceeding to save this data to a file. Is there any global way...
0
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the...
2
by: nussu | last post by:
Hi, A textbox has to accept only numeric values by using validation controls in .net 2.0 Plz help me ... Regards, Nussu
1
by: JFKJr | last post by:
Hello everyone, the following Access VBA code opens an excel file and creates textboxes in a given range of cells dynamically. The code attaches "MouseUP" and "Exit" events to the textboxes (using...
9
by: =?Utf-8?B?dHBhcmtzNjk=?= | last post by:
OK I have some Chinese text in sql server column that looks like this: 12大专题调研破解广东科学发展难题 This is unicode? Anyway, I put this data into a text area like this:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.