Home All Groups Group Topic Archive Search About

Reference To Controls On A Form

Author
5 Feb 2006 8:28 PM
97T
Well this is still bugging me.  I know there are other ways around this, but
for a number of reasons I would like to be able to do this one simple thing.

I have a form with a number of controls on it.

I have created these controls in the form design tool, and given them unique
names.

I would like to be able to put together a line of code that allows this:

OtherForm.Label(UniquePart).Text = "Some text or other"


I can't seem to build a reference to a control on a form.  Every approach I
try seems to object to me trying to use strings to define it!  How the heck
can I get a variable into an object reference?

When I try to create a control variable, it won't let me concatenate and
assign the string variables to it.

Anyone got a clue?

Thanks,

NinerSevenTango

Author
5 Feb 2006 8:54 PM
Chris
97T wrote:
Show quoteHide quote
> Well this is still bugging me.  I know there are other ways around this, but
> for a number of reasons I would like to be able to do this one simple thing.
>
> I have a form with a number of controls on it.
>
> I have created these controls in the form design tool, and given them unique
> names.
>
> I would like to be able to put together a line of code that allows this:
>
> OtherForm.Label(UniquePart).Text = "Some text or other"
>
>
> I can't seem to build a reference to a control on a form.  Every approach I
> try seems to object to me trying to use strings to define it!  How the heck
> can I get a variable into an object reference?
>
> When I try to create a control variable, it won't let me concatenate and
> assign the string variables to it.
>
> Anyone got a clue?
>
> Thanks,
>
> NinerSevenTango
>
>


You need to setup a property on "otherform" to reference your controls.
  If you just want to return a labelbox then:

In OtherForm:
public readonly property Label(Index as String) as LabelBox
Get
For Each Ctr as control in Me.Controls
if Ctr.name = index then
return directcast(ctr, labelbox)
end if       
next
return nothing       
End Get
end property

Hope it helps
Chris
Author
5 Feb 2006 10:10 PM
97T
Thanks, Chris,

I am getting the idea that it is impossible in this language to assemble a
reference by name from a string.

I guess whichever way I go about this, I am going to have to recurse the
form every time I want to refer to an object on a form, or else type the
name out in the code.

I wish someone would prove me wrong.

I thought I had it figured out once, by using a function to return the
reference, but I had something else not working and erased it before I
figured out that saving projects to new names leaves the same form and its
code in use, so I lost it permanently.  Grrrrrr.

Thanks for taking the trouble to reply,

--NinerSevenTango--



Show quoteHide quote
"Chris" <no@spam.com> wrote in message
news:OhX0WZpKGHA.2336@TK2MSFTNGP12.phx.gbl...
>
> You need to setup a property on "otherform" to reference your controls. If
> you just want to return a labelbox then:
>
> In OtherForm:
> public readonly property Label(Index as String) as LabelBox
> Get
> For Each Ctr as control in Me.Controls
> if Ctr.name = index then
> return directcast(ctr, labelbox)
> end if next
> return nothing End Get
> end property
>
> Hope it helps
> Chris
Author
5 Feb 2006 11:30 PM
kashifahmed.bse.mg@gmail.com
hi,

It seems to be parent child form problem. Consider formA (parent) and
formB (child).

Now u want to create some control in formA and assign values from
formB. So when u create object of formB then u better create a
reference with functions in formB of formA, it will help u assign
values into the controls to formA.

You may better create two functions one for reference setting and other
for assign values in controls of formA.

I will send a sample for u if u request.

regards
kashif ahmed
kashifahmed.bse***@gmail.com
Author
6 Feb 2006 4:48 AM
97T
Thank you for replying, sir.

What I would like to do is to accomplish the build of a name to use as the
reference to a named object, such as a control on a form.  I get data type
conversion errors every which way I try.

It doesn't matter whether the control is on the same form or not.  The
problem is that I can't figure out a way to use variables to pick which
control to act upon.

The use of control arrays, and the workarounds therefore in dot net seem to
be a workaround to this problem.

I can and will use the control arrays, but I thought the functionality
should be in there somewhere to allow me to put together a few variables and
use that as a name.

That's what the question is about.

Dim a as String = "Label"
Dim b as String = $(1)

Dim x as Control = a & b
x.Text = "Some Value"

I've tried this a bunch of different ways.

Am I missing something simple?

Thanks again for replying,

--NinerSevenTango--

<kashifahmed.bse***@gmail.com> wrote in message
Show quoteHide quote
news:1139182238.773948.208900@g44g2000cwa.googlegroups.com...
> hi,
>
> It seems to be parent child form problem. Consider formA (parent) and
> formB (child).
>
> Now u want to create some control in formA and assign values from
> formB. So when u create object of formB then u better create a
> reference with functions in formB of formA, it will help u assign
> values into the controls to formA.
>
> You may better create two functions one for reference setting and other
> for assign values in controls of formA.
>
> I will send a sample for u if u request.
>
> regards
> kashif ahmed
> kashifahmed.bse***@gmail.com
>
Author
6 Feb 2006 4:51 AM
97T
To be more specific, I get type conversion errors, can't convert string to
control.

Show quoteHide quote
>
> Dim a as String = "Label"
> Dim b as String = $(1)
>
> Dim x as Control = a & b
> x.Text = "Some Value"
>
> I've tried this a bunch of different ways.
>
> Am I missing something simple?
>
> Thanks again for replying,
>
> --NinerSevenTango--
Author
6 Feb 2006 12:12 AM
Stan Smith
"97T" wrote

> Thanks, Chris,
>
> I am getting the idea that it is impossible in this language to assemble a
> reference by name from a string.
>

97T,

The code I posted works.  Couldn't you get it to work for you?

Stan

--
Stan Smith
ACT! Certified Consultant
ADS Programming Services
Birmingham, AL
205-222-1661
ssmith_at_adsprogramming.com
Author
6 Feb 2006 4:39 AM
97T
Yes, Stan, I'm working on using that concept.

I reposted because I wanted to know if there is any way to build a reference
to a named object from a variable or concatenation thereof.

I came to this language because I wanted explicit data typing along with
some other features.  Now I can't assign a string to a variable and pass
that as the name of an object.  Go figure.

--NinerSevenTango--

Show quoteHide quote
"Stan Smith" <ssm***@adsprogramming.com> wrote in message
news:%23ianxHrKGHA.1132@TK2MSFTNGP10.phx.gbl...
> 97T,
>
> The code I posted works.  Couldn't you get it to work for you?
>
> Stan
>
> --
> Stan Smith
> ACT! Certified Consultant
> ADS Programming Services
> Birmingham, AL
> 205-222-1661
> ssmith_at_adsprogramming.com
>
>
>
Author
6 Feb 2006 6:42 AM
Cor Ligthert [MVP]
Hi,

You would have to understand the difference between a scripting language and
a build (compiled language) (exe or dll)

A scripting language uses all your names at runtime, it is not precompiled
every statement is everytime compiled completely from source to machine
code.

A build language renames all your mnemonic (names) to a for the computer
better usable code (in debug format it holds those names to show them).

The advandce of a build language is simple that it is smaller, less easy to
reuse for others, and process faster.

Cor
Author
7 Feb 2006 1:53 PM
97T
Thank you sir, that is what I have been suspecting.

I expect that these names become pointers to memory locations, and since the
assignments are dynamic, there is no easy way to get their locations unless
you build your own array that points to them.

And that must be why you are prevented from building a name to a reference,
because the compiler would have no way to predict which reference you are
going to build.  (Unless they programmed it to do it!  With a minor memory
and speed penalty of course.)

//Start Minor Rant//

It's not very Visual, and it's not very Basic, though.

As a newcomer to this language, I have been tempted to hunt up a copy of VB6
for this reason, because the few applications I will write are intended to
get a job done, and this job will be most quickly done by designing the
screens once, and writing values into labels many times (something that is
pretty basic to most tasks).

The language is getting in my way.

I don't believe the language couldn't have a generic replacement for the
automatically generated control arrays I have read so much about in VB6
without breaking the OOP dot net religion.  Thousands of coders spending
thousands of hours to do the same task, when it could be fixed once in the
program itself.  All they would have to do is give a choice whether to use
the automatically generated one, or build your own.  They save a hundred man
hours in design, it costs their userbase thousands and thousands of man
hours.

I don't care about portability to other operating systems.  I don't care
about OOP.  I just need a tool to get a job done so I can go back to
designing machines, designing circuits, programming machine controls, and
running a maintenance department for a factory.  I like strong datatypes,
nice interface to networking and file operations, and standard Windows
controls, that is what got me to try this language after learning the basics
of several others.  I don't even need multi threading, except for the
'blocking' behavior thing with sockets.  All the other simple languages I
looked at either tried to hide datatypes so I couldn't work on bytes, or
couldn't do TCP, or didn't have bit shift instructions (I got around that,
try doing CRC calcs without them sometime) or generally had some other huge
stumbling block.

I can get past the stumbling block of needing to go through a bunch of mumbo
jumbo to write text into a box on the user's screen.  It's just a speed
bump.  But it is very irritating.

My problem is that I know too much and too little.  I can write assembler
for cpu's and I can implement database type operations in ladder logic
PLC's, and can design and implement hardwired digital logic circuits.  My
own rule for designs is, "No Ambiguity For The User".  But it gets deep for
me when I get into instatiations of inherited methods of properties of
classes and
my.overloaded.namespace.isitanoperator.isitakeyword.isitabuiltinfunction.itisambiguous.tryeverypossibleiteration._
ItsNamedTheSameIsItTheOneInTheFormOrTheOneInMemory.WhatIsItsState.GoogleItForHours

I know what the processor has to do to time slice operations.  I have pretty
good idea what it has to do to keep track of memory addresses and implement
commands.  It's just not very well explained how all this takes place with
the tools you get.  I grew up with programming manuals that were very
explicit, so this seems like a religion of memorization of arbitrary rules
that have fuzzy boundaries.

//End Of Rant//

Thank you for your patience and your insight and your wise advice.  It was
generous of you to take the time to respond and I do know the value of that,
and I appreciate it.  I am now off to finish my control array logic.  I did
get communications to the industrial black box working, CRC and all, now I
just need to show the user what I got from the box.

Maybe when I get it done I'll write a newcomer's guide on How To Write Text
Variables Into Large Numbers Of Static Labels On Several Screens.

--NinerSevenTango--



Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uLP%23YhuKGHA.500@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> You would have to understand the difference between a scripting language
> and a build (compiled language) (exe or dll)
>
> A scripting language uses all your names at runtime, it is not precompiled
> every statement is everytime compiled completely from source to machine
> code.
>
> A build language renames all your mnemonic (names) to a for the computer
> better usable code (in debug format it holds those names to show them).
>
> The advandce of a build language is simple that it is smaller, less easy
> to reuse for others, and process faster.
>
> Cor
>
Author
7 Feb 2006 2:25 PM
Cor Ligthert [MVP]
97T,

Everything what you write can probably overcomed, however you cannot say,
use 97T as control, while it never has been used or declared.

But you can set "97T" by instance in the Tag property
Or you can make an array, which direct indexes the 97T Control.
And more of those solutions.

Net has not anymore the formcontrolarray as VB6 had completely only for a
form.

But every control has its own array of posible child controls.

You can by instance write. (just typed in this message in this way never
tested by me).

\\\
dim 97TextBox as textbox
For each ctr as control in myform.controls
    if ctr.tag = "97T"
           97TextBox = DirectCast(ctr, TextBox)
            Exit For
    End if
Next
///

I hope this helps,

Cor

Show quoteHide quote
"97T" <not@spamthis.com> schreef in bericht
news:OljPU2%23KGHA.1288@TK2MSFTNGP09.phx.gbl...
> Thank you sir, that is what I have been suspecting.
>
> I expect that these names become pointers to memory locations, and since
> the assignments are dynamic, there is no easy way to get their locations
> unless you build your own array that points to them.
>
> And that must be why you are prevented from building a name to a
> reference, because the compiler would have no way to predict which
> reference you are going to build.  (Unless they programmed it to do it!
> With a minor memory and speed penalty of course.)
>
> //Start Minor Rant//
>
> It's not very Visual, and it's not very Basic, though.
>
> As a newcomer to this language, I have been tempted to hunt up a copy of
> VB6 for this reason, because the few applications I will write are
> intended to get a job done, and this job will be most quickly done by
> designing the screens once, and writing values into labels many times
> (something that is pretty basic to most tasks).
>
> The language is getting in my way.
>
> I don't believe the language couldn't have a generic replacement for the
> automatically generated control arrays I have read so much about in VB6
> without breaking the OOP dot net religion.  Thousands of coders spending
> thousands of hours to do the same task, when it could be fixed once in the
> program itself.  All they would have to do is give a choice whether to use
> the automatically generated one, or build your own.  They save a hundred
> man hours in design, it costs their userbase thousands and thousands of
> man hours.
>
> I don't care about portability to other operating systems.  I don't care
> about OOP.  I just need a tool to get a job done so I can go back to
> designing machines, designing circuits, programming machine controls, and
> running a maintenance department for a factory.  I like strong datatypes,
> nice interface to networking and file operations, and standard Windows
> controls, that is what got me to try this language after learning the
> basics of several others.  I don't even need multi threading, except for
> the 'blocking' behavior thing with sockets.  All the other simple
> languages I looked at either tried to hide datatypes so I couldn't work on
> bytes, or couldn't do TCP, or didn't have bit shift instructions (I got
> around that, try doing CRC calcs without them sometime) or generally had
> some other huge stumbling block.
>
> I can get past the stumbling block of needing to go through a bunch of
> mumbo jumbo to write text into a box on the user's screen.  It's just a
> speed bump.  But it is very irritating.
>
> My problem is that I know too much and too little.  I can write assembler
> for cpu's and I can implement database type operations in ladder logic
> PLC's, and can design and implement hardwired digital logic circuits.  My
> own rule for designs is, "No Ambiguity For The User".  But it gets deep
> for me when I get into instatiations of inherited methods of properties of
> classes and
> my.overloaded.namespace.isitanoperator.isitakeyword.isitabuiltinfunction.itisambiguous.tryeverypossibleiteration._
> ItsNamedTheSameIsItTheOneInTheFormOrTheOneInMemory.WhatIsItsState.GoogleItForHours
>
> I know what the processor has to do to time slice operations.  I have
> pretty good idea what it has to do to keep track of memory addresses and
> implement commands.  It's just not very well explained how all this takes
> place with the tools you get.  I grew up with programming manuals that
> were very explicit, so this seems like a religion of memorization of
> arbitrary rules that have fuzzy boundaries.
>
> //End Of Rant//
>
> Thank you for your patience and your insight and your wise advice.  It was
> generous of you to take the time to respond and I do know the value of
> that, and I appreciate it.  I am now off to finish my control array logic.
> I did get communications to the industrial black box working, CRC and all,
> now I just need to show the user what I got from the box.
>
> Maybe when I get it done I'll write a newcomer's guide on How To Write
> Text Variables Into Large Numbers Of Static Labels On Several Screens.
>
> --NinerSevenTango--
>
>
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:uLP%23YhuKGHA.500@TK2MSFTNGP15.phx.gbl...
>> Hi,
>>
>> You would have to understand the difference between a scripting language
>> and a build (compiled language) (exe or dll)
>>
>> A scripting language uses all your names at runtime, it is not
>> precompiled every statement is everytime compiled completely from source
>> to machine code.
>>
>> A build language renames all your mnemonic (names) to a for the computer
>> better usable code (in debug format it holds those names to show them).
>>
>> The advandce of a build language is simple that it is smaller, less easy
>> to reuse for others, and process faster.
>>
>> Cor
>>
>
>
Author
7 Feb 2006 5:03 PM
Fr15ky
97T,

I am doing a similar thing in my code. I currently only use it to
change the colors of a control, but you should be able to use something
like this:

Public Sub ChangeFormControls(ByVal ctl As Control, ByVal sAction As
String, ByVal sActionType As String)

        Try
            Dim ChangeBackColor As Color     'back color
            Dim ChangeForeColor As Color     'fore color
            Dim bBoldFlag As Boolean         'bold / unbold flag

            Dim ctlType As String = ctl.GetType.ToString
            ctlType = ctlType.Substring(ctlType.LastIndexOf("."))
            ctlType = Right(ctlType, ctlType.Length - 1)

            Select Case ctlType.ToLower
                Case "combobox", "textbox"   'textbox and combobox
change
                    ctl.BackColor = ChangeBackColor
                    ctl.ForeColor = ChangeForeColor
            End Select
        Catch ex As Exception
        End Try
End Sub

The real code you are looking for is around the ctlType String. I hope
this is helpful to you. This is used in VB.NET 2005.

Mark Dahl
Author
7 Feb 2006 5:06 PM
Fr15ky
I just realized that this probably wouldn't help you in what you were
trying to do. Sorry. I misunderstood your problem.

Mark Dahl
Author
8 Feb 2006 12:35 PM
97T
Right, I was whining about having to step through each control and pass it
into a structure similar to what you gave me.

But it is useful anyway, thanks,

--NinerSevenTango--


Show quoteHide quote
"Fr15ky" <shilohs***@gmail.com> wrote in message
news:1139332007.174647.7560@g14g2000cwa.googlegroups.com...
>I just realized that this probably wouldn't help you in what you were
> trying to do. Sorry. I misunderstood your problem.
>
> Mark Dahl
>
Author
8 Feb 2006 12:37 PM
97T
Thank you sir, that does help.

--97T--

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uGC3OJ$KGHA.140@TK2MSFTNGP12.phx.gbl...
> 97T,
>
> Everything what you write can probably overcomed, however you cannot say,
> use 97T as control, while it never has been used or declared.
>
> But you can set "97T" by instance in the Tag property
> Or you can make an array, which direct indexes the 97T Control.
> And more of those solutions.
>
> Net has not anymore the formcontrolarray as VB6 had completely only for a
> form.
>
> But every control has its own array of posible child controls.
>
> You can by instance write. (just typed in this message in this way never
> tested by me).
>
> \\\
> dim 97TextBox as textbox
> For each ctr as control in myform.controls
>    if ctr.tag = "97T"
>           97TextBox = DirectCast(ctr, TextBox)
>            Exit For
>    End if
> Next
> ///
>
> I hope this helps,
>
> Cor
>
> "97T" <not@spamthis.com> schreef in bericht
> news:OljPU2%23KGHA.1288@TK2MSFTNGP09.phx.gbl...
>> Thank you sir, that is what I have been suspecting.
>>
>> I expect that these names become pointers to memory locations, and since
>> the assignments are dynamic, there is no easy way to get their locations
>> unless you build your own array that points to them.
>>
>> And that must be why you are prevented from building a name to a
>> reference, because the compiler would have no way to predict which
>> reference you are going to build.  (Unless they programmed it to do it!
>> With a minor memory and speed penalty of course.)
>>
>> //Start Minor Rant//
>>
>> It's not very Visual, and it's not very Basic, though.
>>
>> As a newcomer to this language, I have been tempted to hunt up a copy of
>> VB6 for this reason, because the few applications I will write are
>> intended to get a job done, and this job will be most quickly done by
>> designing the screens once, and writing values into labels many times
>> (something that is pretty basic to most tasks).
>>
>> The language is getting in my way.
>>
>> I don't believe the language couldn't have a generic replacement for the
>> automatically generated control arrays I have read so much about in VB6
>> without breaking the OOP dot net religion.  Thousands of coders spending
>> thousands of hours to do the same task, when it could be fixed once in
>> the program itself.  All they would have to do is give a choice whether
>> to use the automatically generated one, or build your own.  They save a
>> hundred man hours in design, it costs their userbase thousands and
>> thousands of man hours.
>>
>> I don't care about portability to other operating systems.  I don't care
>> about OOP.  I just need a tool to get a job done so I can go back to
>> designing machines, designing circuits, programming machine controls, and
>> running a maintenance department for a factory.  I like strong datatypes,
>> nice interface to networking and file operations, and standard Windows
>> controls, that is what got me to try this language after learning the
>> basics of several others.  I don't even need multi threading, except for
>> the 'blocking' behavior thing with sockets.  All the other simple
>> languages I looked at either tried to hide datatypes so I couldn't work
>> on bytes, or couldn't do TCP, or didn't have bit shift instructions (I
>> got around that, try doing CRC calcs without them sometime) or generally
>> had some other huge stumbling block.
>>
>> I can get past the stumbling block of needing to go through a bunch of
>> mumbo jumbo to write text into a box on the user's screen.  It's just a
>> speed bump.  But it is very irritating.
>>
>> My problem is that I know too much and too little.  I can write assembler
>> for cpu's and I can implement database type operations in ladder logic
>> PLC's, and can design and implement hardwired digital logic circuits.  My
>> own rule for designs is, "No Ambiguity For The User".  But it gets deep
>> for me when I get into instatiations of inherited methods of properties
>> of classes and
>> my.overloaded.namespace.isitanoperator.isitakeyword.isitabuiltinfunction.itisambiguous.tryeverypossibleiteration._
>> ItsNamedTheSameIsItTheOneInTheFormOrTheOneInMemory.WhatIsItsState.GoogleItForHours
>>
>> I know what the processor has to do to time slice operations.  I have
>> pretty good idea what it has to do to keep track of memory addresses and
>> implement commands.  It's just not very well explained how all this takes
>> place with the tools you get.  I grew up with programming manuals that
>> were very explicit, so this seems like a religion of memorization of
>> arbitrary rules that have fuzzy boundaries.
>>
>> //End Of Rant//
>>
>> Thank you for your patience and your insight and your wise advice.  It
>> was generous of you to take the time to respond and I do know the value
>> of that, and I appreciate it.  I am now off to finish my control array
>> logic. I did get communications to the industrial black box working, CRC
>> and all, now I just need to show the user what I got from the box.
>>
>> Maybe when I get it done I'll write a newcomer's guide on How To Write
>> Text Variables Into Large Numbers Of Static Labels On Several Screens.
>>
>> --NinerSevenTango--
>>
>>
>>
>> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
>> news:uLP%23YhuKGHA.500@TK2MSFTNGP15.phx.gbl...
>>> Hi,
>>>
>>> You would have to understand the difference between a scripting language
>>> and a build (compiled language) (exe or dll)
>>>
>>> A scripting language uses all your names at runtime, it is not
>>> precompiled every statement is everytime compiled completely from source
>>> to machine code.
>>>
>>> A build language renames all your mnemonic (names) to a for the computer
>>> better usable code (in debug format it holds those names to show them).
>>>
>>> The advandce of a build language is simple that it is smaller, less easy
>>> to reuse for others, and process faster.
>>>
>>> Cor
>>>
>>
>>
>
>