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

controlsource is a function 1

Status
Not open for further replies.

Koen Piller

Programmer
Jun 30, 2005
841
NL
Hi,

I would like to have one of the textboxes on my form to have a function as controlsource, which I believe should be possible. However when I apply following code into the ControlSource I get when I click Apply I get error "The data source for this object must be a variable reference"
Any idea what I am doing wrongly here?

vfp said:
Icase(Between(Val(Result.Outcome),Val(Component.Defaultmin) ,Val(Component.Defaultmax)), 'Default', Val(Result.Outcome)<Val(Component.Defaultmin),'-'+Transform(Val(Component.Defaultmin) - Val(Result.Outcome)), Val(Result.Outcome)>Val(Component.Defaultmax),'+' + Transform(Val(Result.Outcome) - Val(Component.Defaultmax)))

Regards,

Koen
 
If you're doing this in the property sheet, put an equal sign in front of the expression.

Tamar
 
Tamar,

with = in front, and or the whole icase between () no difference. No error 1742 but also no effect nothing in my box.
The icase construction works in my commandwindow, proofing no coding or typing error.
Examing the .value (in the debugger) shows ''.
What more could be possible?

Regards,
Koen
 
Olaf,
Koen said:
with = in front, and or the whole icase between () no difference

Either case nothing in my textbox. [mad]

a screenprint of my form:
Naamloos_hkyxl4.png


field "afwijking" is supposed to give the result and here is the datasource the icase statement.

a screenprint of my development desktop, with the same record:
notice the +83 as result. ( a little proof my icase is without errors ) Why it does not show in my form ???
Naamloos2_zjajk9.png


Is there an other technique to show the result of the statement in the textbox?

Regards,
Koen
 
Works. Are you sure you closed every open brakcet? Your expression would normally end in two closing brackets, one of the ICASE call, one of the overall bracketing. And if the last icase aprameter is a complex expression, even more brackets.

For example I can use this as controlsource of a textbox of a form bound to focode.dbf:
text1.controlsource = "(ICASE(type='C','command',type='F','function','other'))"

Or set (ICASE(type='C','command',type='F','function','other')) in the property window in the controlsource.

Bye, Olaf.
 
Olaf,

Shame on me!!
I had Copy&Pasted the code into the Comment method, one row above the ControlsSource in the property sheet, no wonder it did not work.
Now trying to rectify and I get Error 1742. The code I am pasting:

Code:
= Icase(Between(Val(Resultaten.Uitslag),Val(Component.Standaardmin) ,Val(Component.Standaardmax)), 'normaal', Val(Resultaten.Uitslag)<Val(Component.Standaardmin),'-'+Transform(Val(Component.Standaardmin) - Val(Resultaten.Uitslag)), Val(Resultaten.Uitslag)>Val(Component.Standaardmax),'+' + Transform(Val(Resultaten.Uitslag) - Val(Component.Standaardmax)))

or with ( before Icase and an extra ) at the end: no difference -> error 1742.

Grrr. Could it be that the whole statement is too long? So I removed the tablename in front of the field name, still error 1742.
What's more to experiment?

Regards,
Koen
 
Don't put the = in front.

The = tells VFP to evaluate the expression once, it's fine for any other property but controlsource.
Controlsource is a property containing an expression, it is the property containing an expression that always is evalutated by definition of it. But more important, it stays what it is, it is not evaluated once and replaced by the result of it, so it is not assigned (that's what the = operator does here) it is and stays as it is. That's this way, because the result of evaluating the controlsource then is stored in the value property, not in the controlsource property. It should be clear as mud what happens when you assign the evaluation of the controlsource into the controlsource. You're changing the controlsource itself.Most likely to sting, that's in itself not an expression that can be evaluated.

The only other things in your way:
1. Constant names
The controlsource can't make use of constants you defined via #DEFINE,
2. Local variables
The controlsource also can't make use of variables, unless their scope is public.
3. Other
Anything else, which might work in the context of the command window with all it's known SET PROCEDURE etc. not known at runtime to the form control.

Again a simple proof of making an IIF and ICASE expression work:
Code:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


	**************************************************
*-- Form:         form1 (c:\users\olaf\desktop\icasecontrolsource.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   01/17/18 01:39:10 PM
*
DEFINE CLASS form1 AS form


	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT text1 AS textbox WITH ;
		ControlSource = "(iif(empty(expanded),abbrev,expanded))", ;
		Height = 23, ;
		Left = 12, ;
		Top = 12, ;
		Width = 100, ;
		Name = "Text1"


	ADD OBJECT text2 AS textbox WITH ;
		ControlSource = "(ICASE(type='T', 'type', type='C','command',type='F','function','other'))", ;
		Height = 23, ;
		Left = 120, ;
		Top = 12, ;
		Width = 100, ;
		Name = "Text2"


	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 12, ;
		Left = 228, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "skip>", ;
		Name = "Command1"


	PROCEDURE Load
		USE foxcode
	ENDPROC


	PROCEDURE text2.Init
	ENDPROC


	PROCEDURE command1.Click
		SKIP 1
		thisform.Refresh()
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************

Bye, Olaf.
 
Olaf,
1) Your example works (of course)
2) When I insert my full icase statement into the controlsource of my form I get error 1742, with brackets and or with equalsign in front and the insert is not accepted, it remains None.
now take care: If I insert my full icase statement in your form (overwrite yours), it is accepted, no error, however move your cursor one line down and my statement is gone and replaced with the original. Could it be that there is a limit in characters to the controlsource? Icant find a warning in the Help.
In case I am indeed struggling with a too long statement I shall have to find an other way to 'say' one of the 3 possibilities. Grr.
Which meanwhile found, not so generic as with a procedure as controlsource, but it works.
Thanks for all the good advises.

Regards,
Koen
 
The only length limit I can think of would be that of a literal string, 255 chars.

And if you know property values go into the Properties memo field of an SCX or VCX, and how they are stored there as name = value, this might very well be a reason.
You might be able to store this anyway, when assigning it at runtime, because if that's the reasoning it's not really a capacity limit of the controlsource property, but a limit due to the way property defaults are stored in forms and classes. While memos themselves also allow long values, this way of writing them in literals could also hold longer strings, but they couldn't be evaluated from the runtime.

If I remember correctly you can for example set longer tiptexts, even though that's questionable for such small hint texts, simply by setting them at runtime, eg coming from a tiptext memo field.

Bye, Olaf.
 
Prior to VFP9, the property sheet was indeed limited to 255 chars.

Owing to the addition of MemberData, that limit was increased (to 8K) for SOME properties but others remain with the old limit. (This info is from "New in Nine".)

The string in the OP is 321 characters.
 
Dan,
Thank you to confirm.
Will adjust my coding accordingly and inform Francis about the 255 char restriction and the wrongly error message when you try to enter a string > 255
Thanks again.
Regards,
Koen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top