-
Oct 25th, 2018, 01:44 PM
#1
Thread Starter
Hyperactive Member
DateTimePicker Language and settings are changing!!
I have a DateTimePicker tool on my project form and it's all fine on my PC, but when trying to test it on other machines it's language and settings changes according to the PC running the program.
how to make sure it will be all the time English and Gregorian and will never be changed according to the PC language and calendar?
-
Oct 25th, 2018, 02:57 PM
#2
Re: DateTimePicker Language and settings are changing!!
Aaaah..... you don't. You respect the user's settings. Or you build your own control that completely ignores the user's settings and does its own thing.
-tg
-
Oct 25th, 2018, 05:15 PM
#3
Re: DateTimePicker Language and settings are changing!!
Letting it change as it does means that the user gets to see it in a way that is natural for them, so they will be comfortable with it - probably more comfortable than with what you want.
It doesn't need to a affect your code in any way (as long as you are using the .Value property rather than .Text), so is there really a reason to try to force it to be different?
-
Oct 25th, 2018, 06:26 PM
#4
Re: DateTimePicker Language and settings are changing!!
As si suggests, if you find that a user's system settings are affecting your code then the issue is probably with your code. Can you show us how you're using this DateTimePicker and explain how that's being affected by system settings?
-
Oct 26th, 2018, 01:52 AM
#5
Thread Starter
Hyperactive Member
Re: DateTimePicker Language and settings are changing!!
Originally Posted by techgnome
Aaaah..... you don't. You respect the user's settings. Or you build your own control that completely ignores the user's settings and does its own thing.
-tg
Originally Posted by si_the_geek
Letting it change as it does means that the user gets to see it in a way that is natural for them, so they will be comfortable with it - probably more comfortable than with what you want.
It doesn't need to a affect your code in any way (as long as you are using the .Value property rather than .Text), so is there really a reason to try to force it to be different?
Originally Posted by jmcilhinney
As si suggests, if you find that a user's system settings are affecting your code then the issue is probably with your code. Can you show us how you're using this DateTimePicker and explain how that's being affected by system settings?
Well,there is a good reason for that. Actually the program takes the (.Text) of the DateTimePicker and transfers it to an Excel sheet where there is an OFFICIAL form and the Date must be in English and Gregorian and there is a calculation for the Julian date too.
So I don't want to effect the user's settings but I want it to be in the official form to be printed as he/she sure wants it to be.
I think here is what I should do
Originally Posted by si_the_geek
It doesn't need to a affect your code in any way (as long as you are using the .Value property rather than .Text)
and here is the code i'm using with it:
Code:
With xlWorkSheet
'~~> Directly type the values that we want
.Range("B1").Value = ComboBox6.Text
.Range("B7").Value = DateTimePicker1.Text
.Range("B8").Value = DateTimePicker2.Text + " " + JDateN.Text
.Range("F8").Value = "PAGE " + ComboBox8.Text
.Range("j34").Value = SHOP_OFFICERTextBox.Text
.Range("y34").Value = SHOP_HEADTextBox.Text
.Range("E39").Value = PRODUCTION_OFFICERTextBox.Text
.Range("M39").Value = MANAGERTextBox.Text
.Range("X39").Value = DIRECTOR_SRFTextBox.Text
End With
So is it only the matter off taking the the value rather than the text?
-
Oct 26th, 2018, 02:00 AM
#6
Thread Starter
Hyperactive Member
Re: DateTimePicker Language and settings are changing!!
Some of the sittings
-
Oct 26th, 2018, 02:54 AM
#7
Re: DateTimePicker Language and settings are changing!!
Originally Posted by Joye
Well,there is a good reason for that. Actually the program takes the (.Text) of the DateTimePicker and transfers it to an Excel sheet
And that's where your code is worng.
Originally Posted by Joye
So is it only the matter off taking the the value rather than the text?
Yes. The Value property is type DateTime so it is unaffected by format. You should pretty much NEVER use the Text property of a DateTimePicker. If you want to set the date/time then you assign a DateTime to the Value property. How you get that DateTime is up to you. If you want to get the date/time entered by the user then you get a DateTime from the Value property. Every user should see what they expect to see in the control and be able to set it as they expect to set it. For instance, if I was to look at a DateTimePicker that contained the date for January 10, 2018 here in Australia then I should see "10/01/2018" while a person in America should see "1/10/2018". It's the same date in both cases but we each see what we expect to see. ALWAYS work with the Value property.
Once you have a DateTime, you can do what you want with it and what you do is nothing to do with the DateTimePicker. If you're working in a context that doesn't have a dedicated date data type, e.g. Excel, and you have to use text then it's a good idea to use an unambiguous format, e.g. "yyyy-MM-dd". That's how you normally represent dates in SQL Server Management Studio when writing SQL code, for instance. You can convert a DateTime to a String in whatever format you want by calling its ToString method and passing the appropriate format specifier. Again, that step has nothing to do with the DateTimePicker.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|