Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetObjectContext() : why doesn't it work?????

Status
Not open for further replies.

gust1480

Programmer
Mar 19, 2002
148
PH
Dim ctxobject As ObjectContext
Dim objAccount As Account.Pay

Set ctxobject = GetObjectContext()
Set objAccount = ctxobject.CreateInstance("Account.Pay")

I'm trying to run the code above cause I want to be able to use the SetComplete and SetAbort. But it always give me the runtime error 91 : Object variable or With block variable not set.
I noticed that the - Set ctxobject = GetObjectContext()
doesn't seem to work cause it give my object variable Nothing. I was told that I should place my DLL in MTS but I already did placed my DLL in MTS. What's wrong with it? am I missing something here?
 
Are you running your code live? If so, there will be no object context.
In order to work in debug and in production, always use the following syntax with ObjectContext:

Dim ctxobject As ObjectContext
Dim objAccount As Object

Set ctxobject = GetObjectContext()
if ctxobject Is Nothing then
Set objAccount = CreateObject("Account.Pay")
else
Set objAccount = ctxobject.CreateInstance("Account.Pay")
end if
...

If Not ctxobject Is Nothing then
ctxobjext.setcomplete ' or setabort
End if




 
Hi! hirick!
What do you mean by live? And where do I exactly place the code that you mentioned. Cause you see I have a test form and that is where I place the code :

Dim ctxobject As ObjectContext
Dim objAccount As Account.Pay

Set ctxobject = GetObjectContext()
Set objAccount = ctxobject.CreateInstance("Account.Pay")

Does this code have to be inside MTS also to give me an object context? Cause I'm kinda confused in using createinstance.
 
dear gust
u see when u r debugging the MTS component inside the same group project means the dll(mts object and the .exe in a same Vb group it will not run and u will get the Getobjectcontext always retung Nothing
to get rid of this thing u have to run the MTS object (.dll) project seperate from the .exe application
it will work
but if it still give u nothing then install these objects in MTS if ur using NT then add in the MTS and if u r using Win2k then add usign Component Sevices
hope it will help u out
Regards
Nouman
 
Hi! Nomi2000
Thanks for your advice but I already tried putting my dll in MTS but it still doesn't seem to work.
I have also tried what Hirick said :

Dim ctxobject As ObjectContext
Dim objAccount As Object

Set ctxobject = GetObjectContext()
if ctxobject Is Nothing then
Set objAccount = CreateObject("Account.Pay")
else
Set objAccount = ctxobject.CreateInstance("Account.Pay")
end if

And I found out that my object variable, ctxobject is not "Nothing" but actually "Empty". I don't know whta's wrong with it. Pls help!
 
Dear gust
u see there are so many differnece in ur first post and the last post
in first post u said
"- Set ctxobject = GetObjectContext()
doesn't seem to work cause it give my object variable Nothing."
now the reason for this is that what i told that u are not able to connect the component as MTS based & also let u know what might be the possibilties
a) You are making a group and ur .exe and the .dll (MTS based Component) resides in the same group
if a) is not the case then
b) you have not set ur MTS components correctly in componente services (for win2k) and MTS for (winNT)

let me know which environment u r having and also how u r settign ur compoents inside compoents service
okay but the thing is that i think it should be one of the two reasons i mentioned..
okay Regards
Nouman
 
Dear Nouman,

I’m sorry for the contradicting post but I really thought my object variable (ctxobject) is set to Nothing.
Anyway, I have a WinNT platform on my PC so it is definitely MTS. I did the following steps in creating my DLL :

1. I created a new ActiveX DLL project. I named it GetAmt. I have one class named Amount. It is just an ordinary components (only Let ang Get that formats a number placing leading zeroes on it).
2. In the properties window, I set the MTSTransactionMode to 3-Uses Transaction
3. After finishing the codes that will format a number, I compiled it to DLL and set it to Binary Compatibility.

After building my DLL, I then prepared to run it MTS. So I :

1. Created a new package
2. I choose the Create an empty package
3. I named my package as GetAmt
4. In the Set Package Identity, I just choose the Interactive User – the current logged on user. Then I click Finish.
5. I copied my DLL into the package by drag n drop method.
6. then I created the client setup

Then I made a test client :
1. Created a Standard EXE project
2. Opened the Reference dialog and selected GetAmt and Microsoft Transaction Server Type Library.
3. Added 2 text box ( one for input, the other one for output) and one command button.
4. On the command button click event I placed the code:

Dim ctxobject As ObjectContext
Dim objGet As GetAmt.Amount

Set ctxobject = GetObjectContext()
Set objGet = ctxobject.CreateInstance("GetAmt.Amount ")

‘ placed here are the code that actually get the value from
‘ the text box and pass it on to my DLL to be formatted.


I know I did something wrong. Please tell me, what is it?
 
okay gust
hay hay hay where u placed that code?
Dim ctxobject As ObjectContext
Dim objGet As GetAmt.Amount

Set ctxobject = GetObjectContext()
Set objGet = ctxobject.CreateInstance("GetAmt.Amount ")

this code should be in ur MTS based DLL not in ur test-executable,ur test executable should only call a funtion or property of the dll in the usual way
jsut move that code in the dll and call it as

Dim objGet as object
Set objGet=CreateObject("GetAmt.Amount")
'now
‘ placed here are the code that actually get the value from
‘ the text box and pass it on to my DLL to be formatted
i hope u got it
okay
Regards
Nouman
 
Dear Nouman,
I would just like to clarify things and make sure I understood it. So, I can only use GetObjectContext, SetAbort and SetComplete on a DLL that is inside MTS, right?
 

Dear gust1480;

As you wrote in your last post your placed code on click event of command button and you used objectcontext() here.

First of all as you are using late binding so there is no need to referece the GetAmt in your Exe.

Secondly there is not need to reference MTS Library here in EXE b/c you are using objectcontext in DLL not in exe. So remove both these reference from EXE.

Then just run the client setup of MTS package which you created from MTS on the client.

Then check it out either your PC is able to communicate with MTS or to use COM application. You will have to run MSI on this client pc to comunicate with remote server application.

Then just create the object of your DLL here in Exe and try to use these object as you want.

Please, check it out when your object is created then check either the MTS component are moving around.

I hope all this help out. Hi Nouman .

Regards ,
Muhammad Essa Mughal


 
dear gust
yes puts the code in the DLL (MTS Component) don't put it in the exe
you don't have to run MSI or other client setup as ur cheking at devlopment just put the DLL in MTS and run it from VB to check it
but if u r running it live from Executable then u have to make client MSI to run from server if u r checking it
but the problem u r facing is that u r placing the code not at right place hope u understand
regards,Hi essa
Nouman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top