Community
Showing results for 
Search instead for 
Do you mean 
Reply

Visual Basic - Call Sub from Different Class

Accepted Solution Solved
Copper Super Contributor
Posts: 71
Country: Canada
Accepted Solution

Visual Basic - Call Sub from Different Class

Hello Everyone,

 

I have a form called form1, in that form I want to call an event in a seperate class, that works just fine. However the code in that event in the seperate class does not work when running from the form, I believe the actapp is set to nothing which is causing the problem. If that event is called from within the class it works fine as the actapp is declared onload. Any thoughts to make this work?


Accepted Solutions
Solution
Accepted by topic author MattRobillard
‎09-25-2015 03:20 AM
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Visual Basic - Call Sub from Different Class

Matt,

 

I'm not sure how your program works but if the updateTotals class works in a stand alone mode I would recommend launching your form from the updateTotals class and then returning to the class with the information that you are setting in the form using the Property methodology.  Then you could run the updateTotals routine from inside the class where it is already working.

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!

View solution in original post


All Replies
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Visual Basic - Call Sub from Different Class

Matt,

 

Pass the ActApp object to the class as a property.


Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Copper Super Contributor
Posts: 71
Country: Canada

Re: Visual Basic - Call Sub from Different Class

Sorry I am so new to programming but what would the code be for that, is it just a simple line I need to add at the beginning of the event.

Silver Super Contributor
Posts: 2,328
Country: USA

Re: Visual Basic - Call Sub from Different Class

Matt,

 

Here is a little tutorial on Properties.

 

http://www.xtremevbtalk.com/showthread.php?p=688701

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Copper Super Contributor
Posts: 71
Country: Canada

Re: Visual Basic - Call Sub from Different Class

I am still a bit lost, I can create a basic property for a string but an object is confusing. So in the form I have this code calling the event in the other class (updatetotals is the class, Update_Totals() is the event)

 

updateTotals.Update_Totals()

 

So to make the actapp not come up as nothing I need to make it a property, do I do that in the form or the class with the event, I tried doing it in the class but I am not sure of the syntax. I tried this but it did not work.

 

Dim

_actApplication As ActApplication

 

 

 

 

 

 

 

 

Public Property actapplication As ActApplication

 

Get

 

Return _actApplication

 

End Get

 

Set(ByVal actapp As Act.UI.ActApplication)

_actApplication = actapp

 

End Set

 

End Property

I then put the actApplication in my Update_Totals event but it did not work, any thoughts.

Silver Super Contributor
Posts: 2,328
Country: USA

Re: Visual Basic - Call Sub from Different Class

Matt,

 

It's something like this.  Inside the updateTotals Class you would put this code:

 

         Property ActApp() As Act.UI.ActApplication
            Get
                Return _ActApplication
            End Get
            Set(ByVal Value As Act.UI.ActApplication)
                _ActApplication = Value
            End Set
        End Property

Inside the Form you would put:

Dim thisClass as new updateTotals

thisClass.ActApp = [The name of the Act Application object in your Form]

thisClass.Update_Totals

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Copper Super Contributor
Posts: 71
Country: Canada

Re: Visual Basic - Call Sub from Different Class

I do not have any act application object in my form, just in the class. I thought I did not need it there as all my code using the act application object was in the class. What would the code be in the form to add the act application object if I need it there.

Solution
Accepted by topic author MattRobillard
‎09-25-2015 03:20 AM
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Visual Basic - Call Sub from Different Class

Matt,

 

I'm not sure how your program works but if the updateTotals class works in a stand alone mode I would recommend launching your form from the updateTotals class and then returning to the class with the information that you are setting in the form using the Property methodology.  Then you could run the updateTotals routine from inside the class where it is already working.

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Copper Super Contributor
Posts: 71
Country: Canada

Re: Visual Basic - Call Sub from Different Class

Thanks for your help stan, i got it working it just took talking with you through it to figure it out.