argument in Function error 1924 "name" is not an object
argument in Function error 1924 "name" is not an object
(OP)
Good afternoon, thank you For the quick answers under the previous posts, there were difficulties.
In OptionGroup.InteractiveChange this code works
But when I want to transfer this code to a function, problems arise with SortedData
ConnectTxtBoxCursor(ThisForm, "SortedData", @arNameTextField)
error 1924 NameCursor is not an object
Didn't find anything on google
In OptionGroup.InteractiveChange this code works
CODE -->
SortedData arNameTextField FOR i = 1 TO ALEN(arNameTextField) cTextControlSource = 'ThisForm.text' + ALLTRIM(STR(i+3)); + '.ControlSource= ' +'"SortedData." + arNameTextField(i)' &cTextControlSource cLabelCaption = 'ThisForm.label' + ALLTRIM(STR(i)); + '.Caption = ' + '(arNameTextField(i))' &cLabelCaption ENDFOR
But when I want to transfer this code to a function, problems arise with SortedData
ConnectTxtBoxCursor(ThisForm, "SortedData", @arNameTextField)
CODE -->
FUNCTION ConnectTxtBoxCursor(myForm, nameCursor, arField) FOR i = 1 TO ALEN(arField) cTextControlSource = 'myForm.text' + ALLTRIM(STR(i+3)); + '.ControlSource= ' +'"nameCursor"+"." + arField(i)' &cTextControlSource cLabelCaption = 'myForm.label' + ALLTRIM(STR(i)); + '.Caption = ' + '(arField(i))' &cLabelCaption ENDFOR ENDFUNC
Didn't find anything on google
RE: argument in Function error 1924 "name" is not an object
I think it should work if you take out the double quotes.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: argument in Function error 1924 "name" is not an object
I can't stress enough that looking for this sort of thing on Google is not the way to solve the problem. And it's certainly not the way to become a better programmer.
Instead, you should study your code closely to understand exactly what it is doing. If necessary, run it in the Debugger, and examine the actual value that is stored in cTextControlSource. If you did that, you would instantly see what's wrong.
By all means use Google to understand specific commands or functions. (But it's better to use the VFP Help for that.) But don't expect Google to solve your problems for you.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: argument in Function error 1924 "name" is not an object
You make use of macrosubstitution as someone being proud to know it and liking it a lot.
What you do can be done much more directly, still using macro substitution, but just for the control name itself:
CODE
Also, this only works provided Mike is right, nameCursor is a variable or parameter that has the name of the cursor/workarea, then you don't literally mean nameCursor, but it's a variable that contains the name and therefore you use it unquoted to get its value and not use its name.
Btw, it's not nice to have something like Text1,2,,3,4 and then even like in this situation, where I assume Text1,2 and 3 are for something else and the texboxes for the data start at Text4 for field1, etc.
This is not good style at all, I'll just let that stand alone, there are other ways to get this into a better way of addressing. But that's a longer lesson.
You can go one step further, when you make use of EVAL to get an object reference and then WITH
CODE
CODE
This way the compiler isn't needed to compile the line that has one or more macro substitutions.
Well, the far simplest way to get controls bound to fields is
1. open a table in the form dataaenvirnoment (at design time right click and pick data evironment)
2. Drag one field from the visual displayy of a table in the data environment to the form
3. done
This is not building up HTML at runtime, the form is ideally visually design and only needs to be run, not built up.
You have a textbox (usually) that already has controlsource set and a label in front of it with the field name as caption. And there are ways to make this even better.
The major point is actually not that it's easy to do as a drag&drop operation, you do smething in code that's better and easier one at design time. Once you have this all, you can rename the control, you can add controls that go
before it or after, and it all still works, while your code depends on no renumbering and is likely to fail one day someone has the idea of consolidating control names.
Chriss
RE: argument in Function error 1924 "name" is not an object