Results 1 to 4 of 4

Thread: using a matrix

  1. #1
    Join Date
    Oct 2003
    Posts
    233

    Unanswered: using a matrix

    I am struggling with how to use a matrix(?) to feed my class
    the code in sub Main doesnt work and i dont know how to fix it or how to use the data passed to the AddEntry sub.

    Any help greatly appreciated.


    Class:
    Private Entries As Collection
    Private mAcctNo As String
    Private mDebit As Integer
    Private mCredit As Integer

    Public Sub Main(data As Variant)
    Dim i As Integer

    For i = 1 To data.Length
    AddEntry data(1)
    Next i
    End Sub
    Private Sub AddEntry(entry As Variant)
    Dim Je As JournalEntry
    Set Je = New JournalEntry
    Je.acctNo entry(1)
    Je.Debit = entry(2)
    Je.Credit = entry(3)
    Entries.Add (Je)
    End Sub
    Public Property Let acctNo(val As String)
    mAcctNo = val
    End Property
    Public Property Let Credit(val As Integer)
    mCredit = val
    End Property
    Public Property Let Debit(val As Integer)
    mDebit = val
    End Property
    ------------------------------------------------
    calling code:

    Sub getstuff()
    Dim vMatrix As Variant
    Dim rngLastRow As Range

    'a handle on the range we are working with
    With ActiveSheet.Range("A:C")

    'get the LastRow
    Set rngLastRow = .Find(what:="*", searchorder:=xlByRows, searchdirection:=xlPrevious)

    'if the range contains data then populate our variant array
    If Not rngLastRow Is Nothing Then
    vMatrix = .Resize(rngLastRow.Row - .Row + 1, .Columns.Count)
    End If

    End With
    Dim Je As JournalEntry
    Set Je = New JournalEntry
    Je.Main (vMatrix)

    End Sub

  2. #2
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    I have had a quick look and found a one or to probs (vMatrix is a two dimensioanal array?, and you need a NEW key word in the Entries declaration) for which I have suggested some mod as follows
    Class Clode
    Code:
    Option Explicit
    
    Private Entries As New Collection
    Private mAcctNo As String
    Private mDebit As Integer
    Private mCredit As Integer
    
    Public Sub Main(data As Variant)
        Dim i As Integer
        
        For i = 1 To UBound(data, 1)
            AddEntry i, data
        Next i
    End Sub
    Private Sub AddEntry(index As Integer, entry As Variant)
        Dim Je As JournalEntry
        Set Je = New JournalEntry
        Je.acctNo = entry(index, 1)
        Je.Debit = entry(index, 2)
        Je.Credit = entry(index, 3)
        Entries.Add Je
    End Sub
    Public Property Let acctNo(val As String)
        mAcctNo = val
    End Property
    Public Property Let Credit(val As Integer)
        mCredit = val
    End Property
    Public Property Let Debit(val As Integer)
        mDebit = val
    End Property
    This is all a bit incestuous having a collection of 'Journal' Class objects in the 'Journal' class definition ??
    Also, the object properties are Write only (no GET Properties) and the Entries collection isn't visible at all, so how are you going to use them ?

    Hope this makes sense and helps!!

    MTB

  3. #3
    Join Date
    Oct 2003
    Posts
    233
    i know it seems weird to have have the collection of objects in it self, I am a little confused on how to design the whole thing, i also made the props read write.

    I have most of the stuff done now, and will post every thing so all you guys can have a good laugh and give me some design pointers.


    Thanks!

  4. #4
    Join Date
    Aug 2009
    Location
    US
    Posts
    1

    Don't hesitate

    every dofuser needs dofus kamas, but most of them can't find a good cheap dofus kamas provider, so it's a problem is they want to buy cheap dofus kamas.now bawwgt will be your best choice on dofus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •