views:

1981

answers:

4

I have a VB6 program that someone recently helped me convert to VB.NET

In the program, when saving files, I stamp them with the date which I was getting by calling the Today() function.

When I try to run the new VB.NET code in Vista it throws a permission exception for the Today() . If I run Visual Studio Express (this is the 2008 Express version) in Admin mode, then the problem doesn't occur, but clearly I want to end up with a stand-alone program which runs for all users without fancy permissions.

So how can a normal VB.NET program in Vista get today's date?

+8  A: 

Use DateTime.Now or DateTime.Today. These are entirely managed and shouldn't throw security exceptions.

The old VB6 functions, such as Len(), Left(), Right(), OpenFile(), FreeFile() are all present in the .NET Framework in the Microsoft.VisualBasic DLL. To maintain backwards compatibility, they all call the old functions in unmanaged code. Unmanaged code requires special security permissions because it can be dangerous.

Whenever possible, try and use the newer .NET functions. They are usually much faster (File IO using Streams for instance) and safer.

David Sokol
A: 

When I try the following statement:

Dim result As String = Today()

It gives me today's date, as I'd expect, and I'm running VB2005 on Vista. Can you modify the question with the version of VB you're using? Also, can you try the following statement instead of Today() to see it works for you without the exception?

Dim result As String = Now()
rwmnau
A: 

The Today() function should behave properly on Vista. I believe behind the scenes it is simply evaluating the DateTime.Today property, so it shouldn't throw any exceptions. If you're porting VB to VB.NET you should probably go ahead and use the DateTime.Today property rather than the VB6 compatability code.

Scott Dorman
A: 

I am new in programming a vb.net passion intended programmer. I had already install vb studio 2008 on vista OS platform but whenever i run simple program it would never run and keep popup error box. can somebody tell me what is the problem? is it the platform on which it is run or the compiler itself.

And if anyone knows where to download a working compiler I would be glad to appreciate him/ her

Xavier