How to convert a code from VB.Net to VBA Ms access

Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc used Ask the Experts™
on
Dear Experts;

I would like to convert the code below from VB.Net to VBA in Ms Access, any idea?

Public Class details
        Public Property ProductId As Integer
        Public Property Description As String
        Public Property SpecialCode As String
        Public Property Quantity As Integer
        Public Property UnitPrice As Integer
        Public Property Rebates As Integer
        Public Property Tax As String()
        Public Property TotalAmount As Integer
        Public Property TaxInclusive As Boolean
        Public Property FinalPrice As Integer
    End Class

    Public Class Range
        Public Property SerialNumber As String
        Public Property Date As String
        Public Property TransactionType As Integer
        Public Property PaymentMode As Integer
        Public Property Sale As Integer
        Public Property Order As String
        Public Property Clerk As String
        Public Property TaxID As String
        Public Property BuyerName As String
        Public Property AccountName As String
        Public Property Address As String
        Public Property Tel As String
        Public Property InvoiceCode As String
        Public Property InvoiceNumber As String
        Public Property Items As Item()
    End Class

Open in new window


Regards

Chris
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer

Commented:
Just use VBA class. : http://www.cpearson.com/excel/classes.aspx
e.g.
Dim pSerialNumber As String
Public Property Get SerialNumber () As String
    SerialNumber = pSerialNumber 
End Property
Public Property Let SerialNumber (Value As String)
    pSerialNumber = Value
End Property

Open in new window

Kindly use the actual codes I know you have an answer to this , but I'm not able to follow properly.

Just use the data provided, remember there are two code pieces above.

Regards

Chris
Software & Systems Engineer
Commented:
Just cope paste each property like the one i showed you
e.g (2nd)
Insert Class Module : Details
Dim pProductId  as Integer  ' If you see the code in .NET it has a similar "writing"
Public Property Get ProductId   () As Integer ' Here we get the Value Stored in The Property
    ProductId   = pProductId  
End Property
Public Property Let ProductId   (Value As Integer)   'Here we set the Property to the Value we are "setting"
    pProductId  = Value
End Property

Open in new window

So in the end it would something like this in a module that uses this class:
Public Function test()
Dim cdetails As New Details
cdetails.ProductId = 12333
MsgBox cdetails.ProductId
End Function

Open in new window

SideNote: I made error mixing .NET/VBA in my 1st post so i will make a slight change/fix
ste5anSenior Developer

Commented:
Without knowing what your goal it, it would mean to do your actual work..

You create a class in the VBA IDE:

Untitled.pngThis is independent of your used application.

In the class module you need to create a setter and getter for each property. Each property needs a backing field.

Private m_PropertyBackingField As String

Public Property Get PropertyName() As String

  PropertyName = m_PropertyBackingField
  
End Property

Public Property Let PropertyName(AValue As String)

  m_PropertyBackingField = AValue
	
End Property

Open in new window


Thus you need to create two such files and populate them. The actual patter is (e.g. your details class):

Private m_Description As String
Private m_ProductId As Long

Public Property Get Description() As String

  Description = m_Description
  
End Property

Public Property Let Description(AValue As String)

  m_Description = AValue
	
End Property

Public Property Get ProductId() As Long

  ProductId = m_ProductId
  
End Property

Public Property Let ProductId(AValue As Long)

  m_ProductId = AValue
	
End Property

Open in new window


BUT: In many cases in VBA where classes are DTO's you just use a type instead:

Public Type DetailType
  
  Description As String
  ProductId As Long
  
End Type

Open in new window


CAVEAT: (I'm pretty sure, I told you that already..)
Don' t use Integer as long as you don't have an explicit requirement. It only stores values from -32768-32767. Use Long.
Using Long instead of Integer should be a reflex.
John TsioumprisSoftware & Systems Engineer

Commented:
Edit: It seems the VBE complained about starting the variable with Unserscore (_)...i use it in NET
So change the Dim to Private ...although i think it doesn't matter too much.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial