Home > Archive > Programming with dBASE > October 2005 > Why does this code produce an "Invalid subscript reference" error?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Why does this code produce an "Invalid subscript reference" error?
Zagrijs Venter

2005-10-20, 8:26 pm

Hi All,

The included code produces an "Invalid Subscript Reference" error on the
last line, i.e.

form.GDSTOCK.columns "AVAILABLE"].datalink = r.fields["nQuantity"].

It is the fields reference "nQuantity" that generates the error. I tested
it by replacing the
reference with the name of another field in the table. I guess I am
probably missing
something very small here, but just cannot see it! < g >!

Any help appreciated.

Regards

Zagrijs

local c, r, cStockCode, nQty

aCurStock

r = form.rowset
aCurStock = new assocArray()
c = new Field()
c.fieldName := "nQuantity"
r.fields.add(c)

if r.first( )

use stockline

do

cStockCode = trim( r.fields["cUniqCode"].value )
sum qtyBought for cUniqCode == cStockCode to nBought
sum qtySold for cUniqCode == cStockCode to nSold
nQty = nBought - nSold

aCurStock[cStockCode] = nQty

until not r.next()

use

endif

c.beforeGetValue := {||aCurStock[ trim( this.parent.parent.fields
["cUniqCode"].value ) ] }
form.GDSTOCK.columns["AVAILABLE"].datalink = r.fields["nQuantity"]



Roland Wingerter

2005-10-20, 8:26 pm

Zagrijs Venter wrote

>
> The included code produces an "Invalid Subscript Reference" error on the
> last line, i.e.
>
> form.GDSTOCK.columns "AVAILABLE"].datalink = r.fields["nQuantity"].
>
> It is the fields reference "nQuantity" that generates the error.

--------
I guess you got the fieldname wrong. Check the fieldname and make sure it
exists.

Roland


Zagrijs Venter

2005-10-20, 8:26 pm

Hi Roland

Thanks for your response. However, not the problem. If you read my turnkey
code carefully you will notice that the field is created and added to the
rowset. Testing whether the field has really been added by looping through
the fields array, proofed that it is indeed there. Yet, it creates the
error.

My guess is that there is a problem with my "beforeGetValue" code which
creates the error.

"Roland Wingerter" wrote

> I guess you got the fieldname wrong. Check the fieldname and make sure it
> exists.
>
> Roland
>
>



Roland Wingerter

2005-10-20, 8:26 pm

Zagrijs Venter wrote

>
> Thanks for your response. However, not the problem. If you read my
> turnkey code carefully you will notice that the field is created and added
> to the rowset.

-------
Sorry, I should have read more carefully.

> My guess is that there is a problem with my "beforeGetValue" code which
> creates the error.

--------
I always struggle with beforeGetValue <sigh>.

> c.beforeGetValue := {||aCurStock[ trim( this.parent.parent.fields
> ["cUniqCode"].value ) ] }

-------
The problem is to get the reference right. Try
this.parent["cUniqCode"].value instead of this.parent.parent.fields etc.

In a fields beforeGetValue this refers to the field, so this.parent refers
to the fields array.
Maybe rewrite beforeGetValue as a function and test ? this.parent.classname.

Hope this helps

Roland





Zagrijs Venter

2005-10-20, 8:26 pm

Hi

Thanks once again for your help.

Managed to get it going by copying another test form with code that worked
and amending the code. Problem was indeed in the "beforeGetValue".

Now there is a new problem. The value only displays in the Grid if you
actually set focus to the cell to edit. If you scroll down the grid, the
value disappear again. <sigh >

Do you know the answer to this one?

Zagrijs


"Roland Wingerter" wrote

> Sorry, I should have read more carefully.
>
> --------
> I always struggle with beforeGetValue <sigh>.
>
> -------
> The problem is to get the reference right. Try
> this.parent["cUniqCode"].value instead of this.parent.parent.fields etc.
>
> In a fields beforeGetValue this refers to the field, so this.parent refers
> to the fields array.
> Maybe rewrite beforeGetValue as a function and test ?
> this.parent.classname.
>
> Hope this helps
>
> Roland
>
>
>
>
>



Roland Wingerter

2005-10-20, 8:26 pm

Zagrijs Venter wrote

> Thanks once again for your help.

------
You're welcome, Zagrijs.

> Managed to get it going by copying another test form with code that worked
> and amending the code. Problem was indeed in the "beforeGetValue".

------
Glad you solved it.

> Now there is a new problem. The value only displays in the Grid if you
> actually set focus to the cell to edit. If you scroll down the grid, the
> value disappear again. <sigh >
>
> Do you know the answer to this one?

-------
I don't know. You code sample contained a mix of xdml and OODML. Maybe this
causes problems. Don't you use the form designer?

Roland



Marc VdB

2005-10-20, 8:26 pm

Hi Zagrijs,

> Now there is a new problem. The value only displays in the Grid if you
> actually set focus to the cell to edit. If you scroll down the grid, the
> value disappear again. <sigh >


No problem <g>
see the attached form, you will see that it is not a problem of building the
grid on the fly, but rather a problem of column-size.
If you build the grid without specifying the type of the editorcontrol, the
default is entryfield, while in the designer it is according to the type
ofthe field-value (in your case spinbox).
So if you build the grid on the fly and you dont specify the control-type
and you make the column to narrow, the value can't be seen, but it is there.
Widen the column or make it a spinbox and it will work

HTH Marc

--
www.vdblogic.de/dbl
------


begin 666 zag.wfm
M<V5T(&1A=&%B87-E('1O.R!C;&]S92!T86)L97,-"FEF(&9I;&4H)UIA9RYD
M8F8G*3L@9')O<"!T86)L92!Z86<-"F5N9&EF#0IC<F5A=&4@=&%B;&4@>F%G
M*&-S=&]C:V-O9&4@8VAA<B@Q*2P@8VYA;64@8VAA<B@Q,BDI#0II;G-E<G0@
M:6YT;R!Z86<@=F%L=65S("@B,2(L(F1"87-E(BD-"FEN<V5R="!I;G1O('IA
M9R!V86QU97,@*"(R(BPB9%%U97)Y(BD-"FEN<V5R="!I;G1O('IA9R!V86QU
M97,@*" (S(BPB9$)+;VXB*0T**B
H@14Y$($A%041%4B M+2!$:65S92!:96EL
M92!N:6-H="!E;G1F97)N96X-"B\O#0HO+R!%<G-T96QL="!A;2 Q."XQ,"XR
M,# U#0HO+PT*<&%R86UE=&5R(&)-;V1A; T*;&]C86P@9@T*9B ](&YE=R!Z
M86=F;W)M*"D-"FEF("AB36]D86PI#0H@("!F+FUD:2 ](&9A;'-E("\O($YI
M8VAT+4U$22!F97-T;&5G96X-"B @(&8N4F5A9$UO9&%L*"D-"F5L<V4-"B @
M(& 8N3W!E;B@I#0IE;F1I9@
T*#0IC;&%S<R!Z86=F;W)M(&]F($9/4DT-"B @
M('=I=&@@*'1H:7,I#0H@(" @("!H96EG:'0@/2 Q.2XW-S(W#0H@(" @("!L
M969T(#T@-3 N,30R.0T*(" @(" @=&]P(#T@,RXQ.#$X#0H@(" @("!W:61T
M:" ](#<X+C(X-3<-"B @(" @(&UD:2 ](&9A;'-E#0H@("!E;F1W:71H#0H-
M"B @('1H:7,N6D%',2 ](&YE=R!1545262@I#0H@("!T:&ES+EI!1S$N<&%R
M96YT(#T@=&AI<PT*(" @=VET:" H=&AI<RY:04<Q*0T*(" @(" @;VY/<&5N
M(#T@8VQA<W,Z.D-!3$-?1DE%3$0-"B @(" @(&QE9G0@/2 U."XP#0H@(" @
M("!T;W @/2 P+C4-"B @(" @('-Q;" ]("=S96QE8W0@*B!F<F]M(")Z86<N
M1$)&(B<-"B @(" @(')E<75E<W1,:79E(#T@9F%L<V4-"B @(" @(&%C=&EV
M92 ]('1R=64-"B @(&5N9'=I=&@-"@T*(" @=VET:" H=&AI<RY:04<Q+G)O
M=W-E="D-"B @(" @(&9I96QD<ULB;E$B72YB969O<F5'971686QU92 ]('L[
M(')E='5R;B!T:&ES+G!A<F5N="YP87)E;G0N85MT<FEM*'1H:7,N<&%R96YT
M6R)C< W1O8VM#;V1E(ETN=F%L=
64@*2!=?0T*(" @96YD=VET: T*#0H@("!T
M:& ES+D=2240Q(#T@;F5W($
=2240H=&AI<RD-"B @('=I=&@@*'1H:7,N1U))
M1#$I#0H@(" @("!D871A3&EN:R ](&9O<FTN>F%G,2YR;W=S970-"B @(" @
M(&-O;'5M;G-;(D-/3%5-3C$B72 ](&YE=R!'4DE$0T],54U.*&9O<FTN1U))
M1#$I#0H@(" @(" !C;VQU;6YS6R)#3TQ534
XQ(ETN9&%T84QI;FL@/2!F;W)M
M+GIA9S$N<F]W<V5T+F9I96QD<ULB8W-T;V-K8V]D92)=#0H@(" @("!C;VQU
M;6YS6R)#3TQ534XQ(ET
N961I=&]R5'EP92 ](#$)+R\@16EN9V%B969
E;&0-
M"B @(" @(&-O;'5M;G-;(D-/3%5-3C$B72YW:61T:" ](#$T+C -"B @(" @
M(&-O;'5M;G-;(D-/3%5-3C(B72 ](&YE=R!'4DE$0T],54U.*&9O<FTN1U))
M1#$I#0H@(" @(" !C;VQU;6YS6R)#3TQ534
XR(ETN9&%T84QI;FL@/2!F;W)M
M+GIA9S$N<F]W<V5T+F9I96QD<ULB;G$B70T*(" @(" @8V]L=6UN<ULB0T],
M54U.,B)=+F5D:71O<E1Y<&4@/2 S"2\O(%=I<'!R96=L97(-"B @(" @(&-O
M;'5M;G-;(D-/3%5-3C(B72YW:61T:" ](#$R+C -"B @(" @(&-O;'5M;G-;
M(D-/3%5-3C,B72 ](&YE=R!'4DE$0T],54U.*&9O<FTN1U))1#$I#0H@(" @
M(" !C;VQU;6YS6R)#3TQ534
XS(ETN9&%T84QI;FL@/2!F;W)M+GIA9S$N<F]W
M<V5T+F9I96QD<ULB8VYA;64B70T*(" @(" @8V]L=6UN<ULB0T],54U.,R)=
M+F5D:71O<E1Y<&4@/2 Q" 2\O($5I;F=A8F5F96QD#
0H@(" @("!C;VQU;6YS
M6R)#3TQ534XS(ETN=VE
D=&@@/2 Q-RXP#0H@(" @("!W:71H("AC;VQU;6YS
M6R)#3TQ534XQ(ETN961
I=&]R0V]N=')O;"D-"B @(" @(" @('9A;&ED17)R
M;W)-<V<@/2 B56YG_& QT:6=E($5I;F=A8F4@(@
T*(" @(" @96YD=VET: T*
M#0H@(" @("!W:71H(" AC;VQU;6YS6R)#3TQ534
XQ(ETN:&5A9&EN9T-O;G1R
M;VPI#0H@(" @(" @("!V86QU92 ](")C<W1O8VMC;V1E(@T*(" @(" @96YD
M=VET: T*#0H@(" @("!W:71H(" AC;VQU;6YS6R)#3TQ534
XR(ETN961I=&]R
M0V]N=')O;"D-"B @(" @(" @(')A;F=E36%X(#T@,3 P#0H@(" @(" @("!R
M86YG94UI;B ](#$-"B @(" @(" @('9A;&ED17)R;W)-<V<@/2 B56YG_&QT
M:6=E($5I;F=A8F4@(@T
*(" @(" @96YD=VET: T*#0H@(" @("!W:71H("AC
M;VQU;6YS6R)#3TQ534X
R(ETN:&5A9&EN9T-O;G1R;VPI#0H@(" @(" @("!V
M86QU92 ](").<2(-"B @(" @(&5N9'=I=&@-"@T*(" @(" @=VET:" H8V]L
M=6UN<ULB0T],54U.,R)=+F5D:71O<D-O;G1R;VPI#0H@(" @(" @("!V86QI
M9$5R<F]R37-G(#T@(E5N9_QL=&EG92!%:6YG86)E("(-"B @(" @(&5N9'=I
M=&@-"@T*(" @(" @=VET:" H8V]L=6UN<ULB0T],54U.,R)=+FAE861I;F=#
M;VYT<F]L*0T*(" @(" @(" @=F%L=64@/2 B8VYA;64B#0H@(" @("!E;F1W
M:71H#0H-"B @(" @(&AE:6=H=" ](#8N, T*(" @(" @;&5F=" ](#(N, T*
M(" @(" @=&]P(#T@,2XP#0H@(" @("!W:61T:" ](#4R+C -"B @(&5N9'=I
M=&@-"@T*(" @=&AI<RY055-(0E545$].,2 ](&YE=R!055-(0E545$].*'1H
M:7,I#0H@("!W:71H("AT:&ES+E!54TA"55143TXQ*0T*(" @(" @;VY#;&EC
M:R ](&-L87-S.CI055-(0E545$].,5]/3D-,24-+#0H@(" @("!H96EG:'0@
M/2 Q+C Y,#D-"B @(" @(&QE9G0@/2 R+C -"B @(" @('1O<" ](#<N-0T*
M(" @(" @=VED=&@@/2 R-2XP#0H@(" @("!T97AT(#T@(D-R96%T92!G<FED
M(&]N('1H92!F;'DB#0H@("!E;F1W:71H#0H-"B @('1H:7,N4%532$)55%1
/
M3C(@/2!N97<@4%532$)55%1/3BAT:&ES*0T*(" @=VET:" H=&AI<RY055-(
M0E545$].,BD-"B @(" @(&]N0VQI8VL@/2!C;&%S<SHZ4%532$)55%1/3C)?
M3TY#3$E#2PT*(" @(" @=FES:6)L92 ](&9A;'-E#0H@(" @("!H96EG:'0@
M/2 Q+C Y,#D-"B @(" @(&QE9G0@/2 S+C -"B @(" @('1O<" ](#$W+C -
M"B @(" @('=I9'1H(#T@,C,N, T*(" @(" @=&5X=" ](")7:61E;B!C;VQU
M;6XB#0H@("!E;F1W:71H#0H-"B @('1H:7,N<F]W<V5T(#T@=&AI<RYZ86<Q
M+G)O=W-E= T*#0H@("!F=6YC=& EO;B!C86QC7V9I96QD#0
H@(" @("!L;V-A
M;" @8RP@<B L>0T*(" @(" @<B ]('1H:7,N<F]W<V5T#0H@(" @("!R+F$@
M/2!N97<@87-S;V-!<G)A>2@I#0H@(" @("!C(#T@;F5W($9I96QD*"D-"B @
M(" @(&,N9FEE;&1.86UE(#H](")N42(-"B @(" @('(N9FEE;&1S+F%D9"AC
M*0T*(" @(" @<BYA6R(Q(ET@/2 Q, T*(" @(" @<BYA6R(R(ET@/2 R, T*
M(" @(" @<BYA6R(S(ET@/2 Q,# -"B @(" @('(N85LB-")=(#T@,3 U#0H@
M(" @("!R+F9I96QD<ULB;E$B72YB969O<F5'971686QU92 Z/2![.R!R971U
M<FX@=&AI<RYP87)E;G0N<&%R96YT+F%;=')I;2AT:&ES+G!A<F5N=%LB8W-T
M;V-K0V]D92)=+G9A;'5E("D@72!]#0H@("!R971U<FX@(" @(" -"@T*(" @
M9G5N8W1I;VX@4%532$)
55%1/3C%?;VY#;&EC:PT*(" @9F]R;2Y'4DE$,B ]
M(&YE=R!'4DE$*&9O<FTI#0H@("!W:71H("AF;W)M+D=2240R*0T*(" @(" @
M9&%T84QI;FL@/2!F;W)M+GIA9S$N<F]W<V5T#0H@(" @("!C;VQU;6YS6R)#
M3TQ534XQ(ET@/2!N97<@1U))1$-/3%5- 3BAF;W)M+D=2240R*0T*
(" @(" @
M8V]L=6UN<ULB0T],54U.,2)=+F1A=& %,:6YK(#T@9F]R;2YZ86
<Q+G)O=W-E
M="YF:65L9'-;(F-S=&]C:V-O9&4B70T*(" @(" @8V]L=6UN<ULB0T],54U.
M,2)=+F5D:71O<E1Y<&4@/2 Q(" @+R\@16EN9V%B969E;&0-"B @(" @(&-O
M;'5M;G-;(D-/3%5-3C$B72YW:61T:" ](#$T#0H@(" @("!C;VQU;6YS6R)#
M3TQ534XR(ET@/2!N97<@1U))1$-/3%5- 3BAF;W)M+D=2240R*0T*
(" @(" @
M8V]L=6UN<ULB0T],54U.,B)=+F1A=& %,:6YK(#T@9F]R;2YZ86
<Q+G)O=W-E
M="YF:65L9'-;(FYQ(ET-"B @(" @(&-O;'5M;G-;(D-/3%5-3C(B72YE9&ET
M;W)4>7!E(#T@,2 @("\O(%=I<'!R96=L97(-"B @(" @(&-O;'5M;G-;(D-/
M3%5-3C(B72YW:61T:" ](#$R#0H@(" @(" !C;VQU;6YS6R)#3TQ534
XS(ET@
M/2!N97<@1U))1$-/3%5- 3BAF;W)M+D=2240R*0T*
(" @(" @8V]L=6UN<ULB
M0T],54U.,R)=+F1A=& %,:6YK(#T@9F]R;2YZ86
<Q+G)O=W-E="YF:65L9'-;
M(F-N86UE(ET-"B @(" @(&-O;'5M;G-;(D-/3%5-3C,B72YE9&ET;W)4>7!E
M(#T@,2 @(" \O($5I;F=A8F5F96QD#0
H@(" @(" !C;VQU;6YS6R)#3TQ534
XS
M(ETN=VED=&@@/2 Q-PT*(" @(" @:&5I9VAT(#T@-BXP(" [(&QE9G0@/2 R
M+C @.R @=&]P(#T@,3 @.R!W:61T:" ](#<P#0H@("!E;F1W:71H#0H@("!F
M;W)M+G!U<VAB=71T;VXR+G9I<VEB;&4@/71R=64-"B @(')E='5R;@T*#0H@
M("!F=6YC=&EO;B!055-(0E545$].,E]O;D-L:6-K#0H@(" @("!F;W)M+F=R
M:60R+F-O;'5M;G-;(D-/3%5-3C(B72YW:61T:" ](#,X#0H@(" @("!R971U
..<FX-"F5N9&-L87-S#0H`
`
end

Zagrijs Venter

2005-10-24, 8:24 pm

Thanks.

Problem solved.

Zagrijs

"Marc VdB" < wrote

> Hi Zagrijs,
>
>
> No problem <g>
> see the attached form, you will see that it is not a problem of building
> the
> grid on the fly, but rather a problem of column-size.
> If you build the grid without specifying the type of the editorcontrol,
> the
> default is entryfield, while in the designer it is according to the type
> ofthe field-value (in your case spinbox).
> So if you build the grid on the fly and you dont specify the control-type
> and you make the column to narrow, the value can't be seen, but it is
> there.
> Widen the column or make it a spinbox and it will work
>
> HTH Marc
>
> --
> www.vdblogic.de/dbl
> ------
>
>
>



Marc VdB

2005-10-24, 8:24 pm

> Problem solved.

Thanks for the success report...

CU, Marc

--
www.vdblogic.de/dbl
------


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com