Board index » Visual Studio » Variable Declaration

Variable Declaration

Visual Studio377
Hi,



Running VB6 SP5 on WinXP Pro. In a fairly large project (10MB exe) I have

noticed lately that the computer runs with undeclared variables. I have the

'Require Variable Declaration' check box checked in the Options dialog. And

I have the 'Option Explicit' statement at the head of every module in

question. I have noticed this maybe three or four times in the last 6

months. Today I find I have a string array var 'strChildren' which I have

been using right along and there is no declaration for it. I checked the

history in Source Safe and it has never been declared.



This is a little scary. I'm wondering if anyone else has noticed it.



Thanks.



Artie


-
 

Re:Variable Declaration

"Artie Fufkin" <stephenprescott@msn.com>wrote in message

Quote
Hi,



Running VB6 SP5 on WinXP Pro. In a fairly large project (10MB exe) I have

noticed lately that the computer runs with undeclared variables. I have

the 'Require Variable Declaration' check box checked in the Options

dialog. And I have the 'Option Explicit' statement at the head of every

module in question. I have noticed this maybe three or four times in the

last 6 months. Today I find I have a string array var 'strChildren' which

I have been using right along and there is no declaration for it. I

checked the history in Source Safe and it has never been declared.



This is a little scary. I'm wondering if anyone else has noticed it.



Thanks.



Artie



Are you using any "GlobalMultiUse" classes? Place your cursor over that

variable and hit Shift-F2



--

Ken Halter - MS-MVP-VB - www.vbsight.com">www.vbsight.com

Sign up now to help keep VB support alive - classicvb.org/petition">classicvb.org/petition

Please keep all discussions in the groups..





-

Re:Variable Declaration



"Artie Fufkin" <stephenprescott@msn.com>wrote in message

Quote
Hi,



Running VB6 SP5 on WinXP Pro. In a fairly large project (10MB exe) I have

noticed lately that the computer runs with undeclared variables. I have

the

'Require Variable Declaration' check box checked in the Options dialog.

And

I have the 'Option Explicit' statement at the head of every module in

question. I have noticed this maybe three or four times in the last 6

months. Today I find I have a string array var 'strChildren' which I have

been using right along and there is no declaration for it. I checked the

history in Source Safe and it has never been declared.



This is a little scary. I'm wondering if anyone else has noticed it.





Never noticed such a thing. There are only 2 guesses that I have.



1. Are you SURE Option Explicit appears at the top of the module. If the

module was already in a project, did not have Option Explicit and you then

check Require Variable Declarations, this does NOT add Option Explicit to

that module. Only new modules added via a template will have it. IOW, if

the module was added via Add File, Option Explicit still won't be

automatically added.



2. Are you SURE the variable is not declared at a higher scope? For

example, maybe it's global in a different module? What happens if you put

the insertion point within the variable name and press Shft+F2?



--

Mike

Microsoft MVP Visual Basic





-

Re:Variable Declaration

10MB compiled EXE is pretty large and I'm sure there are methods and

variables that are long forgotten...



Check out MzTools and the 'Review Source Code' feature that will help

identify things for you - help determine things that are no longer used.

www.mztools.com



--

Chris Hanscom - Microsoft MVP (VB)

Veign's Resource Center

www.veign.com/vrc_main.asp">www.veign.com/vrc_main.asp

--



"Artie Fufkin" <stephenprescott@msn.com>wrote in message

Quote
Hi,



Running VB6 SP5 on WinXP Pro. In a fairly large project (10MB exe) I have

noticed lately that the computer runs with undeclared variables. I have

the

'Require Variable Declaration' check box checked in the Options dialog.

And

I have the 'Option Explicit' statement at the head of every module in

question. I have noticed this maybe three or four times in the last 6

months. Today I find I have a string array var 'strChildren' which I have

been using right along and there is no declaration for it. I checked the

history in Source Safe and it has never been declared.



This is a little scary. I'm wondering if anyone else has noticed it.



Thanks.



Artie









-

Re:Variable Declaration

First of all thanks everyone. I did all the tests you suggested and the it

is indeed an undeclared var.



It appears that VB will let you ReDim an undeclared variable even if you

have the Option Explicit statement and that's what was happening.



You can make a new VB project with Option Explicit and put this and this

only in a button event handler:



ReDim i(0)

i(0) =1

MsgBox i(0)



It will run. At least it runs on my machine.





-

Re:Variable Declaration

"Artie Fufkin" <stephenprescott@msn.com>wrote in message

Quote


It appears that VB will let you ReDim an undeclared variable even if you

have the Option Explicit statement and that's what was happening.





ReDim i(0)

i(0) =1

MsgBox i(0)



It will run. At least it runs on my machine.



That's correct... it confuses people quite a bit... ReDim is Dim though so,

technically, it's declared.



--

Ken Halter - MS-MVP-VB - www.vbsight.com">www.vbsight.com

Sign up now to help keep VB support alive - classicvb.org/petition">classicvb.org/petition

Please keep all discussions in the groups..





-