[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Access class in another function

Posted on 2009-12-30
2
Medium Priority
?
164 Views
Last Modified: 2013-11-25
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
Comment
Question by:Rock_Lobster
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 26151484
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
 

Author Comment

by:Rock_Lobster
ID: 26153573
worked like a champ, thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question