Consulting

Results 1 to 20 of 23

Thread: Compile error: Variable not defined

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Question Compile error: Variable not defined

    I'm close to the end of this code, but there is a problem with it.

    [vba]Public SumXCollection As Collection
    Public artikal As String
    ...[/vba] [vba]Private Sub Sub1()
    ...
    artikal = Product.Text
    ...
    End Sub[/vba] [vba]Private Sub Sub2()
    ...

    If (some item exists) Then
    ...
    ...
    'update the corresponding object of the SumX collection !!!!!!!!!
    Set zx = SumXCollection(artikal)
    zx.ColorXX = Color.Text
    zx.TotalXX = ActiveSheet.Cells(begin1 + i, 11)

    Else
    ...
    ...
    'create a new object of the SumX coolection
    Set zx = New SumX
    zx.CodeXX = artikal
    zx.ColorXX = Color.Text
    zx.TotalXX = ActiveSheet.Cells(stepx, 11)

    SumXCollection.Add zx, zx.CodeXX
    ...
    End If

    ...
    End Sub[/vba] [vba]'Class Module named 'SumX'
    Option Explicit

    Private pCodeXX As String
    Private pColorXX As String
    Private pTotalXX As String

    Public Property Get CodeXX() As String
    CodeXX = pCodeXX
    End Property

    Public Property Let CodeXX(ByVal vNewValue As String)
    pCodeXX = vNewValue
    End Property

    Public Property Get ColorXX() As String
    ColorXX = pColorXX
    End Property

    Public Property Let ColorXX(ByVal vNewValue As String)
    pColorXX = vNewValue
    End Property

    Public Property Get TotalXX() As String
    TotalXX = pTotalXX
    End Property

    Public Property Let TotalXX(ByVal vNewValue As String)
    TotalXX = vNewValue
    End Property[/vba]
    and i get :
    Compile error:
    Variable not defined
    on 'Set zx = SumXCollection(artikal)' in Sub2().

    What is particularly odd is that the code shouldn't enter the first part of the If statement immediately, because in the first pass the item (from the condition) doesn't exist, so the code must drop to Else part of the If statement, where a zx object needs to be created.

    So that, every new zx object is created in the second (Else) part of the If st., and every existing one is updated in the first part.

    What's wrong with this?

    Thanks a lot in advance
    Last edited by SMC; 01-23-2007 at 05:06 PM.

Posting Permissions

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