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

argument in Function error 1924 "name" is not an object 1

Status
Not open for further replies.

sashaDG

Programmer
Jun 20, 2022
112
BY
Good afternoon, thank you For the quick answers under the previous posts, there were difficulties.
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
error 1924 NameCursor is not an object
Didn't find anything on google
 
Because you've got "nameCursor" in double quotes, it's taking that actual name as the name of the cursor. In other words, it's looking for a cursor named nameCursor, rather than a cursor whose name is passed in the parameter.

I think it should work if you take out the double quotes.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Didn't find anything on google

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
 
I see Mike already addressed your core problem.

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:
cTextControl = 'myForm.text' + ALLTRIM(STR(i+3))
&cTextcontrol..ControlSource = nameCursor+"."+arField(i)
similar for the Labelcaption. What's true is, that no matter whether you build a string of a full line of code or just have a part like the control name as a macro, the compiler wil determine the full line and compile it. It also doesn't matter how many macros are used, it all ends up in onle line of code that is compiled. It's just often better to not make up the whole line, especially if building it up is more complicated than writing it down as is, without needing to think how to put it into a string, especially since string delimiters then become a problem.

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:
oTextControl = Eval('myForm.text' + ALLTRIM(STR(i+3)))
WITH oTextControl
  .ControlSource = nameCursor+"."+arField(i)
ENDWITH
I won't make up an example to see if it even works shortened to
Code:
WITH Eval('myForm.text' + ALLTRIM(STR(i+3)))
  .ControlSource = nameCursor+"."+arField(i)
ENDWITH

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
 
Thanks for the help and advice, removing the quotes everything worked
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top