| From: sarah cheng | E-mail: shakingmyass@hotmail.com | 1 |
Date: Sunday, November 11, 2001 at 20:54:47
Subject: procedures with parameters
Comments:
I have to implement a program where it will display geometric shapes e.g
squares and triangles.
Here is my code but it doesn't seem to work.
private sub cmddisplay_click()
if optsquare then
drawsquare
else
drawtriangle
endif
end sub
private sub drawsquare()
dim i as integer
frmdraw.show
frmdraw.cls
for i = 1 to 10
frm.print string(20,"*")
next i
end sub
private sub drawtriangle()
dim i as integer
frmdraw.show
frmdraw.cls
for i =1 to 10
frmdraw.print string(10-i," ");
frmdraw.print string(2*i-1,"*")
next i
end sub
When i try to run the program it always say variable not defined.
Could you help me?
Thanks
| From: Martin Allen | E-mail: <No e-mail> | 2 |
Date: Saturday, November 17, 2001 at 15:55:28
Subject: RE: procedures with parameters
Comments:
The error is happening because the optsquare variable in the cmddisplay_click event has not been declared. Declare the variable by typing:
| Dim optsquare As Boolean |
as the first line of the cmddisplay_click event (if optsquare is not meant to be a boolean, then use the correct type e.g. integer). Another way of stopping this error is to remove the Option Explicit line at the beginning of the module. Option Explicit means that all variables need declaring.
You also have the line:
| frm.Print String(20, "*") |
in the drawsquare event, I think that the line should actually read:
| frmdraw.Print String(20, "*") |
This forum is no longer taking new messages or replies since 01 November 2002. The above material is for reference purposes only.
The new Visual Basic 6.0 forum can be found here.