newb Declaration Expected error

M

mp

vb.net 2008 express
new project(copy of old one i'm converting to other use)
I created a class MCSUtil.vb to hold general utility functions that could be
of use in multiple projects
'wanted to move some inline functions that occurred in previous class into a
utility class that could provide code reuse.

I put these lines in another class who wanted to use the utility class
Private m_Util As MCSUtil

'm_Util = new mcsutil

'm_Util.init(true)

if i uncomment either or both of the above two lines i get Declaration
expected



what does that mean?

I thought

Private m_Util As MCSUtil

was a declaration?

thanks mark
 
A

Armin Zingler

mp said:
vb.net 2008 express
new project(copy of old one i'm converting to other use)
I created a class MCSUtil.vb to hold general utility functions that could be
of use in multiple projects
'wanted to move some inline functions that occurred in previous class into a
utility class that could provide code reuse.

I put these lines in another class who wanted to use the utility class
Private m_Util As MCSUtil

'm_Util = new mcsutil

'm_Util.init(true)

if i uncomment either or both of the above two lines i get Declaration
expected



what does that mean?

I thought

Private m_Util As MCSUtil

was a declaration?

thanks mark

There is no executable code outside procedures (=subs/functions).
 
M

mp

Armin Zingler said:
snip


There is no executable code outside procedures (=subs/functions).

Thanks Armin - I just figured that out too.
Had to move it into my .Init function that will start the class
i'm not clear on constuctors in vb.net - do they exist?
where automatic startup code would go?
or do i continue providing an .Init method on classes like i did in vb6 to
initialize beginning state of object?
 
A

Armin Zingler

mp said:
Thanks Armin - I just figured that out too.
Had to move it into my .Init function that will start the class
i'm not clear on constuctors in vb.net - do they exist?
where automatic startup code would go?
or do i continue providing an .Init method on classes like i did in vb6 to
initialize beginning state of object?

Yes, you can use constructors:

In Class MCSUtil:

Sub New(byval value as boolean)
'...
end sub


In the class that uses MCSUtil:

Private m_Util As New MCSUtil(true)


See also:
http://msdn.microsoft.com/en-us/library/2z08e49e.aspx

Maybe of interest:
http://msdn.microsoft.com/en-us/library/3fxtxxwa.aspx
http://msdn.microsoft.com/en-us/library/hks5e2k6.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top