I know I can do this, I just don't know the best way.
If I create a form that asks for the date, the user enters the date,
then clicks ok. What is the BEST way to get that date back to the
calling form?
I want it so the calling form code is:
dim gldate as date
gldate=AskDate()
Thanks.
Darin
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
>What is the BEST way to get that date back to the
>calling form?
I would expose it as a property of the form class.
Public ReadOnly Property [Date] As Date
Get
Return YourDateTimePicker.Value
End Get
End Property
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
In your form, create a public function called AskDate, with a return value
of date.
Public Function AskDate() As Date
Me.ShowDialog()
Return YourDateTimePicker.Value
End Function
Then...
Dim fAskDate As New frmAskDate
Dim dtDate As Date = frmAskDate.AskDate()
--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup,
so all can benefit
"Darin" <darin_nospam@nospamever> wrote in message
news:uYKWLmNX...@TK2MSFTNGP10.phx.gbl...
"Darin" <darin_nospam@nospamever> schrieb:
> If I create a form that asks for the date, the user enters the date,
> then clicks ok. What is the BEST way to get that date back to the
> calling form?
\\\
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Vom Windows Form Designer generierter Code "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose( _
ByVal disposing As Boolean _
)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents btnOK As System.Windows.Forms.Button
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.btnCancel = New System.Windows.Forms.Button()
Me.btnOK = New System.Windows.Forms.Button()
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker()
Me.SuspendLayout()
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btnCancel.Location = New System.Drawing.Point(176, 144)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(80, 24)
Me.btnCancel.TabIndex = 0
Me.btnCancel.Text = "Cancel"
'
'btnOK
'
Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btnOK.Location = New System.Drawing.Point(88, 144)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(80, 24)
Me.btnOK.TabIndex = 1
Me.btnOK.Text = "OK"
'
'DateTimePicker1
'
Me.DateTimePicker1.Location = New System.Drawing.Point(16, 24)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(240, 20)
Me.DateTimePicker1.TabIndex = 2
'
'Form2
'
Me.AcceptButton = Me.btnOK
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing.Size(274, 184)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.DateTimePicker1,
Me.btnOK, Me.btnCancel})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form2"
Me.ShowInTaskbar = False
Me.Text = "Select date"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnOK_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles btnOK.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub
Private Sub btnCancel_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles btnCancel.Click
Me.DialogResult = DialogResult.Cancel
Me.Close()
End Sub
Public Property [Date]() As Date
Get
Return Me.DateTimePicker1.Value
End Get
Set(ByVal Value As Date)
Me.DateTimePicker1.Value = Value
End Set
End Property
End Class
///
Test call:
\\\
Private Sub Button1_Click(...) ...
Dim f As New Form2()
If f.ShowDialog(Me) = DialogResult.OK Then
MsgBox(f.Date.ToString())
Else
MsgBox("Cancelled")
End If
End Sub
///
HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet