Home All Groups Group Topic Archive Search About

'Form1' is a type in 'XXX.Module1' and cannot be used as an expression.

Author
14 Nov 2007 1:36 PM
Anonymous
I have this error when I try buiding a VB project:

Error    1    'Form1' is a type in 'XXX.Module1' and cannot be used as an
expression.    C:\code\vbstuff\Form1.vb    0    0

I am a C++ programmer and have played with VB6 in the past, but it seems
a lot has changed since then.

The worst thing (read most annoying thing) about this error is that the
line number is given as 0, so I have absolutely no idea as to what is
causing it.

Anyone knows how to fix this? BTW, the fix proposed by the article in
the MS knowledgebase does not really address this issue - at least, It
did not fix the issue when I followed the instructions.

Author
14 Nov 2007 2:09 PM
Scott M.
It sounds like you are using a type, where an instance is required.  Check
your code for references to "Form1" and ensure that before your use that
term, you have an instatiated object with that name.


Show quoteHide quote
"Anonymous" <no.re***@here.com> wrote in message
news:wfednQ6STZz2Z6faRVnytAA@bt.com...
>I have this error when I try buiding a VB project:
>
> Error 1 'Form1' is a type in 'XXX.Module1' and cannot be used as an
> expression. C:\code\vbstuff\Form1.vb 0 0
>
> I am a C++ programmer and have played with VB6 in the past, but it seems a
> lot has changed since then.
>
> The worst thing (read most annoying thing) about this error is that the
> line number is given as 0, so I have absolutely no idea as to what is
> causing it.
>
> Anyone knows how to fix this? BTW, the fix proposed by the article in the
> MS knowledgebase does not really address this issue - at least, It did not
> fix the issue when I followed the instructions.
Are all your drivers up to date? click for free checkup

Author
29 Nov 2007 11:15 AM
Andrew Bingham
I have had this before and it seems to be a "gotcha" of the form auto-code
generation and  the form "compiler"/designer  which does loads of stuff
"behind your back".

So  - make sure the form has a default constructor ?

If you created your own constructor e.g.

    Public Sub New(ByVal value As string)
        InitializeComponent()
    End Sub

Then the form needs the default construtor:
Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

The gotcha for me was that I used the entity-method dropdowns in VS IDE  to
add a "New" method and then EDITED the signature (added parameter) as above
and the form no longer had a default New constructor.
Author
29 Nov 2007 2:54 PM
Brian Gideon
On Nov 14, 7:36 am, Anonymous <no.re***@here.com> wrote:
Show quoteHide quote
> I have this error when I try buiding a VB project:
>
> Error   1       'Form1' is a type in 'XXX.Module1' and cannot be used as an
> expression.     C:\code\vbstuff\Form1.vb        0       0
>
> I am a C++ programmer and have played with VB6 in the past, but it seems
> a lot has changed since then.
>
> The worst thing (read most annoying thing) about this error is that the
> line number is given as 0, so I have absolutely no idea as to what is
> causing it.
>
> Anyone knows how to fix this? BTW, the fix proposed by the article in
> the MS knowledgebase does not really address this issue - at least, It
> did not fix the issue when I followed the instructions.

Can you post a short program demonstrating the problem?

Bookmark and Share