Class Variables

colboy

Member
Licensed User
Longtime User
Am I right in thinking that to read and assign each variable in a class, I have to write a subroutine to get and put? So in VB.NET I would do :

B4X:
Public Class objProduct
    Public SysProductId As String
    Public SysSkuId As Integer
    Public ProductNumber As String
    Public ProductName As String
    Public QuantityPerPack As Integer
    Public UICSeed As Integer
    Public LabelSize As Integer
    Public Active As Integer
    Public XSL As Integer
    Public MSL As Integer
    Public ROQ As Integer
    Public Cost As Decimal
    Sub initialize()
        Clear()
    end sub
    Sub Clear()
        SysProductId = ""
        SysSkuId = -1
        ProductNumber = ""
        ProductName = ""
        QuantityPerPack = 1
        UICSeed = 100000
        LabelSize = 0
        Active = 1
        XSL = 0
        MSL = 0
        ROQ = 0
        Cost = 0
    End Sub
End Class

and in my main code I can do

dim lProduct as new objProduct

and then happily read and set the variables like

lProduct.XSL=0
etc.

But it doesn't seem to be the way Classes work in B4A. Just want to make sure I don;t do lots of extra work if I don't have too.

Thanks, Colin
 

colboy

Member
Licensed User
Longtime User
Roger, the sample I gave was for VB.NET. I want to be able to access the properties by their name, rather than a subroutine that returns the name. This is my Patient object.

B4X:
'Class module
Sub Class_Globals
   Private SysPatientId As String
   Private NameFull As String
   Private Add1 As String
   Private Add2 As String
   Private Add3 As String
   Private City As String
   Private Province As String
   Private PostCode As String
   Private Telephone As String
   Private TimeStamp As Long
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(pSysPatientId As String, pNameFull As String, pAdd1 As String, pAdd2 As String, pAdd3 As String, pCity As String, pProvince As String,pPostCode As String, pTelephone As String, pTimeStamp As Long)
   SysPatientId=pSysPatientId
   NameFull=pNameFull 
   Add1=pAdd1 
   Add2=pAdd2 
   Add3=pAdd3 
   City=pCity 
   Province=pProvince  
   PostCode=pPostCode  
   Telephone=pTelephone
   TimeStamp=pTimeStamp
End Sub

Public Sub GetPatientId As String
   Return SysPatientId
End Sub

Public Sub GetNameFull As String
   Return NameFull
End Sub

Public Sub GetAddress As String
   Dim lAddress As String
   lAddress=Add1 & ", " & City & ", " &Province
   Return lAddress
End Sub

in my main program I define the object.

B4X:
Dim gPatient As objPatient
gPatient.Initialize("100000", "Colin Meeks","1768 Stonehenge Crescent","","","Ottawa","Ontario","K1V 8T4","613 555 2636",DateTime.DateParse("07/25/2012"))

I want to be able to do something like

B4X:
dim lId as string
lId=gPatient.SysPatientId

rather than have to define a sub routine for assigning to and getting the value from the property.

Colin
 
Upvote 0
Top