.Net newbie - help w/ Date

micropathic

Well-known member
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 wasnt 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: Couldnt 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

Code:
Dim MyString as string

MyString = Now.AddDays(30).ToShortDateString

daytrialends = MyString
 
Not sure what it is, but even w/ that code its 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 didnt correct that line....
ALSO, at the top of all your code pages place these line of code...
Code:
Option Explicit On
Option Strict On
Code:
Dim MyDate As Date

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