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!

error.. variable not found though variable is existing....

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
585
PH
hi everybody.... I have these excerpts code in my program which is already running.... everything is running, except that when i click a grid on the form it says "VARIABLE H not found" i've been going the codes for some quite some time... almost a day to be exact, but i cannot solve the problem... may i ask help.... thanks....

PROCEDURE oButton2.Click

h = ALLTRIM(MyDataB.idnum)

SELECT 2

SEEK H

IF thisform.text41.value = 1

for i=1 to 10

m.deyta = "P"+transform(m.i)

IF &deyta=0
replace &deyta with thisform.text30.value
MESSAGEBOX("Chereret!",0,"Cheret")
EXIT
ENDIF

IF i = 10
MESSAGEBOX("No more Field to record !",0,"Cheret")
ENDIF

NEXT

thisform.oGrid1.refresh()
thisform.oGrid2.refresh()
thisform.oGrid3.refresh()
thisform.oGrid4.refresh()
thisform.oGrid5.refresh()

ENDIF
 
Mandy, you have shown us the code in your oButton2. But you say that the error occurs when you click in a grid. The error must therefore be triggered by some code in the grid. You should check the code in all the relevant events, such as the Click, When, Gotfocus, etc. for the grid, its columns and the controls within the columns. Look for any code that references the variable H. Let us know what you find.

By the way, H is not a sensible name for a variable, as it conflicts with the built-in aliases for the first ten work areas (areas A to J). It's unlikely that that is causing your problem, but it is probably not helping.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I agree with Mike about the H variable and I would advise never to use one letter variables (A-Z).

A long time ago I had a problem with the variable T that behaved erratic and I couldn't solve the problem.
Than I changed it to TT and everything worked just fine. I had the feeling that T, like A-J, had an internal function that conflicted with my variable T. So don't gamble and always use variables consisting of more than one character.

 
Thank you Mike and Jack.... I'll try to change my variable H...
 
Hi... i've changed my single letter variable h to "ayde" but still it looks for the ayde variable everytime i click on any grid on my form... heres my code, help me check it please... thanks...

PROCEDURE combo1.click()

AYDE = ALLTRIM(MyDataB.idnum)

SELECT 1

SEEK AYDE

IF FOUND()

thisform.oGrid2.RecordSource = SPACE(0)

SELECT P1,P2,P3,P4,P5,P6,P7,P8,P9,P10 FROM PAYments WHERE idnum = ayde INTO CURSOR MyTui
thisform.oGrid2.RecordSource = "MyTui"

thisform.oGrid3.RecordSource = SPACE(0)

SELECT BACK1,BACK2,BACK3,BACK4,BACK5 FROM PAYMENTS WHERE idnum = ayde INTO CURSOR MyBack
thisform.oGrid3.RecordSource = "MyBack"

thisform.oGrid4.RecordSource = SPACE(0)

SELECT BOOK1,BOOK2,BOOK3,BOOK4,BOOK5 FROM PAYMENTS WHERE idnum = ayde INTO CURSOR MyBooks
thisform.oGrid4.RecordSource = "MyBooks"

thisform.oGrid5.RecordSource = SPACE(0)

SELECT UNI1,UNI2,UNI3,UNI4,UNI5 FROM PAYMENTS WHERE idnum = ayde INTO CURSOR MyUni
thisform.oGrid5.RecordSource = "MyUni"

ENDIF

ENDPROC
 
Mandy, as I mentioned earlier, using a single-letter variable name in this way was unlikely to be the cause of the error. Rather, it is good practice to avoid it, for the reasons that both Jack and I mentioned.

Let's go back to my other suggestion - that you show us the code in your grid, and in the columns and contained objects within the grid. So what is Combo1? The name suggests that it is a combo box?

It would be helpful if you could also let us know which line of code is triggering the error. If you don't know how to find that, just run the program until the error appears. Then, in the Cancel / Suspend / Ignore dialogue, click Suspend. Then open the Debugger (for example, by typing DEBUG in the command window). In the Trace window, the little yellow arrow on the left of the screen will be pointing to the offending line.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You should also learn about variable scoping. A variable you set somewhere is mainly only available in that single method or event or prg, not in oother events, methods, etc. Vriables are private by default, which is already a larger scope than local. Yet, it only means called code can also see H or now AYDE. If you click on a grid you trigger events, which Mike mentioned, and within these H or AYDE doesn't exíst.

If you want something available to any code, event or method in a form, make that a form property, not a variable.


Chriss
 
Thank Chris, Mike & Jack.... The error is no longer appearing... I did not use any variable... and it worked!!! thanks everyone for helping me.... God Bless....


SEEK ALLTRIM(MyDataB.idnum)
 
Well, strange. if it really just about this code, it should not be triggered by a click on any grid, as Mike already mentioned.

Chriss
 
I'm glad to hear it's working. But, if I was in this situation, I would not leave it at that. I would want to know what caused the error in the first place. There must have been something wrong in the code at some point, and I would want to know what that was - if only to know if it is likely to happen again.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi mike and Chris.... Yes mike i tried looking for the errors, almost two days before i posted for answers here... but i really can't.... sigh... but you always give me answers to every questions i give.... thank you so much....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top