• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Access class in another function

Let me preface this by I am pretty new to VB.

Is it possible to create a new class reference in one function and access it in another?

For example



 
Namespace Buildit
    Public Class testClass
    
    Public Function Start () 
      Dim DB as New my.refclass
      DB.OPEN("my","params") 'opens correctly as it should
      DB.ADD("values") 'adds values correct as it should
    return "test"
End Function
    '--the above code works, I can reference the class and opens and adds with no problem.
    '-- but what I would like to be able to do is reference that already open DB in another function
   
    Public Function AddMore()
      DB.ADD("values) 'something similar to this to access that already open DB
   return ""
End Function

End Class
End Namespace

Open in new window

0
Rock_Lobster
Asked:
Rock_Lobster
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You have to move the "DB" variable up to CLASS LEVEL SCOPE:
    Public Class testClass

        Private DB As My.refclass ' <----- out here it will be accessible to everything in the class

        Public Function Start()
            DB = New My.refclass
            DB.OPEN("my", "params") 'opens correctly as it should
            DB.ADD("values") 'adds values correct as it should
            Return "test"
        End Function
        '--the above code works, I can reference the class and opens and adds with no problem.
        '-- but what I would like to be able to do is reference that already open DB in another function

        Public Function AddMore()
            DB.ADD("values) 'something similar to this to access that already open DB
            Return ""
        End Function

    End Class

Open in new window

0
 
Rock_LobsterAuthor Commented:
worked like a champ, thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now