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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox variable

Status
Not open for further replies.

Toman

Technical User
Mar 30, 2004
190
CZ
Hi, a textbox is bound to a variable lcVar. In some special case I need this variable to reflect textbox value all the time, e.g. after every meaningful keypress.
So I put following "refresh command" into textbox InteractiveChange method
Code:
lcVar = this.value		&& this works
Later willing to make it more generic I've tried
Code:
&this.ControlSource = this.value	&& this does not work giving "Unrecognized command verb" error
Substitution like
Code:
lcDummy = this.ControlSource
&lcDummy = this.value
helps, but seems to be clumsy.
Is there an easy way?

Thank you Tom
 
Tom,

This is how I would do it:

Code:
lcDummy = EVALUATE("this.controlsource")
lcDummy = this.value

But I'm not sure if that's any less "clumsy" than your solution.

Also, I'm curious as to why you want to do this. The controlsource will be updated as soon as the control loses focus. Why do you need to do it after each keypress?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

I like your solution. It is less "clumsy" for me, because it needs not a macro substitution. "One row" solution would be better. It is clear.

My program has to do something with taxes and includes some kind of a decision maker. The user is allowed to change some characteristic values and sees appropriate changes immediately, no need to leave textbox. Relations among numbers in textboxes on a form are valid all the time. I know it is not typical Windows behaviour, but I like the result which is impressive – at least to me :).

Thank you
Tom
 
Hi Mike,
I am sorry, but now I think, that your solution also needs macro substitution. In a first command you load lcDummy with the name of variable bound to textbox. I am surprised, but the effect looks the same as with the simple
Code:
lcDummy = this.ControlSource
Following command (without macro substitution) then refreshes variable lcDummy, not that variable bound to textbox.
Tom.
 
From what I've seen, the macro operator isn't able to resolve the object reference dot operator. In other words, the macro operator can only work on a scalar varable.

If you're really want a one-line solution, then perhaps you could do it with a procedure call, passing the appropriate control by reference as a parameter to the procedure.


--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thank you gentlemen

Mike (Yearwood),
I don't fully understand how to use
Code:
lcObjName = "thisform"

lcObj = lcObjName
&lcObj..Property
	OR
lcObj = eval(lcObjName)
lcObj.Property

when my task is rewrite the value of a variable, which is a ControlSource for a textbox.
If you have a minute, comment it more thoroughly for me. Thank you.


CajunCenturion,
I've tried something like
Code:
* one line code added to all textboxes in question
PROCEDURE text1.InteractiveChange
	thisform.MyRefresh(this)
	…
ENDPROC
…
* new method to a form
PROCEDURE MyRefresh
	PARAMETER MyControl

	VariableName =  MyControl.ControlSource
	&VariableName =  MyControl.value
ENDPROC
and it works. Is it what you meant?


Tom.
 
Yes, that's exactly what I meant.

--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi Toman,

if your controlsource changes to alias.field something like alias.field = this.value won't work.

The simple and very generic solution to update the controlsource without setting focus to some other control is

This.setfocus()

I'd try it, although I think it has some side effects, eg. the cursorposition in the control will change perhaps.

Bye, Olaf.
 
Thanks myearwood.

--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi Olaf,
This.setfocus() really does exactly what I need – refreshes variable with textbox value (not contrariwise as This.refresh() does).
But those side effects you have mentioned are so annoying, that it practically can't be used in application.
Thank you for your post.
Tom.
 
You may save SelStart and Sellength at in Lostfocus Event and set it back at GotFocus. then you may use This.Setfocus() as the solution.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top