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 16 3901
"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
"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
"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
"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
"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
"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
"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
"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.
"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.
"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
"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
"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
"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
"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
"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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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"...
|
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...
|
by: hg |
last post by:
Hi,
Is there a clean way to figure out that a .exe was actually generated by
pyexe ?
hg
|
by: hd95 |
last post by:
vb6: what reference do I need for the "format" command?
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
| |