micropathic Posted November 25, 2003 Posted November 25, 2003 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) Quote
Moderators Robby Posted November 25, 2003 Moderators Posted November 25, 2003 try something like this Dim MyString as string MyString = Now.AddDays(30).ToShortDateString daytrialends = MyString Quote Visit...Bassic Software
micropathic Posted November 25, 2003 Author Posted November 25, 2003 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! Quote
Leaders Iceplug Posted November 25, 2003 Leaders Posted November 25, 2003 Did you convert the DateDiff function? DateDiff(Microsoft.VisualBasic.DateInterval.Day, Today, daytrialends).ToShortDateString ? :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Moderators Robby Posted November 25, 2003 Moderators Posted November 25, 2003 I didn't correct that line.... ALSO, at the top of all your code pages place these line of code... Option Explicit On Option Strict On Dim MyDate As Date MyDate = Now.AddDays(30) lblDaysLeft.Text = "Days Left Until Trial Expires: " & DateDiff(DateInterval.Day, Now.Today, MyDate) Quote Visit...Bassic Software
Moderators Robby Posted November 25, 2003 Moderators Posted November 25, 2003 DateDiff() expects a Date not a String, that's why you need to use Option Strict Quote Visit...Bassic Software
micropathic Posted November 25, 2003 Author Posted November 25, 2003 That worked, thanks so much!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.