Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / June 2004



Tip: Looking for answers? Try searching our database.

Question about controls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PS - 30 Jun 2004 02:41 GMT
   I will try to simplify.  I have a 100 buttons on a form.  The buttons
all have unique names and are NOT in an array.  The name of each button is
displayed in its caption.  There is also a textbox (Text1).  When the user
types in the name of one of the hundred buttons (eg. "Command1") into Text1,
and then presses enter, the caption of the button whose name he typed should
now read "changed".

   This is the code I have, but it does not work:

Dim TargetButton As Control
Dim AA As String
AA = Text1.Text

Set TargetButton = AA
TargetButton.Caption = "Changed"

   This code comes up with a type mismatch error, and I don't know what to
do.  I figure there has got to be a way to hold the name of a button in a
variable.   Could someone please help me solve this problem?
                                                   -Paul
Steve Gerrard - 30 Jun 2004 02:59 GMT
> Dim TargetButton As Control
> Dim AA As String
> AA = Text1.Text
>
> Set TargetButton = AA
> TargetButton.Caption = "Changed"

Set TargetButton = Controls(AA)

Controls is a collection of all the controls on the form. Note that you
will also want to do some error handling, in case there is no control of
that name, or it is a control that does not have a caption.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.