jvcoach23 Posted February 11, 2005 Posted February 11, 2005 I'm trying to create a public class within my form1. I'm going to be using it (my goal anyway) inside this class so that I can call this class from a thread.start. Anyway.. when I try to tell my dataset where to get the data from, it give me an error of declaration expected. If I use the same syntax outside of this class, just with my form class it works fine. What am I not understanding and how do I fix it. Public Class TestingClass Dim ds as new DataSet ds = dlPerfmon.spServer(company, server) End Class thanks Quote JvCoach23 VB.Net newbie MS Sql Vet
stustarz Posted February 11, 2005 Posted February 11, 2005 i would imagine it is in this line: ds = dlperfmon.spserver(company, server) Company and server are variable values right? but there is no declaration for these inside inside your class Quote Visit: VBSourceSeek - The VB.NET sourcecode library "A mere friend will agree with you, but a real friend will argue."
jvcoach23 Posted February 11, 2005 Author Posted February 11, 2005 i would imagine it is in this line: ds = dlperfmon.spserver(company, server) Company and server are variable values right? but there is no declaration for these inside inside your class thanks for the replie.. I had tried that already.. something like this. Public Class TestingClass Private mvcServer As String Private mvcCompany As String Public Property vcServer() As String Get Return mvcServer End Get Set(ByVal pvcServer As String) mvcServer = pvcServer End Set End Property Public Property vcCompany() As String Get Return mvcCompany End Get Set(ByVal pvcCompany As String) mvcCompany = pvcCompany End Set End Property 'hold perfmon info Dim vcCategoryName As String Dim vcCounterName As String Dim vcInstance As String Dim intTblPMInstanceId As Integer 'create dataset to hold the perfmon counters to query Dim ds As New DataSet 'create a row container to step through dataset Dim dr As DataRow 'grab the info from dll for the counters to query ds = wsPerfmon.spPMCategoryInfoForOneServer(vcCompany, vcServer) End Class I don't understand the error to know what I'm doing wrong.. hope you have another idea.. thanks shannon Quote JvCoach23 VB.Net newbie MS Sql Vet
Administrators PlausiblyDamp Posted February 11, 2005 Administrators Posted February 11, 2005 You need to put the line ds = dlperfmon.spserver(company, server) inside a method - you cannot execute code like that at the class level. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
jvcoach23 Posted February 11, 2005 Author Posted February 11, 2005 ok.. thanks for the help Quote JvCoach23 VB.Net newbie MS Sql Vet
jvcoach23 Posted February 11, 2005 Author Posted February 11, 2005 I have tried creating a class like this Namespace pf Public Class pfGather Public Sub New() End Sub Public Sub New(ByVal vcCategoryName As String, ByVal vcCounterName As String, ByVal intTblPMInstanceId As Integer, ByVal vcInstance As String) mvcCategoryName = vcCategoryName mvcCounterName = vcCounterName mintTblPMInstanceId = intTblPMInstanceId mvcInstance = vcInstance End Sub Private mvcCategoryName As String Private mvcCounterName As String Private mintTblPMInstanceId As Integer Private mvcInstance As String Public Property vcCategoryName() As String Public Property vcCounterName() As String Public Property vcInstance() As String Public Property intTblPMInstanceId() As Integer End Class End Namespace and Namespace pf Public Class pfGathers Inherits ArrayList Public Sub New() End Sub End Class End Namespace and Imports System.Diagnostics.PerformanceCounter Imports System.Diagnostics.PerformanceCounterCategory Namespace pf Public Class pfGatherMethod Public Function pfGather(ByVal vcServer As String, ByVal vcCompany As String) As pfGathers Dim opfGather As pfGather Dim opfGathers As New pfGathers Dim wsPerfmon As New Performance.Perfmon Dim ds As DataSet ds = wsPerfmon.spPMCategoryInfoForOneServer(vcCompany, vcServer) Dim WithEvents oCounter1 As New PerformanceCounter Dim Counter1 As Integer End Function End Class End Namespace and then I can create the ds. can you give me a quick explination on why this differs..I have my own idea.. but would like to hear from someone who's already banged their head till the light comes on. when i did it like this.. then it doesn't want me to do the dim withevents.. tells me withevents is not valid on a local variable declaration.. but the performancecounter wants it.. so much to learn Quote JvCoach23 VB.Net newbie MS Sql Vet
Administrators PlausiblyDamp Posted February 11, 2005 Administrators Posted February 11, 2005 You cannot use WithEvents on a variable declared with a method body - only at the class level. As to why it now lets you create an instance of ds it's like I said before - you cannot execute code outside of a method body, the assignment you where trying to do needed to be in a method. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.