"Object variable or With block not Set" , when accessing a class in a activex exe from multiple projects

Posted on 2006-04-04
Last Modified: 2010-05-01
I explain what I have so far and what I am trying to do.  A previous expert got me to the 5 yard line with my project.  I now just need to get in the endzone.

MainProject             standard exe
ElectTestProject       activeX exe
SingletonProject       activex exe  (use to share global vars between Main & ElectTest)

     Singleton class  ( consists of global vars such as:)
                 public voltval as double
                 public currentval as double
                 public Conveyor_Motor as clsIO
                 public Buzzer as ClsIO
                 public  EStop as ClsIO
      ClsIO  class (consists of public properties to take place of Type Def)
                private mboard
                private mport
                private mbit
                public property get board as integer
                        board = mboard
                public property let board (byval Newvalue as integer)
                       mboard = Newvalue
               etc. for mPort and mBit
               So, for instance, Conveyor_Motor.board OR .port  OR  .bit


          The following lines of code causes "Object variable or With block not Set"
                   SingletonProj.Singleton.Conveyor_Motor.port = 1
                   SingletonProj.Singleton.Conveyor_Motor.bit = 32

         The same following lines of code causes "Object variable or With block not Set"

The object list boxes show up ok to set up instruction in both projects,  but don't understand error.  

Question by:dve01
    LVL 26

    Expert Comment

    you need to create an object first


    set SingletonProj = new SingletonProject.clsIO
         if your poject is SingletonProject and the class is clsIO
    LVL 26

    Expert Comment


    set set SingletonProj = createobject("SingletonProject.clsIO")

    Author Comment

    I tried it, but didn't get expected results.   When I type SingletonProj. - no objects show up in list box.  When I type SingletonProject. - I get objects to show up in list box.
    LVL 26

    Expert Comment

    >>SingletonProject       activex exe  (use to share global vars between Main & ElectTest)

    yes you should use SingletonProject.ClsIO  

    Author Comment

    If I should use SingletonProject.ClsIO, what's the purpose of SingletonProj?  How is it used?
    LVL 26

    Accepted Solution

    SingletonProj is your variable

    you define

    dim SingletonProj as SingletonProject.Singleton   ' similiar like that

    set SingletonProj = new SingletonProject.Singleton  

    or using late binding

    dim SingletonProj as object

    set SingletonProj = createobject("SingletonProject.Singleton")

    after that you should be use SingletonProj


    SingletonProj.Conveyor_Motor.port = 1
    SingletonProj.Conveyor_Motor.bit = 32


    Author Comment

    Ok,  I left something out that I think is contributing to this not working right.

    In the SingletonProject I have a Module1.bas which was taken right from a VBaccelerator example on how to use a Singleton ActiveX exe.  It looks like this:

           public function Singleton as Singletonclass
                  if msingleton is nothing then set msingleton = new Singletonclass
                  set Singleton = msingleton
          end function

                    SingletonClass is a Public Not Creatable class.   If you look at the body of my main question there shouldn't be a space between Singleton and Class.  SingletonClass is the name of the class.  Singleton comes from the function in Module1.bas.

    So,  when I try

    dim SingletonProj as SingletonProject.Singleton
     (SingletonClass in only in list after SingletonProject, NOT Singleton)

    set SingletonProj = new SingletonProject.Singleton
      (ClsIO is only in list after SingletonProject, NOT Singleton)

    If I don't use "new" then .Singleton shows up


    Author Comment

    I think I need to look at this a little differently.   I have numerous ClsIO variables in SingletonClass.  The values of these variables (board, bit, port) are contained in a IO_definition.ini file.

    It would probably make more sense to ASSIGN the ClsIO variables in the SingletonProject instead of MainProject.  This way I could access this already assigned variable from MainProject or ElectProject.  Once this variable is assigned, there is no need to change it in MainProject or ElectProject.

    If this makes sense to you, how or where would I first assign these variables in the SingletonProject and secondly access them from MainProject?

    LVL 26

    Expert Comment

    >>SingletonClass is a Public Not Creatable class

    You will not be able to use new from outside. Why not use single use or global single use. That will fit your singleton class objective.

    >>It would probably make more sense to ASSIGN the ClsIO variables in the SingletonProject instead of MainProject.

    Really depend on what you want. If you want to implement singleton (need to use single use or global single use instanting). That mean every createobject from your mainprogram it will create NEW EXE,. You can see two singleton exe running on task manager. Is it what you want?

    If you want to ASSIGN the ClsIO variables in the SingletonProject, if you have second instant created, do you still want to load the same info?

    Author Comment

    It's only necessary to have 1 singleton exe running on task manager.  Once I reference the Singleton.exe in MainProject and ElectProject I thought it would be all I needed.   I didn't realize that if I do a createobject from Mainproject it would create a new exe.  Does that cause problems?

    As far as Assigning ClsIO variables in SingletonProject, I was just thinking that once those variables are assigned in SingletonProject, both MainProject and Electproject could share the already ASSIGNED variables.  I have a procedure called LoadIOvalues in Mainproject, and my previous way of looking at this would require to call LoadIOvalues in Electproject also.     It think it makes more sense to LoadIOvalues in SingletonProject.   Now, the question is how do I (run or call) the LoadIOvalues in SingletonProject, Assign these ClsIO variables, and then access them in MainProject and ElectProject.   Do I put LoadIOvalues in module.bas?  Or create some public property to Dosomething?  
    LVL 26

    Expert Comment

    Sorry i think i reverse the singleton meaning. Singleton means you want to only use 1 exe no matter how many client connect to

    In this case, you should use mutliuse or global multiuse.

    If you want to use the global variable so that all client connect to your object(singleton) then you shall move to module
    Otherwise each client will have its own set of data.


    Author Comment

    Thanks for the responses.  I got it working without the error now.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now