2 easy questions

G

Guest

Question 1
I have two forms, let say Form1 and Form2. There is datetimepicker control
on Form2. In the Load Event of Form2 I have set the default value of
datetimepicker control to NOW. So as expected when I open the form the
default value is set to today's date. Now I sometimes also call Form2 from
Form1. Ok now here is my problem. Actually when I call Form2 from within
Form1 I want to set the set the value of datetimepicker control to something
else. I have written following code to call form2 from form1 and setting the
value of datetimepicker control:

Dim frm As Form2
frm = New Form2
frm.dtbDOB.value = "1 / 1 / 2005"
frm.showdialog()

I know this is happeneing because when I call form2 from form1, even though
I am setting the value of dtbDOB control but it is overwritten by the value
set in Load Event.

What should I do ?

Question 2
What is the purpose of Text property of DateTimePicker Control ?

Question 3.
How come I don't see the Text property in the properties window, however
when I create an instanace of an form and if that form has datetimepicker
control then I can the Text property

frm.dtpDOB.Text

Thanks in advance.
 
G

Guest

Question 3.

What do we do when the user don't want to set any date and the control is
datetimepicker. How do you set null value in this case because if we use
datetimepicker control we are requried to choose the date.
 
P

Peter Proost

patang said:
Question 1
I have two forms, let say Form1 and Form2. There is datetimepicker control
on Form2. In the Load Event of Form2 I have set the default value of
datetimepicker control to NOW. So as expected when I open the form the
default value is set to today's date. Now I sometimes also call Form2 from
Form1. Ok now here is my problem. Actually when I call Form2 from within
Form1 I want to set the set the value of datetimepicker control to something
else. I have written following code to call form2 from form1 and setting the
value of datetimepicker control:

Dim frm As Form2
frm = New Form2
frm.dtbDOB.value = "1 / 1 / 2005"
frm.showdialog()

I know this is happeneing because when I call form2 from form1, even though
I am setting the value of dtbDOB control but it is overwritten by the value
set in Load Event.

What should I do ?

Question 2
What is the purpose of Text property of DateTimePicker Control ?

Question 3.
How come I don't see the Text property in the properties window, however
when I create an instanace of an form and if that form has datetimepicker
control then I can the Text property

frm.dtpDOB.Text

Thanks in advance.
 
P

Peter Proost

To answer your first question:
switch places

frm.showdialog()
frm.dtbDOB.value = "1 / 1 / 2005"

to answer question number 2:
try:
MsgBox(dtbDOB.Text)

to answer question number 3, in a datetimepicker control there always is a
date, you can't make it empty as far is I know.

hth Peter
 
L

Larry Lard

patang said:
Question 1
I have two forms, let say Form1 and Form2. There is datetimepicker control
on Form2. In the Load Event of Form2 I have set the default value of
datetimepicker control to NOW. So as expected when I open the form the
default value is set to today's date. Now I sometimes also call Form2 from
Form1. Ok now here is my problem. Actually when I call Form2 from within
Form1 I want to set the set the value of datetimepicker control to something
else. I have written following code to call form2 from form1 and setting the
value of datetimepicker control:

Dim frm As Form2
frm = New Form2
frm.dtbDOB.value = "1 / 1 / 2005"
frm.showdialog()

I know this is happeneing because when I call form2 from form1, even though
I am setting the value of dtbDOB control but it is overwritten by the value
set in Load Event.

What should I do ?

One suggestion:

In Form2 declarations:

Private InitialValue As Date = Now

In Form2_Load:

dtp.Value = InitialValue

In Form2:

Public Sub MyShowDialog(ByVal ShowValue As Date)
InitialValue = ShowValue
Me.ShowDialog()
End Sub

Then from elsewhere, if you have f2 As Form2, you can either

f2.ShowDialog() 'to get the default of Now
or
f2.MyShowDialog(SomeOtherDate()) 'to start with some other date

Question 2
What is the purpose of Text property of DateTimePicker Control ?
From the help:

The string returned by this property is equivalent to the Value
property with the appropriate formatting or custom formatting applied.
For example, if the Value property is set to 06/01/2001 12:00:00 AM
while the CustomFormat property is set to "dddd, MMMM dd, yyyy", the
Text property value is "Friday, June 01, 2001".

When setting this property, the string must be convertible to an
instance of the DateTime class. It is possible to define a custom
format that results in a string that cannot be converted to a valid
DateTime value. Because of this, the string returned from the Text
property might cause an error if it is passed back to the Text
property. If the string cannot be converted to a date/time value, the
DateTime class throws a FormatException.

Question 3.
How come I don't see the Text property in the properties window, however
when I create an instanace of an form and if that form has datetimepicker
control then I can the Text property

frm.dtpDOB.Text

The Text property of the DateTimePicker has its Browsable attribute set
to No. Which might not mean much to you: basically, when you (or in
this case Microsoft) create a control, you can set attributes of the
properties to determine things like, does it appear in the properties
window, what UI it displays in the properties window, what its default
should be, and so on. In this case, since the Text of a DTP is a purely
dervied value, it makes sense to hide it from the Properties window.
 
C

Crouchie1998

Basically Larry, you have just repeated what I said earlier. What was the
point of repeat posting? Please read the answers to the post before adding
the same info in future.

Crouchie1998
BA (HONS) MCP MCSE
 
L

Larry Lard

Crouchie1998 said:
Basically Larry, you have just repeated what I said earlier. What was the
point of repeat posting? Please read the answers to the post before adding
the same info in future.

Crouchie1998
BA (HONS) MCP MCSE

So many letters and yet such litle understanding of how Usenet works.

btw, the post to which I am replying is the only one by you in this
thread currently visible to me; therefore as far as *I* can tell, 'what
[you] said earlier' Is Nothing.
 
O

Oenone

Crouchie1998 said:
Basically Larry, you have just repeated what I said earlier. What was
the point of repeat posting? Please read the answers to the post
before adding the same info in future.

Your reply certainly hasn't made it to my news server, and checking Google
Groups, it hasn't made it there either. Are you sure you sent it?

For a group populated by people that are supposed to be helping one another,
I have found your replies to be unnecessary and rude on several occasions.
Posting to these groups is not a competition, there aren't prizes awarded to
the first person to respond.

I'm also not aware of you having been elected as the newsgroup police force.

Please try to be more tolerant of other people's messages. Everyone that
responds on here has invested their own personal time in a selfless attempt
to help someone else that has a problem. No one deserves to be met with your
opinionated judgements on whether or not their post was justified.
 
C

Crouchie1998

Larry,

I am using Outlook Express to post info. What about you? I see the results
as soon as they are posted. If you use the Internet way you can still press
the 'Refresh' button

BTW: Not only do I have the letters, but I have the experience to go with
them

Crouchie1998
BA (HONS) MCP MCSE
 
L

Larry Lard

Crouchie1998 said:
Larry,

I am using Outlook Express to post info. What about you? I see the results
as soon as they are posted. If you use the Internet way you can still press
the 'Refresh' button

It's not surprising that *you* see messages you post to *your* news
server immediately. However, not everyone is using *your* news server.
part of the news.newusers.questions faq:

(begin excerpt)
: Do all the messages travel to a central site and then all the sites
: that want it, pick it up there?

No, there is no "central" server on Usenet. A newsgroup article
propagates from one server to another, starting from the server where
it is first posted.

: Do all the messages travel to all the sites?

Ideally, all the article in a newsgroup travel to all sites (news
servers) that carry the newsgroup. This means that when you post an
article, the final result is tens of thousands of copies, all over the
world.

More specifically, when you post an article, it goes first to your
"local" news server (operated by your Internet service provider,
company, or school). Your server then sends copies of the article to
its "neighbors," that is, to servers with which it has agreed to
exchange articles. Those servers in turn send copies to *their*
neighbors. Eventually every server that carries the newsgroup has a
copy.

: In what order?

Most servers normally send articles to other servers more or less in
the order of arrival. This sequence can get scrambled for various
reasons, which is why you often see responses before the "original"
article arrives.
(end excerpt)

You might also enjoy
<http://members.fortunecity.com/nnqweb/nquote.html>
 
C

Chris Dunaway

This won't work

The showdialog method will not return until the form is closed. The
code above will set the date *after* the form is closed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top