ZL1Corvette
ZL1Corvette

Reputation: 415

Populate a class and then use it later

I have a class like

Public Class Location
    Public Name As String
    Public Column As Integer
    Public Row As Integer
    Public Occupant As String
End Class

In my code I have a subroutine to fill the class

Sub Populate Location(ByValue coordinate As String)
    Dim Here As New Location
    Here.Location = coordinate.SubString(0,3)
    Here.Column = SomeFunction(coordinate, Gere.location)
    Here.Row = AnotherFunction(coordinate, Here.Column)
    Here.Occupant = ArrayOfOccupant(column, row)
End Sub

All of that is filled in one press of a button. Later I want to click another button and use the Here class to do other things.

What are my options or what do I search for?

Upvotes: 1

Views: 54

Answers (1)

As is, your class object only exists inside that procedure.

Dim Here As New Location    ' variable declaration, instancing
                            ' Scope is this module or form

Sub PopulateLocation(ByValue coordinate As String)
    ' assuming this might get reused, create a new instance
    Here = New Location            

    Here.Location = coordinate.SubString(0,3)
    Here.Column = SomeFunction(coordinate, Here.location)
    Here.Row = AnotherFunction(coordinate, Here.Column)
    Here.Occupant = ArrayOfOccupant(column, row)
End Sub

Other subs in that module will have access to Here because it now has class/module level Scope

Upvotes: 4

Related Questions