473,386 Members | 1,821 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,386 software developers and data experts.

Date String Format issues converting from VB6 to VB 2005.NET

I am beginning to work with VB2005.NET and I'm getting some problems
with string formatting converting an application from VB6.

VB6 code:-

sTradeDate = Format(pArray(4,i Record), "mmddyy")

pArray is a variant array containing a date string at pArray(4,
iRecord) in the format "yyyy/mm/dd"

The format function call changes that value into an mmddyy string no
problem, which is what I need it to do.

After running the upgrade wizard I get a converted line like:-

TradeDate.Value = VB6.Format(pArray(4, Record), "mmddyy")

Which also works. Note the TradeDate value is converted to a
VB6.FixedLengthString by the wizard and the variant array pArray
becomes an object.

Trying manually to make this more fully VB.NET-like I tried:-

TradeDate.Value = pArray(4, Record).ToString("mmddyy")

but I get a "Conversion from string "mmddyy" to type 'Integer' is not
valid."

I rather suspect that I have mis-understood something here. Any
assistance would be most gratefully received.

Thanks a lot,
Brian
May 24 '07 #1
2 11107
You are absolutely correct. You have misunderstood something.

There is a breaking change from VB6 to VB.Net relating to date formatting
characters.

Where you used mm in VB6 for a 2 digit month you now need to use MM (upper
case). mm (lower case) now represents a 2 digit minute.

For example: DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")

You haven't mentioned what the data type of TradeDate is but because you are
attempting to assign a formatted value I will assume it is a string.

The String data type does not have a Value property so theres no point in
even thinking about attempting to assign something to that.

An assignment to a string is simply: <stringvariable= <string expression>

You need to ascertain exactly what is in pArray(4, Record). It won't be a
variant because we don't have those anymore. Instead it will be an Object
which, from what you say, may contain a string. To do this you can use:

MessageBox.Show(pArray(4, Record).GetType.ToString)

which will give you the data type.

If it is, in fact, a string, then to get the value out of it you can use:

CType(pArray(4, Record), String)

Assuming that it contains a string in yyyy/MM/dd format, then to convert it
to MMddyy format you need to convert it to a date and then reconvert it to a
string.

TradeDate = DateTime.ParseExact(CType(pArray(4, Record), String),
"yyyy/MM/dd", Nothing).ToString("MMddyy")

Another thing you need to do is make sure that you have both Option Explicit
and Option Strict turned on. Use of these will highlight many 'problem'
areas that might otherwise be hidden from you.
"Brian Parker" <bp*****@nemianlife.luwrote in message
news:6k********************************@4ax.com...
>I am beginning to work with VB2005.NET and I'm getting some problems
with string formatting converting an application from VB6.

VB6 code:-

sTradeDate = Format(pArray(4,i Record), "mmddyy")

pArray is a variant array containing a date string at pArray(4,
iRecord) in the format "yyyy/mm/dd"

The format function call changes that value into an mmddyy string no
problem, which is what I need it to do.

After running the upgrade wizard I get a converted line like:-

TradeDate.Value = VB6.Format(pArray(4, Record), "mmddyy")

Which also works. Note the TradeDate value is converted to a
VB6.FixedLengthString by the wizard and the variant array pArray
becomes an object.

Trying manually to make this more fully VB.NET-like I tried:-

TradeDate.Value = pArray(4, Record).ToString("mmddyy")

but I get a "Conversion from string "mmddyy" to type 'Integer' is not
valid."

I rather suspect that I have mis-understood something here. Any
assistance would be most gratefully received.

Thanks a lot,
Brian
May 24 '07 #2
On Fri, 25 May 2007 02:09:34 +1200, "Stephany Young" <noone@localhost>
wrote:

Thanks a lot for the quick and helpful reply.
>You are absolutely correct. You have misunderstood something.

There is a breaking change from VB6 to VB.Net relating to date formatting
characters.

Where you used mm in VB6 for a 2 digit month you now need to use MM (upper
case). mm (lower case) now represents a 2 digit minute.

For example: DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")
Thanks for that, my eye just read right over that one!
>
You haven't mentioned what the data type of TradeDate is but because you are
attempting to assign a formatted value I will assume it is a string.
Yes I did. 8-) I said this...
Note the TradeDate value is converted to a VB6.FixedLengthString by
the wizard and the variant array pArray blah blah

But you correctly assumed it was a string.
>
The String data type does not have a Value property so theres no point in
even thinking about attempting to assign something to that.
The conversion wizard puts the Value property in for all cases where
it has converted _fixed length strings_

Dim TradeDate As New VB6.FixedLengthString(6)
gets a .Value for assignment after the wizard.

I will move away from the VB6 fixed length strings when I figure out
what to replace them with, but at the moment it's how the fields are
organised to the correct columns in the program's output.
>You need to ascertain exactly what is in pArray(4, Record). It won't be a
variant because we don't have those anymore. Instead it will be an Object
which, from what you say, may contain a string. To do this you can use:

MessageBox.Show(pArray(4, Record).GetType.ToString)
Thanks - useful.
>Assuming that it contains a string in yyyy/MM/dd format, then to convert it
to MMddyy format you need to convert it to a date and then reconvert it to a
string.
Right. I think this was the core bit I was getting wrong.
>
TradeDate = DateTime.ParseExact(CType(pArray(4, Record), String),
"yyyy/MM/dd", Nothing).ToString("MMddyy")
I do think it's a pity when something simple like

sTradeDate = Format(pArray(4,i Record), "mmddyy")

ends up as

TradeDate = DateTime.ParseExact(CType(pArray(4, Record), String),
"yyyy/MM/dd", Nothing).ToString("MMddyy")

and that is progress. But that is whole other can of worms. 8-)
>
Another thing you need to do is make sure that you have both Option Explicit
and Option Strict turned on. Use of these will highlight many 'problem'
areas that might otherwise be hidden from you.
Thanks, strict was off. Catching a lot of stuff now.

Again many thanks for taking the time to help.
>

"Brian Parker" <bp*****@nemianlife.luwrote in message
news:6k********************************@4ax.com.. .
>>I am beginning to work with VB2005.NET and I'm getting some problems
with string formatting converting an application from VB6.

VB6 code:-

sTradeDate = Format(pArray(4,i Record), "mmddyy")

pArray is a variant array containing a date string at pArray(4,
iRecord) in the format "yyyy/mm/dd"

The format function call changes that value into an mmddyy string no
problem, which is what I need it to do.

After running the upgrade wizard I get a converted line like:-

TradeDate.Value = VB6.Format(pArray(4, Record), "mmddyy")

Which also works. Note the TradeDate value is converted to a
VB6.FixedLengthString by the wizard and the variant array pArray
becomes an object.

Trying manually to make this more fully VB.NET-like I tried:-

TradeDate.Value = pArray(4, Record).ToString("mmddyy")

but I get a "Conversion from string "mmddyy" to type 'Integer' is not
valid."

I rather suspect that I have mis-understood something here. Any
assistance would be most gratefully received.

Thanks a lot,
Brian
May 24 '07 #3

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

Similar topics

2
by: praba kar | last post by:
Dear All, In Php strtotime() will change a date string into timestamp. I want to know which python function will change a date string into timestamp. Date string format is below
2
by: ORC | last post by:
The string format of a com port when opening a port in win32 API is "COM1:" but how is it in VS 2005 in the System.IO.Ports.SerialPort.PortName property (with or without the ':' character) ? ...
10
by: Kim Hellan | last post by:
I have a simple string in the format "DD-MM-YY hh:mm:ss", that I need to convert to a DateTime value. I know this is a standard problem, but please don't just link to all the MSDN pages regarding...
50
by: z. f. | last post by:
HI, i have string in format dd/mm/yyyyy hh:mm:ss and giving this as an input to DateTime.Parse gives a string was not recognized as a valid date time format string error. how do i make the parse...
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
9
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i...
4
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form...
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
2
by: stainless | last post by:
I know this is probably simple but I cannot find a method of converting a date string into a format that matches the DatePicker format in C# eg string "20080131" converted to "31 January 2008" ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.