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

Error Msg: "Variable is not Found" 1

Status
Not open for further replies.

PBREP

MIS
Mar 14, 2003
75
US
Hello all"

I'm bombing out on my dblClick procedure. I would like to see the rocord/acct# I selected from my liost box, write it to my array sc_ship_a_ship[80] and to my field 'Card' located in my upsman.dbf table (ref. upsman.Card)

Thank you

Error#: 12
Error Msg: "Variable is not Found"
Line of code: "'select Csnum, carrier, acct_no'+;
' from custacct into cursor lstCsnum'"

Thank you,
PM

Procedure Carr_Acct
oForm = Createobject('Carr_Acct')
oForm.Show

Define Class Carr_Acct As Form
DataSession = 2 && Private data session
Caption ='Select Account#'
ControlBox =.T. && We don't want close,min,max etc buttons
BorderStyle = 1
Height=100
Width=250
AutoCenter =.T.
WindowType =1 && Modal - we don't want user to go on w/o this
Add Object Carr_Acct As ListBox With ;
Left=0, Top=0,Height=100,Width=250
Procedure Carr_Acct.Init
With This
.RowSourceType = 3 && SQL
.RowSource = 'select Csnum, carrier, acct_no'+;
' from custacct into cursor lstCsnum'
.ColumnCount=8
.ColumnLines = .t.
.ColumnWidths = '75,75,75'
Endwith

Procedure Load
use upsman alias upsman
Endproc

Procedure Carr_Acct.DblClick
sc_ship_a_ship[80]=(upsman.Card)

Thisform.Release()
Endproc
Enddefine


 
I don't have a problem with your code when
I run it. I've adjusted it for one of my tables obviously.

I think there is something wrong with one of your fields.

Also, even if it did work, the following line
won't return the result I believe you want:
sc_ship_a_ship[80]=(upsman.Card) should be -
sc_ship_a_ship[80]=(lstCsnum.Card)

Darrell

P.S. You should name the objects something different.
i.e. You've named the procedure, the form, and the listbox
all Carr_Acct. Although this will work, it makes for a
nightmare later when you have to maintain it.




'We all must do the hard bits so when we get bit we know where to bite' :)
 
Are you sure sc_ship_a_ship is defined and
within the scope of Carr_Act?

Darrell

'We all must do the hard bits so when we get bit we know where to bite' :)
 
Hi Darrell:

Thanks for the tip.
BTW: The field 'Card' is located in my upsman.dbf; at anyrate, I tried your suggestion and get the same error.

Thanks :<)
 
Darell Wrote:
Are you sure sc_ship_a_ship is defined and
within the scope of Carr_Act?

Darrell
'We all must do the hard bits so when we


Where would I define it, I thought if your using a private data session it also took care of defining the variable?

Thanks,


PS - Still new to Vfp
 
A private datasession property controls whether
tables and views are opened in a private datasession,
not variable definition.

Although VFP allows creation of variables when they are
assigned, it is a good policy to define them ahead of time
using local, public, or private, and then assign values.

In your code's case, you are using an array, so you HAVE TO
define it ahead of time before you reference any array
elements.

Also, you'll need to get the value out of the form by
indirect or direct reference.

Either way the variable needs to be within the scope of
the form. I prefer the indirect method, although it's
more complicated.

Unfortunately, you can't use the return function in the
form's unload method, since you've defined the form as
modal.


An example:

[tt]
* Example of returning a value from a modal form


LOCAL lcCurDefaultPath
lcCurDefaultPath = SYS(5)+SYS(2003)
SET DEFAULT TO ADDBS(SYS(2023)) && Set the path to VFP's temp directory

* Create a test table and close it

CREATE TABLE custacct (Csnum i, carrier c(10), acct_no N(6))

FOR i = 1 TO 5
INSERT INTO CustAcct (Csnum, carrier, acct_no) VALUES ;
(i, ;
IIF(i==1,&quot;Fed Ex&quot;,IIF(i==2,&quot;Aero&quot;,IIF(i==3,&quot;USPS&quot;,IIF(i==4,&quot;UPS&quot;,&quot;WALK&quot;)))),;
i*1000)
NEXT
USE IN &quot;Custacct&quot;


* Define an array here to prove that setting to private
* in the called procedure 'Carr_Acct' actually does what's intended

DIME sc_ship_a_ship[80]
STORE &quot;Array defined outside of Carr_Acct&quot; TO sc_ship_a_ship


* Call the main procedure

DO Carr_Acct


* Show that the array actually wasn't messed with

MESSAGEBOX(&quot;Array value in this scope: &quot; + ;
TRANSFORM(sc_ship_a_ship[80]), ;
48, ;
&quot;&quot; ;
)


* Clean up after yourself

DELETE FILE (&quot;Custacct.dbf&quot;)
SET DEFAULT TO &lcCurDefaultPath &&


*** Procedure: Carr_Acct ***
PROCEDURE Carr_Acct

PRIVATE sc_ship_a_ship && Make sure we don't redefine an existing variable
DIME sc_ship_a_ship[80]

MESSAGEBOX(&quot;Array value in this scope: &quot; + ;
TRANSFORM(sc_ship_a_ship[80]), ;
48, ;
&quot;&quot; ;
)

oForm = CREATEOBJECT('Carr_Acct',&quot;sc_ship_a_ship[80]&quot;)
oForm.SHOW()

MESSAGEBOX(&quot;The returned value is: &quot; + ;
TRANSFORM(sc_ship_a_ship[80]), ;
48, ;
&quot;Success I assume!&quot; ;
)
ENDPROC

DEFINE CLASS Carr_Acct AS FORM
DATASESSION = 2 && Private data session
CAPTION ='Select Account#'
CONTROLBOX =.T. && We don't want close,min,max etc buttons
BORDERSTYLE = 1
HEIGHT=100
WIDTH=250
AUTOCENTER =.T.
WINDOWTYPE =1 && Modal - we don't want user to go on w/o this

cExternalVar = &quot;&quot; && Holds name of external variable

ADD OBJECT Carr_Acct AS LISTBOX WITH ;
LEFT=0, TOP=0,HEIGHT=100,WIDTH=250

PROCEDURE INIT
LPARAM lcNameOfExternalVar
* Save the name of the external variable.
* We'll need it later...
THISFORM.cExternalVar = lcNameOfExternalVar
ENDPROC

PROCEDURE LOAD
* I assume this is a UPS table, but I'm
* commenting it out for convenience.
*!* USE upsman ALIAS upsman
ENDPROC

PROCEDURE Carr_Acct.INIT

WITH THIS
.ROWSOURCETYPE = 3 && SQL

.ROWSOURCE = 'select Csnum, carrier, acct_no'+;
' from custacct into cursor lstCsnum'

.COLUMNCOUNT=8
.COLUMNLINES = .T.
.COLUMNWIDTHS = '75,75,75'
ENDWITH
ENDPROC


PROCEDURE Carr_Acct.DBLCLICK
* Get an indirect ref to external var,
* set it's value to the selected row's value,
* and release the form
LOCAL lnIndirectRef
lnIndirectRef = THISFORM.cExternalVar
&lnIndirectRef = lstCsnum.Carrier && Change for convenience - lstCsnum.Card
THISFORM.RELEASE()
ENDPROC
ENDDEFINE
[/tt]


Darrell



'We all must do the hard bits so when we get bit we know where to bite' :)
 
Darrell:

Excellent documentation; Thank you for taking the time, I will look over the example.

Have an Awesome weekend!!!

PM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top