473,320 Members | 1,857 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.

"Format" Question

First, I'm using vb2005. I have a string that is read from a barcode reader into a TextBox. The string is 6 characters long and
represents a date (mmddyy). I want to display it to the user in a date format of "mm/dd/yy" For example the barcode contains
"112303" and I want to format it to display "11/23/03"

If I use the microsoft.visualbasic.strings.format with a format string of "##/##/##" or "00/00/00" I get the format string in the
TextBox. If I use the microsoft.visualbasic.compatibility.vb6.format it works as I expect.

What Am I missing here? I would prefer not to use the VB6 compatibility.

TIA,

--
Al Reid
Nov 21 '05 #1
16 3988
"Al Reid" <ar*****@reidDASHhome.com> schrieb
First, I'm using vb2005. I have a string that is read from a
barcode reader into a TextBox. The string is 6 characters long and
represents a date (mmddyy). I want to display it to the user in a
date format of "mm/dd/yy" For example the barcode contains "112303"
and I want to format it to display "11/23/03"

If I use the microsoft.visualbasic.strings.format with a format
string of "##/##/##" or "00/00/00" I get the format string in the
TextBox. If I use the
microsoft.visualbasic.compatibility.vb6.format it works as I expect.

What Am I missing here? I would prefer not to use the VB6
compatibility.


Convert it to a Date variable first. Internally always work with it. To
convert to a string, use it's ToString method.

dim s as string = "112303"
dim d as date

d = date.parseexact(s, "MMddyy", nothing)
textbox1.text = d.tostring("MM\/dd\/yy")
Armin

Nov 21 '05 #2
"Armin Zingler" <az*******@freenet.de> wrote in message news:ez**************@TK2MSFTNGP10.phx.gbl...
"Al Reid" <ar*****@reidDASHhome.com> schrieb
First, I'm using vb2005. I have a string that is read from a
barcode reader into a TextBox. The string is 6 characters long and
represents a date (mmddyy). I want to display it to the user in a
date format of "mm/dd/yy" For example the barcode contains "112303"
and I want to format it to display "11/23/03"

If I use the microsoft.visualbasic.strings.format with a format
string of "##/##/##" or "00/00/00" I get the format string in the
TextBox. If I use the
microsoft.visualbasic.compatibility.vb6.format it works as I expect.

What Am I missing here? I would prefer not to use the VB6
compatibility.


Convert it to a Date variable first. Internally always work with it. To
convert to a string, use it's ToString method.

dim s as string = "112303"
dim d as date

d = date.parseexact(s, "MMddyy", nothing)
textbox1.text = d.tostring("MM\/dd\/yy")
Armin


Thanks, but that doesn't answer the question about the two variations of the Format function. Do you know the correct format string
required to make the Strings.Format function work properly?

--
Al Reid
Nov 21 '05 #3
"Al Reid" <ar*****@reidDASHhome.com> schrieb

Thanks, but that doesn't answer the question about the two
variations of the Format function. Do you know the correct format
string required to make the Strings.Format function work properly?


No. They are just different:
http://msdn.microsoft.com/library/en...gesInVBNET.asp

Armin

Nov 21 '05 #4
"Armin Zingler" <az*******@freenet.de> wrote in message news:OS*************@TK2MSFTNGP14.phx.gbl...
"Al Reid" <ar*****@reidDASHhome.com> schrieb

Thanks, but that doesn't answer the question about the two
variations of the Format function. Do you know the correct format
string required to make the Strings.Format function work properly?


No. They are just different:
http://msdn.microsoft.com/library/en...gesInVBNET.asp

Armin


Ok, I see. I have to convert the string to a number (CInt in my case) before it will apply the specified numeric format string.

Thanks,

--

Al Reid
Nov 21 '05 #5
"Al Reid" <ar*****@reidDASHhome.com> schrieb

Ok, I see. I have to convert the string to a number (CInt in my
case) before it will apply the specified numeric format string.


Why not convert to Date (because it is Date)?
Armin

Nov 21 '05 #6
"Armin Zingler" <az*******@freenet.de> wrote in message news:OK**************@TK2MSFTNGP14.phx.gbl...
"Al Reid" <ar*****@reidDASHhome.com> schrieb

Ok, I see. I have to convert the string to a number (CInt in my
case) before it will apply the specified numeric format string.


Why not convert to Date (because it is Date)?
Armin


Because I don't want to keep converting it back and forth. The displayed format is what I need in this specific instance. I agree
that I could have just converted it to a date as you previously suggested, BUT I wanted to understand why he Strings.Format function
did not give the expected results. I now know why and I learned something and that was what I was after.

Thanks again!

--
Al Reid
Nov 21 '05 #7
"Al Reid" <ar*****@reidDASHhome.com> schrieb

Ok, I see. I have to convert the string to a number (CInt in my
case) before it will apply the specified numeric format string.
Why not convert to Date (because it is Date)?


Because I don't want to keep converting it back and forth.

I don't understand. If you use CInt, you also have to convert twice. First
from "112303" to Integer, then Format to a string. IMO, Integer isn't better
than Date (IMO it's even worse). Tomorrow, you might want to make
calculations with the day (add one week etc). You would have to change your
code again.

The
displayed format is what I need in this specific instance. I agree
that I could have just converted it to a date as you previously
suggested, BUT I wanted to understand why he Strings.Format function
did not give the expected results. I now know why and I learned
something and that was what I was after.


I see, but I still don't understand why you want to use Integer instead of
Date. :-)
Armin

Nov 21 '05 #8
"Al Reid" <ar*****@reidDASHhome.com> wrote in message
news:uh**************@TK2MSFTNGP09.phx.gbl...
I have a string that is read from a barcode reader into a TextBox. .. . . I want to display it to the user in a date format of "mm/dd/yy"
For example the barcode contains "112303" and I want to format
it to display "11/23/03"

If I use the microsoft.visualbasic.strings.format with a format string
of "##/##/##" or "00/00/00" I get the format string in the TextBox.


These formatting characters only work on /numeric/ values.
To "format" something that's /already/ a String, you can use "@",
as in :

Strings.Format( "123456", "@@/@@/@@" )

If you're /sure/ about the order the value will appear in, just slice
and dice it, as in

userDate = "120345"
cleanDate = userDate.substring( 0, 2 ) _
& "/" & userDate.substring( 2, 2 ) _
& "/" & userDate.substring( 4, 2 )

HTH,
Phill W.
Nov 21 '05 #9
"Armin Zingler" <az*******@freenet.de> wrote in message news:Ox**************@TK2MSFTNGP12.phx.gbl...

I don't understand. If you use CInt, you also have to convert twice. First
from "112303" to Integer, then Format to a string. IMO, Integer isn't better
than Date (IMO it's even worse). Tomorrow, you might want to make
calculations with the day (add one week etc). You would have to change your
code again.

The
displayed format is what I need in this specific instance. I agree
that I could have just converted it to a date as you previously
suggested, BUT I wanted to understand why he Strings.Format function
did not give the expected results. I now know why and I learned
something and that was what I was after.


I see, but I still don't understand why you want to use Integer instead of
Date. :-)
Armin


Armin,

I don't want to use the Integer, I want to use a formatted string, BUT to get that with the format function I needed to do this:

Microsoft.VisualBasic.Strings.Format(CInt(stringex pression),"00/00/00") in order to get the correct formatting. Sure, I could
have easily followed your advice and never understood why the format function did not work as expected, but instead I took the time
to understand it.

This is not the correct forum to discuss the details of my application and I wouldn't expect you to understand the details of what I
need to do with the decoded barcode data.

BTW, I've been programming for 25 years in many different languages and I am also a MCSD. I know what I need to do for my
application. I am new to VB.Net and now have learned more about the product and that's a good thing<g>. Given what I now Know
about the Strings.Format function, along with other formatting options, I'll choose the implementation that is most suitable for my
specific application.

Again, thanks.
Nov 21 '05 #10
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message news:db*********@yarrow.open.ac.uk...
"Al Reid" <ar*****@reidDASHhome.com> wrote in message
news:uh**************@TK2MSFTNGP09.phx.gbl...
I have a string that is read from a barcode reader into a TextBox.

. . .
I want to display it to the user in a date format of "mm/dd/yy"
For example the barcode contains "112303" and I want to format
it to display "11/23/03"

If I use the microsoft.visualbasic.strings.format with a format string
of "##/##/##" or "00/00/00" I get the format string in the TextBox.


These formatting characters only work on /numeric/ values.
To "format" something that's /already/ a String, you can use "@",
as in :

Strings.Format( "123456", "@@/@@/@@" )

If you're /sure/ about the order the value will appear in, just slice
and dice it, as in

userDate = "120345"
cleanDate = userDate.substring( 0, 2 ) _
& "/" & userDate.substring( 2, 2 ) _
& "/" & userDate.substring( 4, 2 )

HTH,
Phill W.


Phil,

Thanks for the input. I just tried that and got "@@/@@/@@" as the function return value. Perhaps this is an issue with VB2005. I
should probably try it with 2003.

I am sure that the data extracted from the barcode will always be in that format. The user never enters the date, just validates
that the barcode was read correctly (the barcode label shows "11/23/03" while the extracted data is "112303"). I had thought of
building it myself, as you indicated, but I thought it would be easy enough to do with the Format function.

Thanks,

--
Al Reid
Nov 21 '05 #11
"Al Reid" <ar*****@reidDASHhome.com> schrieb
I don't want to use the Integer, I want to use a formatted string,
BUT to get that with the format function I needed to do this:

Microsoft.VisualBasic.Strings.Format(CInt(stringex pression),"00/00/00")
in order to get the correct formatting. Sure, I could have easily
followed your advice and never understood why the format function
did not work as expected, but instead I took the time to understand
it.


I did not say you should not understand it, but now that you understood it,
I was interested in why you still use your solution, not mine. You didn't
provide any reason why, thus I will not be able to understand it.
Armin

Nov 21 '05 #12
"Armin Zingler" <az*******@freenet.de> wrote in message news:eH*************@TK2MSFTNGP09.phx.gbl...
"Al Reid" <ar*****@reidDASHhome.com> schrieb
I don't want to use the Integer, I want to use a formatted string,
BUT to get that with the format function I needed to do this:

Microsoft.VisualBasic.Strings.Format(CInt(stringex pression),"00/00/00")
in order to get the correct formatting. Sure, I could have easily
followed your advice and never understood why the format function
did not work as expected, but instead I took the time to understand
it.


I did not say you should not understand it, but now that you understood it,
I was interested in why you still use your solution, not mine. You didn't
provide any reason why, thus I will not be able to understand it.
Armin


The existing COM component is expecting the barcode data to be passed in a specific format (I didn't write it and I'm not going to
modify it because it works). It is expecting the date to be passed as a string in the "mm/dd/yy" format. Therefore, I want to
convert it once to that format and use it that way up to the point of passing it to the COM object. At that point, I'm done with
it. I just don't see the need to convert it once to display it, then again to pass it to the object, rather that converting it once
and using it again when I need it.

--
Al Reid
Nov 21 '05 #13
"Al Reid" <ar*****@reidDASHhome.com> schrieb
The existing COM component is expecting the barcode data to be
passed in a specific format (I didn't write it and I'm not going to
modify it because it works). It is expecting the date to be passed
as a string in the "mm/dd/yy" format. Therefore, I want to convert
it once to that format and use it that way up to the point of
passing it to the COM object. At that point, I'm done with it. I
just don't see the need to convert it once to display it, then again
to pass it to the object, rather that converting it once and using
it again when I need it.

You misunderstand me, but enough of that.
Armin
Nov 21 '05 #14
"Armin Zingler" <az*******@freenet.de> wrote in message news:Op*************@TK2MSFTNGP14.phx.gbl...
"Al Reid" <ar*****@reidDASHhome.com> schrieb
The existing COM component is expecting the barcode data to be
passed in a specific format (I didn't write it and I'm not going to
modify it because it works). It is expecting the date to be passed
as a string in the "mm/dd/yy" format. Therefore, I want to convert
it once to that format and use it that way up to the point of
passing it to the COM object. At that point, I'm done with it. I
just don't see the need to convert it once to display it, then again
to pass it to the object, rather that converting it once and using
it again when I need it.

You misunderstand me, but enough of that.
Armin


Perhaps we are miscommunicating<g>

How's this:

txtDischDate.Text = Date.ParseExact(strDischDate, "MMddyy", Nothing).ToString("MM/dd/yy")

instead of the Format function?

--

Al Reid
Nov 21 '05 #15
"Al Reid" <ar*****@reidDASHhome.com> schrieb

You misunderstand me, but enough of that.
Perhaps we are miscommunicating<g>


Probably.
How's this:

txtDischDate.Text = Date.ParseExact(strDischDate, "MMddyy",
Nothing).ToString("MM/dd/yy")

instead of the Format function?

It's soooo great. :-) Now you have noticed that you don't have a reason for
your version. ;-) SCNR

But seriously, I was only curious why you insisted on your version.

I think it's time for EOT now, isn't it? :)
Aah, one hint: "MM/dd/yy" would be converted to "07.19.05" here. To keep the
"/" literally, you need "MM\/dd\/yy".
Armin

Nov 21 '05 #16
"Armin Zingler" <az*******@freenet.de> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...


It's soooo great. :-) Now you have noticed that you don't have a reason for
your version. ;-) SCNR

But seriously, I was only curious why you insisted on your version.

I think it's time for EOT now, isn't it? :)
Aah, one hint: "MM/dd/yy" would be converted to "07.19.05" here. To keep the
"/" literally, you need "MM\/dd\/yy".
Armin


I'm still learning the .Net Framework so I naturally gravitate toward familiar territory. I think the misunderstanding was that I
thought you were telling me to keep the date in a date variable and to convert it each time I used it. It finally dawned on me that
I could roll it all together, do it once and go about business.

I appreciate the heads up on the date format and I'll definitely keep that in mind. And I agree that we've hit EOT <g>

Thanks,

--
Al Reid
Nov 21 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Tony | last post by:
Hello I am learning C# and encountered the following problem when I tried to figure out how to print the string {0} in a Console window The following piece of codes complied OK. But when I...
5
by: Robin Tucker | last post by:
My database has a column for numeric data items. How can I use this number in the "format" command, such that for, say precision 2, I get numbers like 2011.01 or 2387.00 and for 4 I would get...
22
by: campbellbrian2001 | last post by:
Thanks in Advance! ... I have two textboxes: 1 is visible (and gets its value based on the invisible textbox and displays either "Male" or "Female", and needs to display either male of female based...
8
by: Ryan | last post by:
Hello, I'm new to Access and DB's in general. I've taken over some light duty support for a lab information system we use in house. Most of our dates are reported as "10/31/2006 12:30:00 PM"...
5
by: veaux | last post by:
I'm thinking this is easy but can't get it. I have a table with following: Table1 Date 1/1/2007 Table2 Type 0107 (This is MMYY of above) So I'm having trouble using a query to turn the...
4
by: hg | last post by:
Hi, Is there a clean way to figure out that a .exe was actually generated by pyexe ? hg
3
by: hd95 | last post by:
vb6: what reference do I need for the "format" command?
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: Shællîpôpï 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...

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.