Re: Global Variable in Class

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



Now I'm confused. Do you want the variable to be in the function (no data is saved across function calls), or do you want the variable outside of the function (dad is saved across function calls)?

If you want the variable inside the function, just declare it in the function:

Public Class dataClass
  Public Shared Function GetRep(ByVal prodNumber As Integer) As DataSet
        Dim ProdName as String
	'do stuff with ProdName - value is lost at end of function
  End Function
End Class

If you want the variable outside the function, just declare it outside of the function (but make sure to add the Shared modifier so it is available to Shared functions):


Public Class dataClass Private Shared ProdName as String Public Shared Function GetRep(ByVal prodNumber As Integer) As DataSet 'do stuff with ProdName ' value is still available after function End Function End Class



Joe via DotNetMonster.com wrote:
Thanks for the reply. I have declared the function as shared. How would I
define the variable within the function?

.



Relevant Pages

  • How to use API calls in VS2005 for printing
    ... Public WriteOnly Property _DocumentNameAs String ... Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr) As Boolean ... Dim hPrinter As IntPtr ' The printer handle. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: How to print like the old ways
    ... Public pDocName As String ... Public Shared Function OpenPrinter(ByVal src As String, ByRef hPrinter As IntPtr, ByVal pd As Long) As Boolean ... Dim dwWritten As Int32 ' The number of bytes written by WritePrinter. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: (vb2005) I need your help for using "Rasapi32.dll"
    ... Declare Function RasGetEntryDialParams Lib "rasapi32.dll" Alias ... "RasGetEntryDialParamsA" (ByVal lpcstr As String, ... Private Declare Function InternetDial Lib "wininet.dll" Alias ... Public Shared Function InternetDial(ByVal hWndParent As IntPtr, ...
    (microsoft.public.dotnet.languages.vb)
  • BC30518: Overload resolution failed because no accessible ToString can be called with these argument
    ... Microsoft Visual Basic .NET Compiler version 7.10.6310.4 ... 'Public Shared Function ToString(value As String) As String': ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Findwindow Question
    ... > String) as IntPtr ... Public Class Form1 ... Private Sub Form1_Load ... Public Shared Function FindWindow(ByVal lpClass As String, ...
    (microsoft.public.dotnet.framework.compactframework)