Any idea what is causing this error?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Any idea what is causing this error?

  1. #1
    Join Date
    Jun 2006
    Posts
    168

    Any idea what is causing this error?

    i have a class, that when I try to assign a value to its properties, i get an "object not initialized or with block not set" error (whatever it is).

    Usually get this on connection objects or whatever when they arent set= new ___

    anyway.

    here's is code for assignment:

    Code:
    Public Sub testsub()
    
    Dim IDs() As OldNewID
    
    Dim i As Integer
    
    For i = 0 To 100 Step 1
      ReDim Preserve IDs(i + 1)
      IDs(i).New_ID = i
      IDs(i).Old_ID = i - 1
    Next i
    
    
    End Sub


    here is the class:

    Code:
    Option Explicit
    
    Private m_Old_id As Long
    Private m_New_ID As Long
    
    
    Public Property Get New_ID() As Long
      New_ID = m_New_ID
    End Property
    
    Public Property Let New_ID(ByVal vNewValue As Long)
      m_New_ID = vNewValue
    End Property
    
    Public Property Get Old_ID() As Long
      New_ID = m_Old_id
    End Property
    
    Public Property Let Old_ID(ByVal vNewValue As Long)
      m_Old_id = vNewValue
    End Property


    ideas?
    -Jon


    Visual Basic 6.0
    Microsoft Access 2003

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    You must create an instance of the object (using New) for each element of the array:
    Code:
    For i = 0 To 100 Step 1
        ReDim Preserve IDs(i + 1)
        Set IDs(i) = New OldNewID
        IDs(i).New_ID = i
        IDs(i).Old_ID = i - 1
    Next i
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jun 2006
    Posts
    168
    Quote Originally Posted by Phil Weber
    You must create an instance of the object (using New) for each element of the array:
    Code:
    For i = 0 To 100 Step 1
        ReDim Preserve IDs(i + 1)
        Set IDs(i) = New OldNewID
        IDs(i).New_ID = i
        IDs(i).Old_ID = i - 1
    Next i

    I can't believe that slipped by me.

    haha

    Thanks phil!
    -Jon


    Visual Basic 6.0
    Microsoft Access 2003

  4. #4
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Noticed a small bug in your properties
    Code:
    Public Property Get Old_ID() As Long
    
      New_ID = m_Old_id
      ^^^^^ this is the wrong name it should be:
      Old_ID = m_Old_id
    
    End Property

  5. #5
    Join Date
    Jun 2006
    Posts
    168
    Quote Originally Posted by Ron Weller
    Noticed a small bug in your properties
    Code:
    Public Property Get Old_ID() As Long
    
      New_ID = m_Old_id
      ^^^^^ this is the wrong name it should be:
      Old_ID = m_Old_id
    
    End Property
    ****!

    nice catch

    Thanks! (again)
    -Jon


    Visual Basic 6.0
    Microsoft Access 2003

Similar Threads

  1. Returning errors from SQL Server Stored Procs
    By Khalizan in forum VB Classic
    Replies: 1
    Last Post: 11-28-2001, 02:32 AM
  2. Re: Error handling in components called from ASP
    By James Barbetti in forum ASP.NET
    Replies: 2
    Last Post: 11-06-2001, 02:13 PM
  3. Internal Server Error 500 on IIS
    By John in forum ASP.NET
    Replies: 0
    Last Post: 08-16-2001, 01:06 PM
  4. Sample Sites.
    By Murray Foxcroft in forum Web
    Replies: 5
    Last Post: 11-02-2000, 03:42 AM
  5. Replies: 1
    Last Post: 09-05-2000, 06:11 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center