• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

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

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.  

  • 6
  • 6
1 Solution
you need to create an object first


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

set set SingletonProj = createobject("SingletonProject.clsIO")
dve01Author Commented:
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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

yes you should use SingletonProject.ClsIO  
dve01Author Commented:
If I should use SingletonProject.ClsIO, what's the purpose of SingletonProj?  How is it used?
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

dve01Author Commented:
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

dve01Author Commented:
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?

>>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?
dve01Author Commented:
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?  
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.

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now