Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6529553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:38:59+00:00 2026-05-25T09:38:59+00:00

Getting some weird behavior in VB6 and I’m throwing a net out for some

  • 0

Getting some weird behavior in VB6 and I’m throwing a net out for some answers.

I have a collection in which I use to store a group of custom forms of the same type.

Dim formCollection As New Collection

Public Sub AddForm()
    Dim newForm As New frmCustomForm
    formCollection.Add(newForm)
End Sub

Then in another routine I iterate through the collection. But as I cast the variant back into the custom form class I get a type casting error (“Run-time error ’13’: Type mismatch”).

Public Sub Foo()
    Dim someForm As frmCustomForm
    Dim iterator As Integer

    For iterator = 1 To formCollection.Count
        Set someForm = formCollection.Item(iterator) ' The error appears here
        someForm.SomeProperty = 3
    Next iterator
End Sub

It seems that though initially it was of the custom form class, as it got stored into the collection it lost it’s type and can’t be casted back. Further, if I put a breakpoint before I try casting the stored form and then I examine the object through Locals, it’s lost all the class specific information such as property names, which appear only as ‘Item 1’, ‘Item 2’, ‘Item 3’, etc.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:39:00+00:00Added an answer on May 25, 2026 at 9:39 am

    You can’t use parentheses like this in VB6. Try this

        formCollection.Add newForm
    

    or this

        Call formCollection.Add(newForm)
    

    In your case parentheses force VB6 to evaluate the default property of the object reference and this gets stored in the collection, not the form reference.

    Usually you get an extra space in the IDE just before the opening bracket like this

        formCollection.Add (newForm)
    

    which should make you extra suspicious.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting some weird behavior in asp.net MVC2 (at least it's not what I'm
I am getting some weird behavior when using cout in my programm, which is
I'm getting some weird behavior from IE when trying to change a session variable
I'm getting a very strange behavior in MySQL, which looks like some kind of
I'm writing an IME (soft keyboard) and I'm getting some weird behavior from one
I'm getting some weird results while parsing some XML in JavaScript. I have the
I have a little weird behavior with my ASP.NET MVC 2 application. I'm using
I'm getting some weird behavior with a vector in C++ I was hoping someone
I have been getting some weird errors when I upgrade jQuery from 1.4.4 to
I'm using Fluid 960 at the moment, and I'm getting some weird behavior with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.