?
Solved

How to update textbox value using global string variable as textbox name

Posted on 2008-11-01
4
Medium Priority
?
459 Views
Last Modified: 2012-05-05
I would normally use the following line of code to update the value of a date textbox in a form.......

SpecificForm.DateTextBox.Text = Format(MonthCalendar1.SelectionStart, "MM/dd/yyyy").ToString

BUT, in this particular sub routine I need to be able to update various maskedtextboxes as shown above using a global variable that has the name of the textbox stored in it.  Using a select case I'm able to identify the form that contains the date field, but I need to be able to use the global variable in updating the textbox because there are multiple date fields on various forms....as opposed to one date field.

How can I replace "DateTextBox" with the global variable to accomplish the task?
0
Comment
Question by:TSFLLC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:bigdaddyz99
ID: 22859819
You should be able to access the control  by using the form and "finding" the control by name.

dim tbname as string = "mytextbox"

Dim tb As TextBox = CType(Me.FindControl(tbname), TextBox)
tb.Text = "mytext"
0
 

Author Comment

by:TSFLLC
ID: 22860772
I see FindForm in the list but I do not see FindControl.

I'm using VB2005 and Framework 2.0.
0
 
LVL 3

Accepted Solution

by:
bigdaddyz99 earned 2000 total points
ID: 22862052
Here's what I do...
Add a function to your form to find the control,
then in your code, call it like this for a textbox...

 Dim tb As TextBox
 tb = CType(GetControl("mytextbox"), TextBox)
 tb.Text = "123"
    Public Function GetControl(ByVal cn As String) As Control
        Dim c As Control
        For Each c In Me.Controls
            If c.Name.ToLower = cn.ToLower Then
                Return c
            End If
        Next
        Return Nothing
    End Function
 
     

Open in new window

0
 

Author Comment

by:TSFLLC
ID: 22862800
I already had a similar function set up on most if not all of my forms when it came to a textbox.....only with this one I needed to add new functions on about ten forms for MaskedTextBox 's.

And after doing that, the procedure worked like a charm.

Thanks! for the effort.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question