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