473,503 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Turning customerID-number "10205" into layout "10 205"

1 New Member
How do I do that? Turning the layout from the customerID-number "10205" into looking like "10 205"? I've just incresed it from four digits to five, and it looks like this: lsvItem.SubItems(1) = Right("0000" & CStr(rs!customerID), 5), but how do I affect the layout?
Apr 23 '07 #1
3 1534
Killer42
8,435 Recognized Expert Expert
How do I do that? Turning the layout from the customerID-number "10205" into looking like "10 205"? I've just incresed it from four digits to five, and it looks like this: lsvItem.SubItems(1) = Right("0000" & CStr(rs!customerID), 5), but how do I affect the layout?
One fairly simple way would be...
Expand|Select|Wrap|Line Numbers
  1. strID = Right("0000" & CStr(rs!customerID), 5)
  2. lsvItem.SubItems(1) = Left(strID,2) & " " & mid(strID,3)
You could probably do it more simply using the Format() function, I'm just too lazy to look it up right now.

The precise method would depend a bit on the format of the customerID field - is it text or numeric?
Apr 24 '07 #2
Robbie
180 New Member
I think you mean you want to put a space after every third digit starting from the right to separate hundreds, thousands, millions, hundred-millions etc...?
Example: 99999999 -> 99 999 999
If so, I'll try to make a function for you...

Here we are! :D Tested and working:

Expand|Select|Wrap|Line Numbers
  1. Public Function NumberSeparate(NumberToSeparate, Optional SeparatingChar As String = " ") As String
  2. '
  3. 'NumberToSeparate - The original number
  4. 'SeparatingChar -   What to separate the digits with.
  5. '                   Usually a comma, space, or dot.
  6. '                   By default it is a space.
  7. '
  8. 'Gives back a string with the number nicely separated at every
  9. 'third digit.
  10.  
  11.  
  12. Dim CurrentDigit As Byte
  13. Dim CurrentBackward As Integer
  14.  
  15. CurrentDigit = 0
  16. NumberSeparate = Str(NumberToSeparate)
  17.  
  18.     For CurrentBackward = Len(NumberSeparate) To 1 Step -1
  19.  
  20.         CurrentDigit = CurrentDigit + 1
  21.         If CurrentDigit = 3 Then
  22.  
  23.             NumberSeparate = Mid(NumberSeparate, 1, CurrentBackward - 1) + SeparatingChar + Mid(NumberSeparate, CurrentBackward, Len(NumberSeparate) - (CurrentBackward - 1))
  24.             CurrentDigit = 0
  25.  
  26.         End If
  27.  
  28.     Next CurrentBackward
  29.  
  30.     'Remove any accidental separating chars on the left
  31.     'before any digits!
  32.     While Mid(NumberSeparate, 1, 1) = SeparatingChar
  33.         NumberSeparate = Mid(NumberSeparate, 2, Len(NumberSeparate) - 1)
  34.     Wend
  35.  
  36.  
  37. End Function
  38.  
Apr 24 '07 #3
Killer42
8,435 Recognized Expert Expert
Thanks for that.

I don't mean to rain on your parade, but it seems to me you could achieve much the same end with one statement...
Expand|Select|Wrap|Line Numbers
  1. Public Function NumberSeparate(NumberToSeparate, Optional SeparatingChar As String = " ") As String
  2.   ' NumberToSeparate - The original number
  3.   ' SeparatingChar -   What to separate the digits with.
  4.   '                    Usually a comma, space, or dot.
  5.   '                    By default it is a space.
  6.   ' Gives back a string with the number nicely separated at every
  7.   ' third digit.
  8.  
  9.   NumberSeparate = Replace(Format(NumberToPad, "#,###"), ",", SeparatingChar)
  10.  
  11. End Function
(Sorry, but since I recently discovered the Split and Replace functions I've been having great fun finding uses for them.)

Oh, and this might need adjustment to handle different regional number-formatting settings.
Apr 24 '07 #4

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

Similar topics

49
2350
by: lime | last post by:
I have addressed most of the issues listed in the responses to my last post "Critique CSS layout (1st go - fingers crossed)". I'm rapt with the progress I have made, thanks to all for your past...
30
3088
by: Diane Wilson | last post by:
I'm trying (once again) to figure out how to make a robust CSS layout style that can replace tables. I'd like to be able to do a basic two-column layout, with a one-column header, a two column...
0
1368
by: Deena | last post by:
Hi Windows forms layout is turning to be a nightmare. I add my controls to a form and then save it and then it just get's all messed up. I'm using inheritance if this makes any difference. Also...
5
1382
by: et | last post by:
How do I get Visual Studio to quit modifying the layout of my code? In Tools, Options, Text Editor, All Languages, Tabs, I have set to None. In HTML/XML, I have tabs set to none; all automatic...
10
2788
by: Magnus Warker | last post by:
Hi group! I know that HTML output is not as predictable as sometimes desired, but let me ask a question. The following HTML code produces a rectangle that covers the entire client area of a...
3
2256
by: =?Utf-8?B?QnJldA==?= | last post by:
I have a standard Form View bound to a SQL Data Source with about 30 fields and it works well and fine. However I want to change the layout from the standard Vertical View of form to a more...
3
4211
by: Jlcarroll | last post by:
Hi, I am building a web page.and have a simple javascript menu... I call the javascript menu within a div block that my print sytlesheet has set as a display: none;, well all the content in that...
18
2486
by: Nik Coughlin | last post by:
I am halfway through writing a tutorial on image slicing for fluid CSS layouts, I would love some feedback on what I've done up until this point: http://nrkn.com/index.html I am still writing...
53
4063
by: brave1979 | last post by:
Please check out my javascript library that allows you to create any layout for your web page, nested as deep as you like, adjusting to width and height of a browser window. You just describe it in...
0
7199
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,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4670
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...
0
3162
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...
0
1507
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 ...
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.