Link to home
Start Free TrialLog in
Avatar of dve01
dve01

asked on

"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)

SingletonProject
     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
                  etc.
      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
                end
                public property let board (byval Newvalue as integer)
                       mboard = Newvalue
                end
               etc. for mPort and mBit
             
               So, for instance, Conveyor_Motor.board OR .port  OR  .bit

MainProject:

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

ElecProject:
         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.  
                 


Avatar of EDDYKT
EDDYKT
Flag of Canada image

you need to create an object first

ie

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


set set SingletonProj = createobject("SingletonProject.clsIO")
Avatar of dve01
dve01

ASKER

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.
>>SingletonProject       activex exe  (use to share global vars between Main & ElectTest)


yes you should use SingletonProject.ClsIO  
Avatar of dve01

ASKER

If I should use SingletonProject.ClsIO, what's the purpose of SingletonProj?  How is it used?
ASKER CERTIFIED SOLUTION
Avatar of EDDYKT
EDDYKT
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dve01

ASKER

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:

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

Also,
                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


Avatar of dve01

ASKER

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?
Avatar of dve01

ASKER

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.

Avatar of dve01

ASKER

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