473,883 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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.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
Nov 21 '05 #1
16 4031
"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

Nov 21 '05 #2
"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
Nov 21 '05 #3
"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

Nov 21 '05 #4
"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
Nov 21 '05 #5
"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

Nov 21 '05 #6
"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
Nov 21 '05 #7
"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

Nov 21 '05 #8
"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.
Nov 21 '05 #9
"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.
Nov 21 '05 #10

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

Similar topics

8
3360
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
5
2215
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!)
22
22385
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
8
4433
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
5
2175
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
4
2256
by: hg | last post by:
Hi, Is there a clean way to figure out that a .exe was actually generated by pyexe ? hg
3
4229
by: hd95 | last post by:
vb6: what reference do I need for the "format" command?
0
9943
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, 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...
0
9793
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,...
1
10858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10419
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7974
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 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...
0
7134
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();...
0
5804
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...
2
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3237
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 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...

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.