0

I have 2 Forms.Form 1 is main and holds a button that should show msgbox with date that is selected on datetimepicker which is on Form 2. Date shown on msgbox should be in short format (dd.MM.yyyy.).

On program start datetimepicker should be reset to today and msgbox should show today date unless user selects another date on Form2. If user goes to From 2 and changes date Form 2 should save new value and msgbox should show it after button click on form1. How do i do this?

I made myDate parameter in settings of type "DATE" and i didn't set a value. on form1 load i have: my.Settings.myDate = Today

on Form2 load i have:

datetimepicker1.Value = my.Settings.myDate

on Form2 closing i have:

 my.Settings.myDate = datetimepicker1.Value

This sets date on picker correctly, but when i go to form2 and change value, then close form2 and reopen it it still shows date that i have chosen, but msgbox shows initial value.

Thank you

msosa
  • 5
  • 1
  • 4

1 Answers1

0

Change the line where you show the message box to:

MsgBox(my.Settings.myDate)

Or better yet, change it to the .NET way instead of the VB6 way:

MessageBox.Show(my.Settings.myDate.ToShortDateString())

The reason it's failing for you, I think, is because you are using the global Form2 reference to the form which may or may not be the same instance of the form that you are showing? It's hard to say without seeing more of your code.

Steven Doggart
  • 43,358
  • 8
  • 68
  • 105
  • Both work, but the second one you proposed also shows time (5.6.2012. 0.00.00) and i dont quite understand what you are saying in this explanation... both forms are created for them own. i dont know what is the instance of form. i am quite new to all this. – msosa Jun 05 '12 at 17:51
  • I updated it, try that. ToString allows you to specify any custom format that you want, but if all you want is the short date format, ToShortDateString is the best option. – Steven Doggart Jun 05 '12 at 17:54
  • btw, thank you very much... but i can't vote up... no rep yet :) – msosa Jun 05 '12 at 17:55
  • yes, ToShortDateString does the job as well. By the way is this kind of workaround, or i can use it as something solid in future. – msosa Jun 05 '12 at 17:58
  • ok thank you for your time. we can close it now. do i need to mark something as answered and where. this is my first time here. – msosa Jun 05 '12 at 18:00
  • Looks like you already have. I'm not totally sure because I haven't asked a question yet. – Steven Doggart Jun 05 '12 at 18:02