LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Creating a User Defined Class / Object

I am fairly new to VBA and am working on a project where a simple Object
structure could be useful. Most of my previous scripting has been with php
and javascript, both of which blur the distinction between Classes and
Objects so I am pretty fuzzy on it myself.

With javascript you can define a variable as an Object and simply assign
properties to it:

var myObject = New Object ()
myObject.name = "My Name"

This can be very easy to work with and useful. This is what I have come up
with for a slightly more complex VBA equivalent. If there is a better way to
structure it I would appreciate the feedback.

In a class module called DRec I have:

Option Explicit

Public sf As String
Public tf As String
Public oa As Boolean
Public del As Boolean
Public aso As String
Public codes As String
Public t As String
Public tfa As String
Public ttb As String
Public k As String
Public kfa As String
Public ktb As String
Public m As String
Public mfa As String
Public mtb As String

Sub docc()
MsgBox "DRec Test " & m & " : " & t
End Sub

Then in a standard module I have:

Function docArray(sf As String, Optional tf As String = "", _
Optional oa As Boolean = True, Optional del As Boolean =
True, _
Optional aso As String = "", Optional codes As String =
"", _
Optional t As String = "", Optional tfa As String = "",
Optional ttb As String = "", _
Optional k As String = "", Optional kfa As String = "",
Optional ktb As String = "", _
Optional m As String = "", Optional mfa As String = "",
Optional mtb As String = "" _
) As DRec

Dim ar(1 To 15) As Variant
Dim tRec As DRec
Set tRec = New DRec
tRec.tf = tf
If tf = "" Then tf = sf
tRec.sf = sf
tRec.tf = tf
tRec.oa = oa
tRec.del = del
tRec.aso = aso
tRec.codes = codes
tRec.t = t
tRec.tfa = tfa
tRec.ttb = ttb
tRec.k = k
tRec.kfa = kfa
tRec.ktb = ktb
tRec.m = m
tRec.mfa = mfa
tRec.mtb = mtb
Set docArray = tRec
End Function

Sub testDRec()
Dim v As DRec
Set v = docArray(sf:="Daily Bulletin Folder", codes:="ABC", t:="Daily
Bulletin", m:="emailBody")
v.docc
End Sub

Any pointers to better formulation much appreciated

Andrew
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does one create a delete property of a user defined class? [email protected] Excel Programming 6 June 28th 06 08:12 PM
User-defined type collection in class module Rob[_29_] Excel Programming 2 May 31st 06 06:02 PM
Creating my own user defined function help statements Craig Excel Worksheet Functions 2 February 22nd 06 04:51 PM
User Defined Object help fast reddog9069[_14_] Excel Programming 0 July 27th 05 03:40 PM
Creating a action for a defined object Adrix[_4_] Excel Programming 3 April 22nd 04 07:37 PM


All times are GMT +1. The time now is 08:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"