Solved

I need help formatting values in VB6

Posted on 2014-01-08
5
274 Views
Last Modified: 2014-01-27
HiExperts,
I need help formatting some field values in VB6.  I need the following:

Any currency value in this format:        -#########.##
Any date value in this format:             MM/DD/YYYY
Any numeric value in this format:      ###########
Any phone value in this format:            (Exactly 10 digits for example  (123) 456-7890  would become 1234567890)
Any SSN value in this format:            (Exactly 9 digits for example 111-22-3333 would become 111223333)
Any TIME value in one of these 2 formats:      HH:MM[:SS]  for any 24 hour time for example 1345 would become 13:45:00
                                    HH:MM[:SS] AM/PM  for any 12 hour time for example 1:45 would become 01:45:00PM


Thanks in advance for all of your help,
mrotor
0
Comment
Question by:mainrotor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 39766701
1. Are these "field values" in a recordset variable or Access table/query result?

2. Where does this formatting take place?
0
 

Author Comment

by:mainrotor
ID: 39766725
The fields are in an array

This is what my code looks like as I loop through the array:

strRecord = strRecord & "," & Trim$(Replace(tblEmployee.Extract(6, 1, 1), ",", "''"))
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39766728
Have you looked at the Format() function? It is well documented in the MSDN Help that comes with VB6.

If you can't find that, the VBA version of the function is the same and the Microsoft reference can still be found on line here:
http://msdn.microsoft.com/EN-US/library/office/gg251755.aspx

If, after trying, you have a problem with any specific format target, let us know.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39767087
Which columns/indexes contain what kind of data?
Please take a second look at your TIME specification.  These two examples do not align with each other or prior (data type) examples.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39767552
mainrotor,
Here is an illustration of the use of the Format function:
strDate = Format(dtMyDate, "MM/DD/YYYY")

Open in new window

The code
strRecord = strRecord & "," & Trim$(Replace(tblEmployee.Extract(6, 1, 1), ",", "''")) 

Open in new window

in your last comment (39766725) seems to be using a function to get some data and concatenate it into a simple comma-separated string. It is hard to understand what that has to do with the question as originally posed.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question