Home All Groups Group Topic Archive Search About

use variable as textbox name?

Author
23 May 2009 4:43 PM
Co
Hi All,

I use following code to update a textbox when a date has been chosen
from my MonthCalendar.
Since 6 textboxes use the same MonthCalendar I need to tell him which
textbox was used.
Therefore I have the variable: sWhichDateBox.
How can I use that string to become the name of a textbox:
SelectedTextBox.Text =
m_picker.SelectionRange.Start.Date.ToShortDateString()


Private Sub m_picker_DateChanged(ByVal sender As Object, _
    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged

        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
(m_picker.PointToClient(MousePosition))
        Dim SelectedTextBox As TextBox = Nothing
        SelectedTextBox.Name = sWhichDateBox
        'Display the Start and End property values of
        'the SelectionRange object in the text boxes.
        SelectedTextBox.Text =
m_picker.SelectionRange.Start.Date.ToShortDateString()
        SelectedTextBox.Text =
m_picker.SelectionRange.End.Date.ToShortDateString()

        'if we clicked on a date then hide the Calendar
        If hti.HitArea = MonthCalendar.HitArea.Date Then
            m_picker.Hide()
            SelectedTextBox.Parent.Controls.Remove(m_picker)
            m_picker = Nothing
            bCalOpened = False
        End If
    End Sub

Regards
Marco
The Netherlands

Author
23 May 2009 5:06 PM
Mike
Try using the user-defined Tag property for each text box.

--

Co wrote:
Show quoteHide quote
> Hi All,
>
> I use following code to update a textbox when a date has been chosen
> from my MonthCalendar.
> Since 6 textboxes use the same MonthCalendar I need to tell him which
> textbox was used.
> Therefore I have the variable: sWhichDateBox.
> How can I use that string to become the name of a textbox:
> SelectedTextBox.Text =
> m_picker.SelectionRange.Start.Date.ToShortDateString()
>
>
> Private Sub m_picker_DateChanged(ByVal sender As Object, _
>     ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>
>         Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
> (m_picker.PointToClient(MousePosition))
>         Dim SelectedTextBox As TextBox = Nothing
>         SelectedTextBox.Name = sWhichDateBox
>         'Display the Start and End property values of
>         'the SelectionRange object in the text boxes.
>         SelectedTextBox.Text =
> m_picker.SelectionRange.Start.Date.ToShortDateString()
>         SelectedTextBox.Text =
> m_picker.SelectionRange.End.Date.ToShortDateString()
>
>         'if we clicked on a date then hide the Calendar
>         If hti.HitArea = MonthCalendar.HitArea.Date Then
>             m_picker.Hide()
>             SelectedTextBox.Parent.Controls.Remove(m_picker)
>             m_picker = Nothing
>             bCalOpened = False
>         End If
>     End Sub
>
> Regards
> Marco
> The Netherlands
Author
23 May 2009 5:20 PM
Co
On 23 mei, 19:06, Mike <unkn***@unknown.tv> wrote:
Show quoteHide quote
> Try using the user-defined Tag property for each text box.
>
> --
>
> Co wrote:
> > Hi All,
>
> > I use following code to update a textbox when a date has been chosen
> > from my MonthCalendar.
> > Since 6 textboxes use the same MonthCalendar I need to tell him which
> > textbox was used.
> > Therefore I have the variable: sWhichDateBox.
> > How can I use that string to become the name of a textbox:
> > SelectedTextBox.Text =
> > m_picker.SelectionRange.Start.Date.ToShortDateString()
>
> > Private Sub m_picker_DateChanged(ByVal sender As Object, _
> >     ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>
> >         Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
> > (m_picker.PointToClient(MousePosition))
> >         Dim SelectedTextBox As TextBox = Nothing
> >         SelectedTextBox.Name = sWhichDateBox
> >         'Display the Start and End property values of
> >         'the SelectionRange object in the text boxes.
> >         SelectedTextBox.Text =
> > m_picker.SelectionRange.Start.Date.ToShortDateString()
> >         SelectedTextBox.Text =
> > m_picker.SelectionRange.End.Date.ToShortDateString()
>
> >         'if we clicked on a date then hide the Calendar
> >         If hti.HitArea = MonthCalendar.HitArea.Date Then
> >             m_picker.Hide()
> >             SelectedTextBox.Parent.Controls.Remove(m_picker)
> >             m_picker = Nothing
> >             bCalOpened = False
> >         End If
> >     End Sub
>
> > Regards
> > Marco
> > The Netherlands

I've been trying this:

        Dim textBoxNew As New TextBox
        textBoxNew.Name = "tbVerlooptTot"
        m_Controls.Add(textBoxNew.Name, textBoxNew)
        Dim textBoxNew2 As New TextBox
        textBoxNew2.Name = "tbVerlooptVan"
        m_Controls.Add(textBoxNew2.Name, textBoxNew2)
        Dim textBoxNew3 As New TextBox
        textBoxNew3.Name = "tbGemaaktTot"
        m_Controls.Add(textBoxNew3.Name, textBoxNew3)

Private Sub CreateDTP()

        Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox),
TextBox)
        bCalOpened = True
        m_picker = New MonthCalendar
        m_picker.BringToFront()
        m_picker.MaxSelectionCount = 1
        m_picker.Size = t.Size
        m_picker.BackColor = Color.Beige
        Me.Parent.Controls(0).Controls.Clear()
        Me.Parent.Controls(0).Controls.Add(m_picker)
        m_picker.BringToFront()
        m_picker.Select()

    End Sub

    Private Sub m_picker_DateChanged(ByVal sender As Object, _
    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged

        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
(m_picker.PointToClient(MousePosition))
        Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox),
TextBox)


        'Display the Start and End property values of
        'the SelectionRange object in the text boxes.
        t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString
()
        t.Text = m_picker.SelectionRange.End.Date.ToShortDateString()

        'if we clicked on a date then hide the Calendar
        If hti.HitArea = MonthCalendar.HitArea.Date Then
            m_picker.Hide()
            Me.Parent.Controls(0).Controls.Remove(m_picker)
            m_picker = Nothing
            bCalOpened = False
        End If
    End Sub

But I keep getting an error saying I should use the New instance.
"Object reference not set to an instance of an object"

Marco
Author
23 May 2009 7:49 PM
Mike
Maybe that isn't useful for you, but I thought I mention it. :-)

I was referring to the Tag property that is a persistent user-defined
element.

   Dim tb As TextBox
   tb = New TextBox : tb.Tag = "Tot" :  m_Controls.Add(tb.Tag, tb)
   tb = New TextBox : tb.Tag = "Van" :  m_Controls.Add(tb.Tag, tb)
   tb = New TextBox : tb.Tag = "Gemaakt" :  m_Controls.Add(tb.Tag, tb)

This is very useful for when the user-defined element is more complex,
  like a key or reference or pointer to some data associations to link
to some other controls.

--

Co wrote:
Show quoteHide quote
> On 23 mei, 19:06, Mike <unkn***@unknown.tv> wrote:
>> Try using the user-defined Tag property for each text box.
>>
>> --
>>
> I've been trying this:
>
>         Dim textBoxNew As New TextBox
>         textBoxNew.Name = "tbVerlooptTot"
>         m_Controls.Add(textBoxNew.Name, textBoxNew)
>         Dim textBoxNew2 As New TextBox
>         textBoxNew2.Name = "tbVerlooptVan"
>         m_Controls.Add(textBoxNew2.Name, textBoxNew2)
>         Dim textBoxNew3 As New TextBox
>         textBoxNew3.Name = "tbGemaaktTot"
>         m_Controls.Add(textBoxNew3.Name, textBoxNew3)
>
> Private Sub CreateDTP()
>
>         Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox),
> TextBox)
>         bCalOpened = True
>         m_picker = New MonthCalendar
>         m_picker.BringToFront()
>         m_picker.MaxSelectionCount = 1
>         m_picker.Size = t.Size
>         m_picker.BackColor = Color.Beige
>         Me.Parent.Controls(0).Controls.Clear()
>         Me.Parent.Controls(0).Controls.Add(m_picker)
>         m_picker.BringToFront()
>         m_picker.Select()
>
>     End Sub
>
>     Private Sub m_picker_DateChanged(ByVal sender As Object, _
>     ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>
>         Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
> (m_picker.PointToClient(MousePosition))
>         Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox),
> TextBox)
>
>
>         'Display the Start and End property values of
>         'the SelectionRange object in the text boxes.
>         t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString
> ()
>         t.Text = m_picker.SelectionRange.End.Date.ToShortDateString()
>
>         'if we clicked on a date then hide the Calendar
>         If hti.HitArea = MonthCalendar.HitArea.Date Then
>             m_picker.Hide()
>             Me.Parent.Controls(0).Controls.Remove(m_picker)
>             m_picker = Nothing
>             bCalOpened = False
>         End If
>     End Sub
>
> But I keep getting an error saying I should use the New instance.
> "Object reference not set to an instance of an object"
>
> Marco
Author
23 May 2009 8:18 PM
Jack Jackson
On Sat, 23 May 2009 10:20:09 -0700 (PDT), Co <vonclausow***@gmail.com>
wrote:

Show quoteHide quote
>On 23 mei, 19:06, Mike <unkn***@unknown.tv> wrote:
>> Try using the user-defined Tag property for each text box.
>>
>> --
>>
>> Co wrote:
>> > Hi All,
>>
>> > I use following code to update a textbox when a date has been chosen
>> > from my MonthCalendar.
>> > Since 6 textboxes use the same MonthCalendar I need to tell him which
>> > textbox was used.
>> > Therefore I have the variable: sWhichDateBox.
>> > How can I use that string to become the name of a textbox:
>> > SelectedTextBox.Text =
>> > m_picker.SelectionRange.Start.Date.ToShortDateString()
>>
>> > Private Sub m_picker_DateChanged(ByVal sender As Object, _
>> >     ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>>
>> >         Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
>> > (m_picker.PointToClient(MousePosition))
>> >         Dim SelectedTextBox As TextBox = Nothing
>> >         SelectedTextBox.Name = sWhichDateBox
>> >         'Display the Start and End property values of
>> >         'the SelectionRange object in the text boxes.
>> >         SelectedTextBox.Text =
>> > m_picker.SelectionRange.Start.Date.ToShortDateString()
>> >         SelectedTextBox.Text =
>> > m_picker.SelectionRange.End.Date.ToShortDateString()
>>
>> >         'if we clicked on a date then hide the Calendar
>> >         If hti.HitArea = MonthCalendar.HitArea.Date Then
>> >             m_picker.Hide()
>> >             SelectedTextBox.Parent.Controls.Remove(m_picker)
>> >             m_picker = Nothing
>> >             bCalOpened = False
>> >         End If
>> >     End Sub
>>
>> > Regards
>> > Marco
>> > The Netherlands
>
>I've been trying this:
>
>        Dim textBoxNew As New TextBox
>        textBoxNew.Name = "tbVerlooptTot"
>        m_Controls.Add(textBoxNew.Name, textBoxNew)
>        Dim textBoxNew2 As New TextBox
>        textBoxNew2.Name = "tbVerlooptVan"
>        m_Controls.Add(textBoxNew2.Name, textBoxNew2)
>        Dim textBoxNew3 As New TextBox
>        textBoxNew3.Name = "tbGemaaktTot"
>        m_Controls.Add(textBoxNew3.Name, textBoxNew3)
>
>Private Sub CreateDTP()
>
>        Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox),
>TextBox)
>        bCalOpened = True
>        m_picker = New MonthCalendar
>        m_picker.BringToFront()
>        m_picker.MaxSelectionCount = 1
>        m_picker.Size = t.Size
>        m_picker.BackColor = Color.Beige
>        Me.Parent.Controls(0).Controls.Clear()
>        Me.Parent.Controls(0).Controls.Add(m_picker)
>        m_picker.BringToFront()
>        m_picker.Select()
>
>    End Sub
>
>    Private Sub m_picker_DateChanged(ByVal sender As Object, _
>    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>
>        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
>(m_picker.PointToClient(MousePosition))
>        Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox),
>TextBox)
>
>
>        'Display the Start and End property values of
>        'the SelectionRange object in the text boxes.
>        t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString
>()
>        t.Text = m_picker.SelectionRange.End.Date.ToShortDateString()
>
>        'if we clicked on a date then hide the Calendar
>        If hti.HitArea = MonthCalendar.HitArea.Date Then
>            m_picker.Hide()
>            Me.Parent.Controls(0).Controls.Remove(m_picker)
>            m_picker = Nothing
>            bCalOpened = False
>        End If
>    End Sub
>
>But I keep getting an error saying I should use the New instance.
>"Object reference not set to an instance of an object"
>
>Marco

First, when you say you get an error, TELL US WHICH LINE GETS THE
ERROR.  Most people will read this post and ignore it, because it is
too much work to look through your lengthy code to try to figure out
which line might get that error.

My guess is that the error occurs on the second of these lines:

        Dim textBoxNew As New TextBox
        textBoxNew.Name = "tbVerlooptTot"

"Dim textBoxNew As New TextBox" does not create at TextBox object.  It
creates a variable named textBoxNew that contains Nothing.  You need
to create a TextBox object.

You need to do this:
        Dim textBoxNew As TextBox = New TextBox
        textBoxNew.Name = "tbVerlooptTot"
Author
26 May 2009 2:38 PM
Andrew Morton
Jack Jackson wrote:
> My guess is that the error occurs on the second of these lines:
>
>        Dim textBoxNew As New TextBox
>        textBoxNew.Name = "tbVerlooptTot"
>
> "Dim textBoxNew As New TextBox" does not create at TextBox object.

Oh yes it does: "Dim textBoxNew As New TextBox" is short for "Dim textBoxNew
As TextBox = New TextBox".

Andrew
Author
26 May 2009 11:15 PM
Jack Jackson
On Tue, 26 May 2009 15:38:05 +0100, "Andrew Morton"
<a**@in-press.co.uk.invalid> wrote:

>Jack Jackson wrote:
>> My guess is that the error occurs on the second of these lines:
>>
>>        Dim textBoxNew As New TextBox
>>        textBoxNew.Name = "tbVerlooptTot"
>>
>> "Dim textBoxNew As New TextBox" does not create at TextBox object.
>
>Oh yes it does: "Dim textBoxNew As New TextBox" is short for "Dim textBoxNew
>As TextBox = New TextBox".
>
>Andrew
>

My mistake.  I meant to say "Dim textBoxNew As TextBox".
Author
23 May 2009 5:12 PM
Armin Zingler
Co wrote:
> Hi All,
>
> I use following code to update a textbox when a date has been chosen
> from my MonthCalendar.
> Since 6 textboxes use the same MonthCalendar I need to tell him which
> textbox was used.
> Therefore I have the variable: sWhichDateBox.

Is there a reason why you don't declare "WhichDateBox As Textbox"?


Armin
Author
23 May 2009 5:24 PM
Co
On 23 mei, 19:12, "Armin Zingler" <az.nos***@freenet.de> wrote:
> Co wrote:
> > Hi All,
>
> > I use following code to update a textbox when a date has been chosen
> > from my MonthCalendar.
> > Since 6 textboxes use the same MonthCalendar I need to tell him which
> > textbox was used.
> > Therefore I have the variable: sWhichDateBox.
>
> Is there a reason why you don't declare "WhichDateBox As Textbox"?
>
> Armin

That didn't work either.
Author
23 May 2009 6:32 PM
Armin Zingler
Co wrote:
>>
>>> I use following code to update a textbox when a date has been chosen
>>> from my MonthCalendar.
>>> Since 6 textboxes use the same MonthCalendar I need to tell him
>>> which textbox was used.
>>> Therefore I have the variable: sWhichDateBox.
>>
>> Is there a reason why you don't declare "WhichDateBox As Textbox"?
>>
>> Armin
>
> That didn't work either.

What does not work? What did you try?  More information, please.


Armin
Author
23 May 2009 6:43 PM
Co
Show quote Hide quote
On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote:
> Co wrote:
>
> >>> I use following code to update a textbox when a date has been chosen
> >>> from my MonthCalendar.
> >>> Since 6 textboxes use the same MonthCalendar I need to tell him
> >>> which textbox was used.
> >>> Therefore I have the variable: sWhichDateBox.
>
> >> Is there a reason why you don't declare "WhichDateBox As Textbox"?
>
> >> Armin
>
> > That didn't work either.
>
> What does not work? What did you try?  More information, please.
>
> Armin

I can only create a New textbox.
That will bring up a new textbox on the form instead of using the
existing one.

Private Sub CreateDTP()

        Dim t As New TextBox
        t.Name = sDateBox
        't = DirectCast(m_Controls.Item(sDateBox), TextBox)
        bCalOpened = True
        m_picker = New MonthCalendar
        m_picker.BringToFront()
        m_picker.MaxSelectionCount = 1
        m_picker.Size = t.Size
        m_picker.BackColor = Color.Beige
        t.Parent = Me
        Me.Controls.Add(m_picker)
        m_picker.BringToFront()
        m_picker.Select()

    End Sub

    Private Sub m_picker_DateChanged(ByVal sender As Object, _
    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged

        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
(m_picker.PointToClient(MousePosition))
        Dim t As New TextBox
        'Dim t As TextBox = DirectCast(m_Controls.Item(iDateBox),
TextBox)

        'Display the Start and End property values of
        'the SelectionRange object in the text boxes.
        t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString
()
        t.Text = m_picker.SelectionRange.End.Date.ToShortDateString()

        'if we clicked on a date then hide the Calendar
        If hti.HitArea = MonthCalendar.HitArea.Date Then
            m_picker.Hide()
            Me.Controls.Remove(m_picker)
            m_picker = Nothing
            bCalOpened = False
            t.Dispose()
        End If
    End Sub

Marco
Author
23 May 2009 8:00 PM
Armin Zingler
Co wrote:
Show quoteHide quote
> On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote:
>> Co wrote:
>>
>>>>> I use following code to update a textbox when a date has been
>>>>> chosen from my MonthCalendar.
>>>>> Since 6 textboxes use the same MonthCalendar I need to tell him
>>>>> which textbox was used.
>>>>> Therefore I have the variable: sWhichDateBox.
>>
>>>> Is there a reason why you don't declare "WhichDateBox As Textbox"?
>>
>>>> Armin
>>
>>> That didn't work either.
>>
>> What does not work? What did you try? More information, please.
>>
>> Armin
>
> I can only create a New textbox.
> That will bring up a new textbox on the form instead of using the
> existing one.

You did not really read my post, did you? I asked why you don't declare
"WhichDateBox As Textbox". Now you removed it completely.


Armin
Author
23 May 2009 8:53 PM
Co
Show quote Hide quote
On 23 mei, 22:00, "Armin Zingler" <az.nos***@freenet.de> wrote:
> Co wrote:
> > On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote:
> >> Co wrote:
>
> >>>>> I use following code to update a textbox when a date has been
> >>>>> chosen from my MonthCalendar.
> >>>>> Since 6 textboxes use the same MonthCalendar I need to tell him
> >>>>> which textbox was used.
> >>>>> Therefore I have the variable: sWhichDateBox.
>
> >>>> Is there a reason why you don't declare "WhichDateBox As Textbox"?
>
> >>>> Armin
>
> >>> That didn't work either.
>
> >> What does not work? What did you try? More information, please.
>
> >> Armin
>
> > I can only create a New textbox.
> > That will bring up a new textbox on the form instead of using the
> > existing one.
>
> You did not really read my post, did you? I asked why you don't declare
> "WhichDateBox As Textbox". Now you removed it completely.
>
> Armin

I didn't remove it just renamed it:
Dim sDateBox As TextBox

Marco
Author
24 May 2009 12:27 AM
Armin Zingler
Co wrote:
Show quoteHide quote
> On 23 mei, 22:00, "Armin Zingler" <az.nos***@freenet.de> wrote:
>> Co wrote:
>>> On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote:
>>>> Co wrote:
>>
>>>>>>> I use following code to update a textbox when a date has been
>>>>>>> chosen from my MonthCalendar.
>>>>>>> Since 6 textboxes use the same MonthCalendar I need to tell him
>>>>>>> which textbox was used.
>>>>>>> Therefore I have the variable: sWhichDateBox.
>>
>>>>>> Is there a reason why you don't declare "WhichDateBox As
>>>>>> Textbox"?
>>
>>>>>> Armin
>>
>>>>> That didn't work either.
>>
>>>> What does not work? What did you try? More information, please.
>>
>>>> Armin
>>
>>> I can only create a New textbox.
>>> That will bring up a new textbox on the form instead of using the
>>> existing one.
>>
>> You did not really read my post, did you? I asked why you don't
>> declare "WhichDateBox As Textbox". Now you removed it completely.
>>
>> Armin
>
> I didn't remove it just renamed it:
> Dim sDateBox As TextBox


Yes, but in your first post you were referring to 'sWhichDateBox'. It is not
a local variable. Therefore I had to assume it is declared at class level. I
don't see it in your latest code. In Sub CreateDTP, you use 'sDateBox' now.
I can not see where it is declared - probably a field in the class - and
which value you assign.

Anyway, if sDateBox is the Textbox in question, I don't know why you create
a new Textbox instead of just using sDateBox.


Armin
Author
24 May 2009 8:57 AM
Co
Show quote Hide quote
On 24 mei, 02:27, "Armin Zingler" <az.nos***@freenet.de> wrote:
> Co wrote:
> > On 23 mei, 22:00, "Armin Zingler" <az.nos***@freenet.de> wrote:
> >> Co wrote:
> >>> On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote:
> >>>> Co wrote:
>
> >>>>>>> I use following code to update a textbox when a date has been
> >>>>>>> chosen from my MonthCalendar.
> >>>>>>> Since 6 textboxes use the same MonthCalendar I need to tell him
> >>>>>>> which textbox was used.
> >>>>>>> Therefore I have the variable: sWhichDateBox.
>
> >>>>>> Is there a reason why you don't declare "WhichDateBox As
> >>>>>> Textbox"?
>
> >>>>>> Armin
>
> >>>>> That didn't work either.
>
> >>>> What does not work? What did you try? More information, please.
>
> >>>> Armin
>
> >>> I can only create a New textbox.
> >>> That will bring up a new textbox on the form instead of using the
> >>> existing one.
>
> >> You did not really read my post, did you? I asked why you don't
> >> declare "WhichDateBox As Textbox". Now you removed it completely.
>
> >> Armin
>
> > I didn't remove it just renamed it:
> > Dim sDateBox As TextBox
>
> Yes, but in your first post you were referring to 'sWhichDateBox'. It is not
> a local variable. Therefore I had to assume it is declared at class level. I
> don't see it in your latest code. In Sub CreateDTP, you use 'sDateBox' now.
> I can not see where it is declared - probably a field in the class - and
> which value you assign.
>
> Anyway, if sDateBox is the Textbox in question, I don't know why you create
> a new Textbox instead of just using sDateBox.
>
> Armin

That's what I couldn't get done.
How would that look Armin?

Marco
Author
24 May 2009 10:18 AM
Armin Zingler
Co wrote:
Show quoteHide quote
> On 24 mei, 02:27, "Armin Zingler" <az.nos***@freenet.de> wrote:
>> Co wrote:
>>> On 23 mei, 22:00, "Armin Zingler" <az.nos***@freenet.de> wrote:
>>>> Co wrote:
>>>>> On 23 mei, 20:32, "Armin Zingler" <az.nos***@freenet.de> wrote:
>>>>>> Co wrote:
>>
>>>>>>>>> I use following code to update a textbox when a date has been
>>>>>>>>> chosen from my MonthCalendar.
>>>>>>>>> Since 6 textboxes use the same MonthCalendar I need to tell
>>>>>>>>> him which textbox was used.
>>>>>>>>> Therefore I have the variable: sWhichDateBox.
>>
>>>>>>>> Is there a reason why you don't declare "WhichDateBox As
>>>>>>>> Textbox"?
>>
>>>>>>>> Armin
>>
>>>>>>> That didn't work either.
>>
>>>>>> What does not work? What did you try? More information, please.
>>
>>>>>> Armin
>>
>>>>> I can only create a New textbox.
>>>>> That will bring up a new textbox on the form instead of using the
>>>>> existing one.
>>
>>>> You did not really read my post, did you? I asked why you don't
>>>> declare "WhichDateBox As Textbox". Now you removed it completely.
>>
>>>> Armin
>>
>>> I didn't remove it just renamed it:
>>> Dim sDateBox As TextBox
>>
>> Yes, but in your first post you were referring to 'sWhichDateBox'.
>> It is not a local variable. Therefore I had to assume it is declared
>> at class level. I don't see it in your latest code. In Sub
>> CreateDTP, you use 'sDateBox' now. I can not see where it is
>> declared - probably a field in the class - and which value you
>> assign.
>>
>> Anyway, if sDateBox is the Textbox in question, I don't know why you
>> create a new Textbox instead of just using sDateBox.
>>
>> Armin
>
> That's what I couldn't get done.
> How would that look Armin?

I don't know _what_ you couldn't get done. Could you please be a bit more
precise? :-)

Ok, back the start:
What I understood is that you have several textboxes. For which reason ever,
you want to assign the value from a DateTimePicker to one of the Textboxes.
First you want to memorize a certain Textbox in a variable. Later, in the
DTP's DateChanged event, you want to assign the value to the Textbox that
you've memorized in the variable. Is this correct? You first used a String
to store the name of the Textbox in question. I suggested to use a variable
of type Textbox instead. This enables you to directly use the variable
instead of finding the Textbox by a String. Therefore I currently don't know
what's the problem. By saying "just using sDateBox" I meant, well, just use
it like any other variable, for example in

    sDateBox.Text = m_picker.SelectionRange.Start.Date.ToShortDateString

I do not know when you intend to set variable 'sDateBox'. Maybe in the
Textbox' Enter or GotFocus event? I don't know. Is this the problem?



Armin
Author
23 May 2009 5:43 PM
Family Tree Mike
Show quote Hide quote
"Co" <vonclausow***@gmail.com> wrote in message
news:b333bfeb-e42a-4a05-a677-ead79316144d@z9g2000yqi.googlegroups.com...
> Hi All,
>
> I use following code to update a textbox when a date has been chosen
> from my MonthCalendar.
> Since 6 textboxes use the same MonthCalendar I need to tell him which
> textbox was used.
> Therefore I have the variable: sWhichDateBox.
> How can I use that string to become the name of a textbox:
> SelectedTextBox.Text =
> m_picker.SelectionRange.Start.Date.ToShortDateString()
>
>
> Private Sub m_picker_DateChanged(ByVal sender As Object, _
>    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>
>        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
> (m_picker.PointToClient(MousePosition))
>        Dim SelectedTextBox As TextBox = Nothing
>        SelectedTextBox.Name = sWhichDateBox
>        'Display the Start and End property values of
>        'the SelectionRange object in the text boxes.
>        SelectedTextBox.Text =
> m_picker.SelectionRange.Start.Date.ToShortDateString()
>        SelectedTextBox.Text =
> m_picker.SelectionRange.End.Date.ToShortDateString()
>
>        'if we clicked on a date then hide the Calendar
>        If hti.HitArea = MonthCalendar.HitArea.Date Then
>            m_picker.Hide()
>            SelectedTextBox.Parent.Controls.Remove(m_picker)
>            m_picker = Nothing
>            bCalOpened = False
>        End If
>    End Sub
>
> Regards
> Marco
> The Netherlands


It sounds to me like you have a datetime object that is being set or
displayed by the calander control as well as the six text boxes.  If this is
the case, why aren't all six text boxes just updated with the new datetime
from the calander?  Either you are making this too complicated or, more
likely, I'm over simplifying your issue.

--
Mike
Author
23 May 2009 5:59 PM
Co
Show quote Hide quote
On 23 mei, 19:43, "Family Tree Mike" <FamilyTreeM***@ThisOldHouse.com>
wrote:
> "Co" <vonclausow***@gmail.com> wrote in message
>
> news:b333bfeb-e42a-4a05-a677-ead79316144d@z9g2000yqi.googlegroups.com...
>
>
>
> > Hi All,
>
> > I use following code to update a textbox when a date has been chosen
> > from my MonthCalendar.
> > Since 6 textboxes use the same MonthCalendar I need to tell him which
> > textbox was used.
> > Therefore I have the variable: sWhichDateBox.
> > How can I use that string to become the name of a textbox:
> > SelectedTextBox.Text =
> > m_picker.SelectionRange.Start.Date.ToShortDateString()
>
> > Private Sub m_picker_DateChanged(ByVal sender As Object, _
> >    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>
> >        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
> > (m_picker.PointToClient(MousePosition))
> >        Dim SelectedTextBox As TextBox = Nothing
> >        SelectedTextBox.Name = sWhichDateBox
> >        'Display the Start and End property values of
> >        'the SelectionRange object in the text boxes.
> >        SelectedTextBox.Text =
> > m_picker.SelectionRange.Start.Date.ToShortDateString()
> >        SelectedTextBox.Text =
> > m_picker.SelectionRange.End.Date.ToShortDateString()
>
> >        'if we clicked on a date then hide the Calendar
> >        If hti.HitArea = MonthCalendar.HitArea.Date Then
> >            m_picker.Hide()
> >            SelectedTextBox.Parent.Controls.Remove(m_picker)
> >            m_picker = Nothing
> >            bCalOpened = False
> >        End If
> >    End Sub
>
> > Regards
> > Marco
> > The Netherlands
>
> It sounds to me like you have a datetime object that is being set or
> displayed by the calander control as well as the six text boxes.  If this is
> the case, why aren't all six text boxes just updated with the new datetime
> from the calander?  Either you are making this too complicated or, more
> likely, I'm over simplifying your issue.
>
> --
> Mike

It's a search form with six textboxes holding dates.
All can have different values.

Marco
Author
23 May 2009 7:29 PM
Cor Ligthert[MVP]
Marco,

You can set the name of a textbox to another name, however that does not
change the reference to that texbox object.

In other words, you don't make it dynamic like that.
When you want to use it a little bit more dynamic then look at that samples
I have given you some time ago but it did not fit you then (it was for
another reason)

Dim TextBoxes as Textbox() = {Textbox1,Textbo2 tot 6 }

Now you can use it dynamically by just using the TextBoxes with its number
from 0 to 5

Cor


Show quoteHide quote
"Co" <vonclausow***@gmail.com> wrote in message
news:b333bfeb-e42a-4a05-a677-ead79316144d@z9g2000yqi.googlegroups.com...
> Hi All,
>
> I use following code to update a textbox when a date has been chosen
> from my MonthCalendar.
> Since 6 textboxes use the same MonthCalendar I need to tell him which
> textbox was used.
> Therefore I have the variable: sWhichDateBox.
> How can I use that string to become the name of a textbox:
> SelectedTextBox.Text =
> m_picker.SelectionRange.Start.Date.ToShortDateString()
>
>
> Private Sub m_picker_DateChanged(ByVal sender As Object, _
>    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>
>        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
> (m_picker.PointToClient(MousePosition))
>        Dim SelectedTextBox As TextBox = Nothing
>        SelectedTextBox.Name = sWhichDateBox
>        'Display the Start and End property values of
>        'the SelectionRange object in the text boxes.
>        SelectedTextBox.Text =
> m_picker.SelectionRange.Start.Date.ToShortDateString()
>        SelectedTextBox.Text =
> m_picker.SelectionRange.End.Date.ToShortDateString()
>
>        'if we clicked on a date then hide the Calendar
>        If hti.HitArea = MonthCalendar.HitArea.Date Then
>            m_picker.Hide()
>            SelectedTextBox.Parent.Controls.Remove(m_picker)
>            m_picker = Nothing
>            bCalOpened = False
>        End If
>    End Sub
>
> Regards
> Marco
> The Netherlands
Author
23 May 2009 7:36 PM
Co
Show quote Hide quote
On 23 mei, 21:29, "Cor Ligthert[MVP]" <Notmyfirstn***@planet.nl>
wrote:
> Marco,
>
> You can set the name of a textbox to another name, however that does not
> change the reference to that texbox object.
>
> In other words, you don't make it dynamic like that.
> When you want to use it a little bit more dynamic then look at that samples
> I have given you some time ago but it did not fit you then (it was for
> another reason)
>
> Dim TextBoxes as Textbox() = {Textbox1,Textbo2 tot 6 }
>
> Now you can use it dynamically by just using the TextBoxes with its number
> from 0 to 5
>
> Cor
>
> "Co" <vonclausow***@gmail.com> wrote in message
>
> news:b333bfeb-e42a-4a05-a677-ead79316144d@z9g2000yqi.googlegroups.com...
>
> > Hi All,
>
> > I use following code to update a textbox when a date has been chosen
> > from my MonthCalendar.
> > Since 6 textboxes use the same MonthCalendar I need to tell him which
> > textbox was used.
> > Therefore I have the variable: sWhichDateBox.
> > How can I use that string to become the name of a textbox:
> > SelectedTextBox.Text =
> > m_picker.SelectionRange.Start.Date.ToShortDateString()
>
> > Private Sub m_picker_DateChanged(ByVal sender As Object, _
> >    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>
> >        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
> > (m_picker.PointToClient(MousePosition))
> >        Dim SelectedTextBox As TextBox = Nothing
> >        SelectedTextBox.Name = sWhichDateBox
> >        'Display the Start and End property values of
> >        'the SelectionRange object in the text boxes.
> >        SelectedTextBox.Text =
> > m_picker.SelectionRange.Start.Date.ToShortDateString()
> >        SelectedTextBox.Text =
> > m_picker.SelectionRange.End.Date.ToShortDateString()
>
> >        'if we clicked on a date then hide the Calendar
> >        If hti.HitArea = MonthCalendar.HitArea.Date Then
> >            m_picker.Hide()
> >            SelectedTextBox.Parent.Controls.Remove(m_picker)
> >            m_picker = Nothing
> >            bCalOpened = False
> >        End If
> >    End Sub
>
> > Regards
> > Marco
> > The Netherlands

I worked it out.

Dim sDateBox As TextBox

Private Sub tbVerlooptTot_DoubleClick(ByVal sender As Object, ByVal e
As System.EventArgs) Handles tbVerlooptTot.DoubleClick
        If bCalOpened = False Then
            sDateBox = tbVerlooptTot
            CreateDTP()
        End If

Private Sub CreateDTP()

        bCalOpened = True
        m_picker = New MonthCalendar
        m_picker.BringToFront()
        m_picker.MaxSelectionCount = 1
        m_picker.Size = tbVerlooptTot.Size
        m_picker.BackColor = Color.Beige
        tbVerlooptTot.Parent = Me
        Me.Controls.Add(m_picker)
        m_picker.BringToFront()
        m_picker.Select()

    End Sub

    Private Sub m_picker_DateChanged(ByVal sender As Object, _
    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged

        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
(m_picker.PointToClient(MousePosition))
        Dim t As TextBox = DirectCast(sDateBox, TextBox)

        'Display the Start and End property values of
        'the SelectionRange object in the text boxes.
        t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString
()
        t.Text = m_picker.SelectionRange.End.Date.ToShortDateString()

        'if we clicked on a date then hide the Calendar
        If hti.HitArea = MonthCalendar.HitArea.Date Then
            m_picker.Hide()
            Me.Controls.Remove(m_picker)
            m_picker = Nothing
            bCalOpened = False
        End If
    End Sub

Thanks for helping me in the right direction.

Marco
Author
23 May 2009 8:28 PM
Jack Jackson
On Sat, 23 May 2009 12:36:36 -0700 (PDT), Co <vonclausow***@gmail.com>
wrote:

Show quoteHide quote
>On 23 mei, 21:29, "Cor Ligthert[MVP]" <Notmyfirstn***@planet.nl>
>wrote:
>> Marco,
>>
>> You can set the name of a textbox to another name, however that does not
>> change the reference to that texbox object.
>>
>> In other words, you don't make it dynamic like that.
>> When you want to use it a little bit more dynamic then look at that samples
>> I have given you some time ago but it did not fit you then (it was for
>> another reason)
>>
>> Dim TextBoxes as Textbox() = {Textbox1,Textbo2 tot 6 }
>>
>> Now you can use it dynamically by just using the TextBoxes with its number
>> from 0 to 5
>>
>> Cor
>>
>> "Co" <vonclausow***@gmail.com> wrote in message
>>
>> news:b333bfeb-e42a-4a05-a677-ead79316144d@z9g2000yqi.googlegroups.com...
>>
>> > Hi All,
>>
>> > I use following code to update a textbox when a date has been chosen
>> > from my MonthCalendar.
>> > Since 6 textboxes use the same MonthCalendar I need to tell him which
>> > textbox was used.
>> > Therefore I have the variable: sWhichDateBox.
>> > How can I use that string to become the name of a textbox:
>> > SelectedTextBox.Text =
>> > m_picker.SelectionRange.Start.Date.ToShortDateString()
>>
>> > Private Sub m_picker_DateChanged(ByVal sender As Object, _
>> >    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>>
>> >        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
>> > (m_picker.PointToClient(MousePosition))
>> >        Dim SelectedTextBox As TextBox = Nothing
>> >        SelectedTextBox.Name = sWhichDateBox
>> >        'Display the Start and End property values of
>> >        'the SelectionRange object in the text boxes.
>> >        SelectedTextBox.Text =
>> > m_picker.SelectionRange.Start.Date.ToShortDateString()
>> >        SelectedTextBox.Text =
>> > m_picker.SelectionRange.End.Date.ToShortDateString()
>>
>> >        'if we clicked on a date then hide the Calendar
>> >        If hti.HitArea = MonthCalendar.HitArea.Date Then
>> >            m_picker.Hide()
>> >            SelectedTextBox.Parent.Controls.Remove(m_picker)
>> >            m_picker = Nothing
>> >            bCalOpened = False
>> >        End If
>> >    End Sub
>>
>> > Regards
>> > Marco
>> > The Netherlands
>
>I worked it out.
>
>Dim sDateBox As TextBox
>
>Private Sub tbVerlooptTot_DoubleClick(ByVal sender As Object, ByVal e
>As System.EventArgs) Handles tbVerlooptTot.DoubleClick
>        If bCalOpened = False Then
>            sDateBox = tbVerlooptTot
>            CreateDTP()
>        End If
>
>Private Sub CreateDTP()
>
>        bCalOpened = True
>        m_picker = New MonthCalendar
>        m_picker.BringToFront()
>        m_picker.MaxSelectionCount = 1
>        m_picker.Size = tbVerlooptTot.Size
>        m_picker.BackColor = Color.Beige
>        tbVerlooptTot.Parent = Me
>        Me.Controls.Add(m_picker)
>        m_picker.BringToFront()
>        m_picker.Select()
>
>    End Sub
>
>    Private Sub m_picker_DateChanged(ByVal sender As Object, _
>    ByVal e As DateRangeEventArgs) Handles m_picker.DateChanged
>
>        Dim hti As MonthCalendar.HitTestInfo = m_picker.HitTest
>(m_picker.PointToClient(MousePosition))
>        Dim t As TextBox = DirectCast(sDateBox, TextBox)
>
>        'Display the Start and End property values of
>        'the SelectionRange object in the text boxes.
>        t.Text = m_picker.SelectionRange.Start.Date.ToShortDateString
>()
>        t.Text = m_picker.SelectionRange.End.Date.ToShortDateString()
>
>        'if we clicked on a date then hide the Calendar
>        If hti.HitArea = MonthCalendar.HitArea.Date Then
>            m_picker.Hide()
>            Me.Controls.Remove(m_picker)
>            m_picker = Nothing
>            bCalOpened = False
>        End If
>    End Sub
>
>Thanks for helping me in the right direction.
>
>Marco

It looks like you have six DoubleClick event routines.  You should
have only one that handles the DoubleClick events from all of the
textboxes.  It is not necessary to have bCalOpened, use sDateBox
instead.  CreateDTP is hard coded to use one textbox.  Why does
CreateDTP set the Size of the MonthCalendar to match the textbox Size?
I would think you would want to leave the size alone and set the
Location to something like New Point(sDateBox.Left, sDateBox.Bottom +
5).

Private sDateBox As TextBox = Nothing

Private Sub tbVerlooptTot_DoubleClick(ByVal sender As Object, ByVal e
As System.EventArgs) Handles tbVerlooptTot.DoubleClick, ...
        If sDateBox Is Nothing Then
            sDateBox = DirectCast(sender, TextBox)
            m_picker = New MonthCalendar
            m_picker.BringToFront()
            m_picker.MaxSelectionCount = 1
            m_picker.Size = sDateBox.Size
            m_picker.BackColor = Color.Beige
            Me.Controls.Add(m_picker)
            m_picker.BringToFront()
            m_picker.Select()
        End If
End Sub