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.visua lbasic.strings. format with a format string of "##/##/##" or "00/00/00" I get the format string in the
TextBox. If I use the microsoft.visua lbasic.compatib ility.vb6.forma t it works as I expect.
What Am I missing here? I would prefer not to use the VB6 compatibility.
TIA,
--
Al Reid 16 4016
"Al Reid" <ar*****@reidDA SHhome.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.visua lbasic.strings. format with a format string of "##/##/##" or "00/00/00" I get the format string in the TextBox. If I use the microsoft.visua lbasic.compatib ility.vb6.forma t 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*******@free net.de> wrote in message news:ez******** ******@TK2MSFTN GP10.phx.gbl... "Al Reid" <ar*****@reidDA SHhome.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.visua lbasic.strings. format with a format string of "##/##/##" or "00/00/00" I get the format string in the TextBox. If I use the microsoft.visua lbasic.compatib ility.vb6.forma t 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*****@reidDA SHhome.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*******@free net.de> wrote in message news:OS******** *****@TK2MSFTNG P14.phx.gbl... "Al Reid" <ar*****@reidDA SHhome.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*****@reidDA SHhome.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*******@free net.de> wrote in message news:OK******** ******@TK2MSFTN GP14.phx.gbl... "Al Reid" <ar*****@reidDA SHhome.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*****@reidDA SHhome.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*****@reidDA SHhome.com> wrote in message
news:uh******** ******@TK2MSFTN GP09.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.visua lbasic.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.substr ing( 0, 2 ) _
& "/" & userDate.substr ing( 2, 2 ) _
& "/" & userDate.substr ing( 4, 2 )
HTH,
Phill W.
"Armin Zingler" <az*******@free net.de> wrote in message news:Ox******** ******@TK2MSFTN GP12.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.Visua lBasic.Strings. Format(CInt(str ingexpression), "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. 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 ran it, it failed
The codes are
using System
class Test
|
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 2011.0100 or
2387.0000?
(simple question I know!)
|
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 on the value
that comes up in the tables record as "M" or "F".
I tried:
=Iff((!)="M","Male","Female")
'the is form, is the textbox name
|
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" (With seconds listed in
the report field).
However, nobody wants to see the seconds. So I tried to format it
=Format(DateCollected, "mm/dd/yy hh:nn AM/PM").
Works great, right? Well.. yeah for the most part. However if we
|
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 date from Table 1 into
| |
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: 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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |