Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help setting up Properties? 1

Status
Not open for further replies.

Ferlin

Programmer
Jan 18, 2001
71
US
Hi All,

I'm trying to use a couple of Arrays in some properties, the problem
I am having is this, when I try to use the properties in my form to set
the Column Start and Column Lengths they are all set to 0. The reason
being that instead of using the Property Let in the .ColStart(?) = ##
the Property Get is being processed, I found this out by steping thru
the code with F8. I was wondering HOW to get around this, is this caused
by the fact that VB6 will not allow you to make an Array Public?

Below is an excerpt of code from the Class and the Form.

----------------------- Class Code (clsExport) --------------
Option Explicit

' clsExport
.
.
.
Private lngColStart() As Long
Private lngColLen() As Long
.
.
.
Public Property Get ColStart() As Variant
ColStart = lngColStart
End Property

Public Property Let ColStart(ByRef v_varColStart As Variant)
ReDim Preserve lngColStart(intNumCols)
lngColStart = v_varColStart
End Property

Public Property Get ColLen() As Variant
ColLen = lngColLen
End Property

Public Property Let ColLen(ByRef v_varColLen As Variant)
ReDim Preserve lngColLen(intNumCols)
lngColLen = v_varColLen
End Property

----------------------- Form Code (frmMain) -----------------
Option Explicit

' frmMain

Dim objExportXcl As New clsExport
.
.
.
objExportXcl.NumCols = 10
.
.
.
objExportXcl.ColStart(2) = 31
objExportXcl.ColLen(2) = 14
objExportXcl.ColStart(3) = 45
objExportXcl.ColLen(3) = 16
.
.
.
objExportXcl.NumCols = 4
.
.
.
objExportXcl.ColStart(2) = 31
objExportXcl.ColLen(2) = 15
objExportXcl.ColStart(3) = 46
objExportXcl.ColLen(3) = 21

-----------------------------------------------------------

Any help would be greatly appreciated, and Thanks In Advance.

Ferlin.
 
lngColStart = v_varColStart
You assigned a variant to an array. I don't know what you mean to do but maybe it should be
lngColStart(intNumCols) = v_varColStart

also, how about
Code:
Public Property Let ColStart(ByRef v_varColStart As Variant)
   if Ubound(lngColstart) <> intNumcols) then 
       ReDim Preserve lngColStart(intNumCols)
   end if     
   lngColStart(intNumCols) = v_varColStart
End Property
End if
 
JohnYingling,

Thanks for the speedy reply. I'm not always the best at making myself clear on my exact problem or situation, so let me see if I can clear it up a little better.

I tried to set up an array as a Property, but when I tried to put Public lngColStart As Long in my Class, the compiler gave me a message that Constants, fixed-length strings, arrays .... and so on not allowed as public members of object modules.

The next thing I tried was to set up my properties as follows:

Private lngColStart() As Long
.
.
.
Public Property Get ColStart() As Long()
ColStart=lngColStart
End Property

Public Property Let ColStart(ByRef v_lngColStart() As Long)
ReDim Preserve lngColStart(intNumCols)
lngColStart=v_lngColStart
End Property

Then in the Form when I had objExportXcl.ColStart(2) = 31
then compiler would tell me cant assign to a ReadOnly Property.

Finally I tried the Code in my original message, it compiles and runs, but with undesired results, all elements of ColStart are 0. I used the F8 key to step thru the run and discovered the program was using the *** Public Property Get *** instead of the Public Property Let when processing the objExportXcl.ColStart(2) = 31 statement.

I hope this clears my situation up a little and makes it more clear as to what I am faced with.

Again Thanks.

Ferlin.
 
Ferlin,
The GET is being called because you INDEXED the property but there is no INDEX defined for the LET.
Let's get away from arrays as properties for now. Try this.
Code:
Private lngColStart() As Long
.
.
.
Public Property Get ColStart(Index as long) as long
' * Return ColStart for the Indexed Column
  ColStart=lngColStart(index)
End Property

Public Property Let ColStart(Byval Index As Long, _
                             byval lngValue as long)
' FIRST PARM is inside () on left side.
' LAST PARM is Right hand side of =
' Set the value of INDEXed Column
    If Index > Ubound(lngColstart) then
        ReDim Preserve lngColStart(Index)
        lngColStart=lngValue
    End if
End Property
 
JohnYingling,

Thanks again, trying your code now.......

Compile Error:

Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, a ParamArray, or an invalid Set final parameter.

I'll have to take a closer look at it and see what's up, maybe I can figure some thing out from there.

Thanks again.

Ferlin.
 
JohnYingling,

Thanks again, you have been an imense help I'm getting much closer now. That solved the Get/Let problem, now I just need to figure out why it is saying subscript out of range on the Ubound(lngColStart).

Index is equal to 2 just as is in my () and lngValue is equal to 31 just like after my = . Just the desired results I needed.

Once again Thanks you have been a tremendous help. I went ahead and cast my vote for a tip master for you in appreciation.

Ferlin.
 
JohnYingling,

By The Way in the let property it needed to be lngColStart(Index)=lngValue instead of lngColStart=lngValue otherwise you hit an cant assign array value error on compile.

Ferlin.
 
JohnYingling,

As you can tell I'm still getting my feet wet with Classes and been with VB steady for only a few months. I put
ReDim lngColStart(0) in my Class_Initialize() routine.

That Solved It.....Yeah......

Thanks for ALL your help.

Ferlin.
 
Put this in your Class_initilize
Redim lngColStart(0)
You may have to use a boolean flag to determine the difference between 0 column (is col 0 valid) and never initialized.
 
JohnYingling,

Bet that couldn't happen again if we tried.... :-D
 
What happened? Is it it working? If so, then NOW you can play with NEW (meaning in addition to) properties that handle an array...that is if an array can be handled as a property in VB and you feel like messin' with it. I'm late responding because my machine (at work) has decided to misbehave on drive C:. I'm due for something bigger than a 48 meg 100mz system.
 
JohnYingling,

I'm the one late responding this time. What happened was we both replied about the ReDim in the Class_Initialize at the same moment, I got a chuckle out of that. The program is working GREAT now thanks to you, don't know what I would do without you? I still have a few more properties and methods to add, but that's par for the course.

Tell your Boss, that I said to get you a 1GHZ processor with at least 256 MEGS of Ram and 100 Gigs of Hard Drive, for a starter any way. :->

Ferlin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top