|
-
March 27th, 2001, 06:12 AM
#1
why cannot work?
hi
hope some one can help.
After running the code below i always can this run-time error '91', Object Variable or with block variable not set
why is that so?
private function myfn() as integer
dim i as integer
i = 1
if i = 1 then
fn = 0
msgbox ("0",)
else if i = 3 then
fn = 2
end if
end function
private sub mysub ()
dim abc as integer
abc = myfn
if abc = 1 then
msgbox "error:", , "debug"
elseif abd = 2 then
exit sub
end if
end sub
after 0 was printed out , the error message came out.
thank you!
-
March 27th, 2001, 06:30 AM
#2
Re: why cannot work?
You should always include
option Explicit
as the first line in any module, form or class.
This forces you to declare variables before using them and the compiler would pick up the fact that you have decl;ared your function using the name "myfn" but tried to use "fn" to set it.
The corrected version is:
private function myfn() as integer
dim i as integer
i = 1
if i = 1 then
myfn = 0
msgbox ("0",)
else if i = 3 then
myfn = 2
end if
end function
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|