Re: Not first class in file

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@xxxxxxxxxxxxx> wrote in
message news:%23BlDc6mrGHA.5032@xxxxxxxxxxxxxxxxxxxxxxx
Tom,
I find its "Better" to have each type have its own file. Naming each file
for what it contains. As its then immediately obvious what's in the file
by
looking at the file name. Plus you avoid this warning message.

So if you have 3 types (classes):
| CMailMessage
| EmailPoller (the offending Class)
| Project Installer.

You would have 3 files:|
| EmailPoller.vb
| ProjectInstaller.vb (which is created automatically).
CMailMessage.vb


As the message implies, the "designers" in VS expect the class to be first
type in a file... The Windows Service has a designer as it (EmailPoller)
inherits from ServiceBase which inherits from Component. Component has a
designer associated with it.

But why does it work OK in 2002 but not in 2003?

Tom


--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


"tshad" <tscheiderich@xxxxxxxxxxxxxxx> wrote in message
news:e6$zAUOrGHA.1796@xxxxxxxxxxxxxxxxxxxxxxx
|I have a problem with a VS 2003 project.
|
| This project was designed and works fine in VS 2003.
|
| But trying to open the project I get the following error.
| ************************************************************
| The class EmailPoller can be designed, but is not the first class in the
| file. Visual Studio requires that designers use the first class in the
| file. Move the class code so that it is the first class in the file and
try
| loading the designer again.
| **************************************************************
|
| Not sure why this is a problem. This is a Windows Service I am creating
| with 3 Classes:
|
| CMailMessage
| EmailPoller (the offending Class)
| Project Installer.
|
| There are 2 files:
|
| EmailPoller.vb
| ProjectInstaller.vb (which is created automatically).
|
| In the following code, do I just move the "Class CmailMessage" code to
the
| bottom of the source file?
|
| If that is the case, why?
|
| I didn't have to do that in VS 2002.
|
| The first part of the EmailPoller.vb file is:
| **************************************************
| Imports System.ServiceProcess
| Imports System.Web.Mail
| Imports System.Data.SqlClient
| Imports System.IO
|
| Class CEmailMessage
| Public id As Integer
| Public strTo As String
| Public strCC As String
| Public strBCC As String
| Public strFrom As String
| Public strSubject As String
| Public strBody As String
| Public isHTML As Integer
| Public dateAttempted As Date
| Public status As Integer
| Public errMessage As String
| End Class
|
| Public Class EmailPoller
| Inherits System.ServiceProcess.ServiceBase
| Friend WithEvents cmd_get_poller_settings As
| System.Data.SqlClient.SqlCommand
| Friend WithEvents cmd_update_msg As System.Data.SqlClient.SqlCommand
| Friend WithEvents SqlSelectCommand1 As
System.Data.SqlClient.SqlCommand
| Const ATTEMPTED = 2
| Const SENT = 3
| Dim strProgress As String
|
| #Region " Component Designer generated code "
|
| Public Sub New()
| MyBase.New()
|
| ' This call is required by the Component Designer.
| InitializeComponent()
|
| ' Add any initialization after the InitializeComponent() call
| 'LogInfo("Completed New()")
| End Sub
|
| 'UserService overrides dispose to clean up the component list.
| Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
| If disposing Then
| 'LogInfo("In Dispose()")
| If Not (components Is Nothing) Then
| components.Dispose()
| End If
| End If
| MyBase.Dispose(disposing)
| End Sub
|
| ' The main entry point for the process
| <MTAThread()> _
| Shared Sub Main()
| Dim ServicesToRun() As System.ServiceProcess.ServiceBase
|
| ' More than one NT Service may run within the same process. To
add
| ' another service to this process, change the following line to
| ' create a second service object. For example,
| '
| ' ServicesToRun = New System.ServiceProcess.ServiceBase () {New
| Service1, New MySecondUserService}
| '
| ServicesToRun = New System.ServiceProcess.ServiceBase() {New
| EmailPoller()}
|
| System.ServiceProcess.ServiceBase.Run(ServicesToRun)
| End Sub
|
| 'Required by the Component Designer
| Private components As System.ComponentModel.IContainer
|
| ' NOTE: The following procedure is required by the Component Designer
| ' It can be modified using the Component Designer.
| ' Do not modify it using the code editor.
| Friend WithEvents EmailQueueTimer As System.Timers.Timer
| Friend WithEvents SqlConnection1 As
System.Data.SqlClient.SqlConnection
| Friend WithEvents da_get_messages As
| System.Data.SqlClient.SqlDataAdapter
| <System.Diagnostics.DebuggerStepThrough()> Private Sub
| InitializeComponent()
| Me.EmailQueueTimer = New System.Timers.Timer()
| Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
| Me.da_get_messages = New System.Data.SqlClient.SqlDataAdapter()
| Me.cmd_get_poller_settings = New
System.Data.SqlClient.SqlCommand()
| Me.cmd_update_msg = New System.Data.SqlClient.SqlCommand()
| Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand()
| CType(Me.EmailQueueTimer,
| System.ComponentModel.ISupportInitialize).BeginInit()
|
| 'LogInfo("Init EmailQueueTimer")
| '
| 'EmailQueueTimer
| '
| Me.EmailQueueTimer.Enabled = True
| Me.EmailQueueTimer.Interval = 10000
| '
| 'LogInfo("Init SqlConnection1")
| 'SqlConnection1
| '
| Me.SqlConnection1.ConnectionString = "data source=VENUS;initial
| catalog=FTSolutions;password=web4pay;persist security i" & _
| "nfo=True;user id=ftsweb;workstation id=PROGRAMMER1;packet
| size=4096"
| '
| 'da_get_messages
| '
| Me.da_get_messages.SelectCommand = Me.SqlSelectCommand1
| '
| 'cmd_get_poller_settings
| '
| Me.cmd_get_poller_settings.CommandText =
| "dbo.[COM_GET_EMAIL_QUEUE_SETTINGS_SP]"
| Me.cmd_get_poller_settings.CommandType =
| System.Data.CommandType.StoredProcedure
| Me.cmd_get_poller_settings.Connection = Me.SqlConnection1
| Me.cmd_get_poller_settings.Parameters.Add(New
| System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
| System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.ReturnValue,
| False, CType(10, Byte), CType(0, Byte), "",
| System.Data.DataRowVersion.Current, Nothing))
| '
| 'cmd_update_msg
| '
| Me.cmd_update_msg.CommandText =
| "dbo.[COM_UPDATE_EMAIL_QUEUE_MSG_STATUS_SP]"
| Me.cmd_update_msg.CommandType =
| System.Data.CommandType.StoredProcedure
| Me.cmd_update_msg.Connection = Me.SqlConnection1
| Me.cmd_update_msg.Parameters.Add(New
| System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
| System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.ReturnValue,
| False, CType(10, Byte), CType(0, Byte), "",
| System.Data.DataRowVersion.Current, Nothing))
| Me.cmd_update_msg.Parameters.Add(New
| System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.Int, 4,
| System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0,
| Byte), "", System.Data.DataRowVersion.Current, Nothing))
| Me.cmd_update_msg.Parameters.Add(New
| System.Data.SqlClient.SqlParameter("@status",
System.Data.SqlDbType.TinyInt,
| 1, System.Data.ParameterDirection.Input, False, CType(3, Byte), CType(0,
| Byte), "", System.Data.DataRowVersion.Current, Nothing))
| Me.cmd_update_msg.Parameters.Add(New
| System.Data.SqlClient.SqlParameter("@date_attempted",
| System.Data.SqlDbType.DateTime, 8))
| Me.cmd_update_msg.Parameters.Add(New
| System.Data.SqlClient.SqlParameter("@error_message",
| System.Data.SqlDbType.VarChar, 100))
| '
| 'SqlSelectCommand1
| '
| Me.SqlSelectCommand1.CommandText =
| "dbo.[COM_GET_EMAIL_QUEUE_MESSAGES_SP]"
| Me.SqlSelectCommand1.CommandType =
| System.Data.CommandType.StoredProcedure
| Me.SqlSelectCommand1.Connection = Me.SqlConnection1
| Me.SqlSelectCommand1.Parameters.Add(New
| System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
| System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.ReturnValue,
| False, CType(10, Byte), CType(0, Byte), "",
| System.Data.DataRowVersion.Current, Nothing))
| Me.SqlSelectCommand1.Parameters.Add(New
| System.Data.SqlClient.SqlParameter("@quantity",
System.Data.SqlDbType.Int,
| 4, System.Data.ParameterDirection.Input, False, CType(10, Byte),
CType(0,
| Byte), "", System.Data.DataRowVersion.Current, Nothing))
| '
| 'EmailPoller
| '
| Me.CanPauseAndContinue = True
| Me.ServiceName = "EmailPoller"
| CType(Me.EmailQueueTimer,
| System.ComponentModel.ISupportInitialize).EndInit()
|
| End Sub
|
| #End Region
|
| Protected Overrides Sub OnStart(ByVal args() As String)
| 'LogInfo("EmailPoller Started")
| EmailQueueTimer.Start()
| End Sub
|
| Protected Overrides Sub OnStop()
| 'LogInfo("EmailPoller Stopped")
| EmailQueueTimer.Stop()
| End Sub
|
| Private Sub EmailQueueTimer_Elapsed(ByVal sender As System.Object,
ByVal
| e As System.Timers.ElapsedEventArgs) Handles EmailQueueTimer.Elapsed
| 'LogInfo("EmailPoller Timer Interval")
| PollAndSendEmail()
| End Sub
|
| Private Sub PollAndSendEmail()
| Try
| 'LogInfo("PollAndSend() Starting")
|
| Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
| Dim isHTML, intInterval, intMsgQuantity, intProcessMessages
As
| Integer
| Dim DR As SqlDataReader
|
| ' grab our poller/email settings from DB
| strProgress = "About to open connection"
| dbOpenConnection()
|
| strProgress = "About to execute the reader"
|
| ***************************************************
|
| Thanks,
|
| Tom
|
|




.



Relevant Pages

  • Re: Need to add domain user to local group
    ... Public Sub New ... Friend WithEvents txtLoginName As System.Windows.Forms.TextBox ... Dim c As Control ... Private Overloads Function AddUser(ByVal sUsername As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Not first class in file
    ... Public strTo As String ... Friend WithEvents cmd_update_msg As System.Data.SqlClient.SqlCommand ... ' This call is required by the Component Designer. ... Protected Overloads Overrides Sub Dispose ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Not first class in file
    ... Public strTo As String ... Friend WithEvents cmd_update_msg As System.Data.SqlClient.SqlCommand ... ' This call is required by the Component Designer. ... Protected Overloads Overrides Sub Dispose ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Not first class in file
    ... Public strTo As String ... Friend WithEvents cmd_update_msg As System.Data.SqlClient.SqlCommand ... ' This call is required by the Component Designer. ... Protected Overloads Overrides Sub Dispose ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Not first class in file
    ... Because a Delegate tends to be a single line, does it really make sense to ... |> designer associated with it. ... |> | Public strTo As String ... |> | Public Sub New ...
    (microsoft.public.dotnet.languages.vb)