Click here to Skip to main content
15,906,947 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: VB - Looping Pin
Richard MacCutchan22-Sep-16 20:38
mveRichard MacCutchan22-Sep-16 20:38 
GeneralRe: VB - Looping Pin
Jughead323-Sep-16 3:10
Jughead323-Sep-16 3:10 
GeneralRe: VB - Looping Pin
Richard MacCutchan23-Sep-16 3:55
mveRichard MacCutchan23-Sep-16 3:55 
GeneralRe: VB - Looping Pin
Jughead323-Sep-16 11:04
Jughead323-Sep-16 11:04 
GeneralRe: VB - Looping Pin
Richard MacCutchan23-Sep-16 22:43
mveRichard MacCutchan23-Sep-16 22:43 
QuestionUse date format in my program independently from System date format Pin
desanti20-Sep-16 9:34
desanti20-Sep-16 9:34 
AnswerRe: Use date format in my program independently from System date format Pin
Bernhard Hiller20-Sep-16 20:58
Bernhard Hiller20-Sep-16 20:58 
AnswerRe: Use date format in my program independently from System date format Pin
Richard Deeming21-Sep-16 3:01
mveRichard Deeming21-Sep-16 3:01 
This is why all VB.NET programs should be compiled with Option Strict On.

You're taking a DateTime, converting to a String, and then assigning that String to a DateTime value.

Without Option Strict, VB is attempting to convert that String back to a DateTime. But it has to make some assumptions, one of which is that the String represents a date formatted using the current culture settings - in this case, US-format dates.

If you turn on Option Strict, you will get a compiler error telling you that you cannot store a String in a DateTime variable.

You could use DateTime.Parse or DateTime.TryParse to try to convert the String back into a DateTime.

But it would be much simpler to just not convert the DateTime to a String in the first place!
VB.NET
Dim dt As DateTime = DateTime.Now 'NB: No "ToString" call here!

Remember, a DateTime value does not have a "format" stored with it. It is simply the number of ticks since midnight on 1st January 0001. You only use a format when you are displaying the value to the user, or parsing a user-supplied string back into a DateTime.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


QuestionProblem with connectionstrings Pin
desanti20-Sep-16 6:30
desanti20-Sep-16 6:30 
QuestionRe: Problem with connectionstrings Pin
Mathi Mani20-Sep-16 7:15
Mathi Mani20-Sep-16 7:15 
AnswerRe: Problem with connectionstrings Pin
ZurdoDev20-Sep-16 7:56
professionalZurdoDev20-Sep-16 7:56 
QuestionVisual Basic Pin
mariajohnson15-Sep-16 0:55
mariajohnson15-Sep-16 0:55 
QuestionRe: Visual Basic Pin
Richard MacCutchan15-Sep-16 1:42
mveRichard MacCutchan15-Sep-16 1:42 
AnswerRe: Visual Basic Pin
Tim Carmichael15-Sep-16 5:00
Tim Carmichael15-Sep-16 5:00 
QuestionVB6 app loses mojo - runs 3 times slower Pin
Dr Memory14-Sep-16 20:07
Dr Memory14-Sep-16 20:07 
AnswerRe: VB6 app loses mojo - runs 3 times slower Pin
Mycroft Holmes16-Sep-16 13:31
professionalMycroft Holmes16-Sep-16 13:31 
GeneralRe: VB6 app loses mojo - runs 3 times slower Pin
Dr Memory16-Sep-16 19:22
Dr Memory16-Sep-16 19:22 
GeneralRe: VB6 app loses mojo - runs 3 times slower Pin
Dave Kreskowiak17-Sep-16 4:00
mveDave Kreskowiak17-Sep-16 4:00 
GeneralRe: VB6 app loses mojo - runs 3 times slower Pin
Mycroft Holmes17-Sep-16 11:16
professionalMycroft Holmes17-Sep-16 11:16 
RantRe: VB6 app loses mojo - runs 3 times slower Pin
Dr Memory17-Sep-16 11:40
Dr Memory17-Sep-16 11:40 
GeneralRe: VB6 app loses mojo - runs 3 times slower Pin
Eddy Vluggen18-Sep-16 0:57
professionalEddy Vluggen18-Sep-16 0:57 
AnswerRecord not Display in Datagridview1 Pin
Computechsoft14-Sep-16 5:03
Computechsoft14-Sep-16 5:03 
QuestionPanel in a Form loses contents Pin
Hurricane300011-Sep-16 7:57
Hurricane300011-Sep-16 7:57 
AnswerRe: Panel in a Form loses contents Pin
Eddy Vluggen11-Sep-16 10:09
professionalEddy Vluggen11-Sep-16 10:09 
GeneralRe: Panel in a Form loses contents Pin
Hurricane300011-Sep-16 10:45
Hurricane300011-Sep-16 10:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.