Windows Develop Bookmark and Share   
 index > Windows Forms General > Issues with the error"...frmTest is a type in 'PPL' and cannot be used as an expression."
 

Issues with the error"...frmTest is a type in 'PPL' and cannot be used as an expression."

Hi there,

This may be a really simple answer. I have got the following error.

'frmTest' is a type in 'PPL' and cannot be used as an expression.

when I click on the error it shows this code:

Code Snippet

Namespace My

'NOTE: This file is auto-generated; do not modify it directly. To make changes,

' or if you encounter build errors in this file, go to the Project Designer

' (go to Project Properties or double-click the My Project node in

' Solution Explorer), and make changes on the Application tab.

'

Partial Friend Class MyApplication

<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _

Public Sub New()

MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)

Me.IsSingleInstance = false

Me.EnableVisualStyles = true

Me.SaveMySettingsOnExit = true

Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses

End Sub

<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _

Protected Overrides Sub OnCreateMainForm()

Me.MainForm = Global.PPL.frmTest

End Sub

End Class

End Namespace

I use a subMainModule to start my project as so:

Code Snippet

Module SubMainModule

Public db As New PPLDataContext()

Public Sub Main()

' Create an instance of the Form

Dim clLINQ As New clientsLINQ

Dim personalLedger As New frmTest(clLINQ)

personalLedger.Show()

Application.Run()

End Sub

End Module

The form I am using here is as follows:

Code Snippet

Public Class frmTest

Private clientLINQ As clientsLINQ

Public Sub New(ByRef clLINQ As Object)

InitializeComponent()

clientLINQ = clLINQ

End Sub

Private Sub btnAccounts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccounts.Click

Dim accountsDisplay As New frmAccountsDisplay()

'Open the form as a dialog.

accountsDisplay.ShowDialog(Me)

End Sub

Private Sub btnCLients_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCLients.Click

Dim ClientDisplay As New frmClientsDisplay(clientLINQ)

'Open the form as a dialog.

ClientDisplay.ShowDialog(Me)

End Sub

End Class

Whats causing this error??

Simon

ss2030  Monday, October 27, 2008 4:56 AM
The problem seems to be at this line:
Me.MainForm = Global.PPL.frmTest

On the left hand side of an equation mark there should be and expression and NOT a type.
Just like the error noted, frmTest is a type (it is a class that represents the form).
I guess what you should have done is create an instance of frmTest and assign the instance to Me.MainForm.

hth,
Lior.
Lior Salem  Monday, October 27, 2008 6:56 AM
Odd problem, have you been tinkering with the project settings? Your code suggests that you really want to run Sub Main() to start your program. Project + Properties, Application tab. Turn off the "Enable application framework" checkbox, then change Startup form to "Sub Main".
nobugz  Monday, October 27, 2008 3:08 PM
The problem seems to be at this line:
Me.MainForm = Global.PPL.frmTest

On the left hand side of an equation mark there should be and expression and NOT a type.
Just like the error noted, frmTest is a type (it is a class that represents the form).
I guess what you should have done is create an instance of frmTest and assign the instance to Me.MainForm.

hth,
Lior.
Lior Salem  Monday, October 27, 2008 6:56 AM
Odd problem, have you been tinkering with the project settings? Your code suggests that you really want to run Sub Main() to start your program. Project + Properties, Application tab. Turn off the "Enable application framework" checkbox, then change Startup form to "Sub Main".
nobugz  Monday, October 27, 2008 3:08 PM

Hi Hans

In the end I removed the entire section including subMainModule() and the start form and then recreated it.... for some reason it worked. I did want to make it start at the sub Main class and having done this it worked. Fortunately it was not to much work to fix.

Cheers

Simon

ss2030  Tuesday, October 28, 2008 12:28 PM
I realize this is an old thread, but the root cause of the issue was never addressed. This issue is usually caused by creating a constructor for the form with 'Private' scope, ("Private Sub New()...").
Change the scope of the constructor to Public and you'll be able to designate the form as the startup form.
LRoberts  Tuesday, September 15, 2009 1:35 PM

You can use google to search for other answers

Custom Search

More Threads

• Database and DateTimePicker
• Acessing Control Between Forms
• How to use IXMLDocument in C#?
• Running System Tray Application Prevents Computer Shutdown
• remoting/web services book
• Line numbers in datagridview column and datagridview column manual edit!
• Delayed Sending of an Email
• insert date into oracle database
• Is there a control object for storing a mixture of text and images in columns?
• Multi language help please