Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change a textbox value using a variable programatcally

Status
Not open for further replies.

JWilsonny

Programmer
May 8, 2001
46
US
I have a bunch of objects on a form. Mostly textboxes and I want to dynamicaly change the value of the box programatically. How can I address the textbox with a variable?? For example:

For a textbox named textbox1

Thisform.textbox1.value="value"


I need to programatically change textbox1 using a variable.

 
HI
Put in its controlsource the variable name

For example..

TextBox1.ControlSource = m.MyVariable

Then whenever you change the value of m.myVariable thru programme, follow it up with the command..
ThisForm.Refresh() so that the display is also refreshed.

:)

____________________________________________
ramani - (Subramanian.G) :)
 
ramani - thanks for the reply. What I am really trying to do is change the properties of an object where the object name is variable.

So here is the concept ..

if variable(1) = command1

thisform.variable(1).caption="new value"
(does not work)

Where the object can be a textbox or command button etc. an the properties change in a loop structure. ?? Thanks
 
Your are addressing the controls as if a reference to them are in an array.

e.g.

Create a dymanic form such as the following:

Code:
PUBLIC oForm

oForm = CREATEOBJECT("myform")
oForm.SHOW()

DEFINE CLASS myform AS FORM
  DOCREATE = .T.
  AUTOCENTER = .T.
  CAPTION = "Test form"

  ADD OBJECT lblOne AS LABEL WITH ;
    TOP = 10, LEFT = 10, AUTOSIZE = .T., CAPTION = "Initial caption"

  ADD OBJECT txtOne AS TEXTBOX WITH ;
    TOP = THIS.lblOne.TOP+16, LEFT = 10, WIDTH = 100
ENDDEFINE

Then, in the command window type the following:

Code:
DIME ar[2]
ar[1] = oform.lblOne
ar[2] = oform.txtOne
ar[1].CAPTION = "hello"
ar[2].VALUE = "hello"

release ar

Don't forget to release the array from memory, or you
won't be able to close the form.

Darrell
 
HI

if variable(1) = command1

thisform.variable(1).caption="new value"
(does not work)

LOCAL lcObject
lcObject = [ThisForm.]+variable(1)
&lcObject..Caption = "NewValue"

PLease note the & and double dot all without spaces

This will work.

:)

____________________________________________
ramani - (Subramanian.G) :)
 
Ramani,Darrel

Thanks. I see where you are going Darrel. Ramani - I had tried this before without the double dot with no luck. The double dot does the trick. Why the double dot? Thanks for the fix.
 
The first dot is used to terminate the macro definition (see the help file). e.g.
Code:
xx="123"
?&xx.89
?TYPE("&xx.89")
** OR
abcde = 15
xx="abc"
?&xx.ef
The second dot is, in this case, the separtor character between the object and it's property.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top