Banging My Head Against the Wall on Returning values from a class

twcaddell

Registered User.
Local time
Today, 00:09
Joined
Apr 8, 2013
Messages
31
:banghead:
As the title states, I have hit the wall. I have two class variables (both arrays) among about 10 other class variables, that are not returning any values but "" for the string or #12:00:00AM" for a date. Here are my class variables:
Code:
'UPSData Class Module
Private p_LetterArray() As String
Private p_date() As Date
Private p_LetterArraySize As Integer

My Properties
Code:
'Properties
Public Property Get LetterArray(index As Integer) As String
    LetterArray(index) = p_LetterArray(index)
End Property
 
Public Property Let LetterArray(index As Integer, NewValue As String)
        p_LetterArray(index) = NewValue
End Property
 
Public Property Get UPSDate(index As Integer) As Date
    UPSDate(index) = p_date(index)
End Property
 
Public Property Let UPSDate(index As Integer, NewValue As Date)
    p_date(index) = NewValue
End Property
 
Public Property Get LetterArraySize() As Integer
    LetterArraySize = p_LetterArraySize
End Property
 
Public Property Let LetterArraySize(ByVal vNewValue As Integer)
    p_LetterArraySize = vNewValue
    ReDim p_LetterArray(p_LetterArraySize) As String 'value of  the  p_LetterArraySize is dimension of the two arrays 
 
    ReDim p_date(p_LetterArraySize) As Date

And my test code:
Code:
'test code
Sub test()
Dim tmp As UPSData
Dim tLet As String
Dim tDate As Date
    Set tmp = New UPSData
    tmp.LetterArraySize = 0  '1 dimenional array of 1 value (zero based)
    tmp.LetterArray(0) = "src"
    tmp.UPSDate(0) = "12/25/2013"
    tLet = tmp.LetterArray(0)
    tDate = tmp.UPSDate(0)
End Sub

As I said, tLet and tDate result in "" and #12:00:00AM# respectively
When I step through the code, the values for tmp.LetterArray(0) is assigned "src" and tmp.UPSDate(0) stores "12/25/2013" correctly

When i assign tLet and TDate, the same thing happens when stepping through the code. I'll use the LetterArray property to describe what happens:
Get LetterArray is called. p_LetterArray(0) does equal "src"
Let LetterArray is called. NewValue is "src" and p_LetterArray is "src" when End Property is highlighted in the debugger
Scope returns to Get LetterArray with End Property highlighted. In checking the values, LetterArray(0) = ""

Same steps happen with the same results ("12:00:00AM" vice "")

Does anyone have any ideas.

Thanks
TC
 
Note the Similar Threads table at the bottom.

If you provide a BS title yourself, you'll get a matching listing of BS titles.

If you provide a title that succinctly specifies the issue and not your state of mind, then you are quite likely to get a listing of similar problems, since a huge majority of issues have been seen @AWF before.

Google for how to write dates in Access.
 
first, note that the date being returned indicates that the value being retrieved is actually zero

maybe its to do with the redim

in order for the array not to be cleared when redimming, you need redim array PRESERVE

I don't quite see why this causes a problem with array index(0) though. I would put some msgboxes in the various properties, so you can test the values you have.

I am not sure exactly how you use the class, but once you populate a few terms in the array, how do you clear it to start again?

maybe a collection would be more appropriate than an array.
 
Spike - Noted. Will be more descriptive in my title and will look up how to pass dates

Gemma-the-Husky. Will follow your suggestions as well as look at collections vice an array
 
I've had a look now. The problem is these two

Code:
 Public Property Get LetterArray(index As Integer) As String
    'LetterArray(index) = p_LetterArray(index) 'WRONG
     LetterArray = p_LetterArray(index)   'RIGHT
End Property

 
Public Property Get UPSDate(index As Integer) As Date
    'UPSDate(index) = p_date(index)   'WRONG
     UPSDate = p_date(index)             'RIGHT
End Property
you do not need the array qualifier in the get methods. It works now (well for value 0, I haven't tested further).
 

Users who are viewing this thread

Back
Top Bottom