.Net newbie - help w/ Date

micropathic

Regular
Joined
Oct 23, 2003
Messages
75
I am new to .Net. This is my first project, which is upgrading an app I had working in VB6. My question is about how to make the following code work in VB .Net given that the upgrade wizard wasn't able to do it automatically and I have not been able to figure it out by searching the forum. Any help would be GREATLY APPRECIATED!!!

Code:



Dim MyString as string

MyString = CStr(System.DateTime.FromOADate(Today.ToOADate + 30))

daytrialends = MyString


'****************************************
'UPGRADE_WARNING: Couldn't resolve default property of object daytrialends. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
'****************************************

lblDaysLeft.Text = "Days Left Until Trial Expires: " & DateDiff(Microsoft.VisualBasic.DateInterval.Day, Today, daytrialends)
 
try something like this

Visual Basic:
Dim MyString as string

MyString = Now.AddDays(30).ToShortDateString

daytrialends = MyString
 
Not sure what it is, but even w/ that code it's still throwing this at me:


An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

Additional information: Cast from string "" to type 'Date' is not valid.


And then it "marks" the line:

lblDaysLeft.Text = "Days Left Until Trial Expires: " & DateDiff(Microsoft.VisualBasic.DateInterval.Day, Today, daytrialends)


Thanks for your help!
 
I didn't correct that line....
ALSO, at the top of all your code pages place these line of code...
Visual Basic:
Option Explicit On
Option Strict On
Visual Basic:
Dim MyDate As Date

MyDate = Now.AddDays(30)
lblDaysLeft.Text = "Days Left Until Trial Expires: " & DateDiff(DateInterval.Day, Now.Today, MyDate)
 
Back
Top