www.homeseer.com    
 

Go Back   HomeSeer Message Board > HomeSeer Products & Services > HomeSeer Software > HS3 / HS3PRO > HS3 / HS3PRO Discussion

HS3 / HS3PRO Discussion Discussions related to the released version of HS3/HS3PRO

Reply
 
Thread Tools Display Modes
  #1  
Old January 9th, 2017, 11:45 AM
ksum ksum is offline
Seer Deluxe
 
Join Date: Oct 2006
Location: Bel Air, MD, USA
Posts: 214
Scripts with common subroutine

Is it possible to use a second file in a vb.net script to call a common subroutine? For instance, the blow could be cut into 2 scripts

Code:
Sub Main(Parms As Object)
'  hs.writelog("Parameter Test",CInt(Parms(0)))
Dim newValue as Integer

	newValue = CInt(Parms(0))

	'Ceiling Fan
	TestSet("Ceiling Fan Light Selector", "Ceiling Fan Light", newValue)

	'Fireplace Outside Cans
	TestSet("HSTouch -Fireplace Outside Cans Selector", "Fireplace Outside Lights", newValue)

	'Fireplace Inside Cans
	TestSet("Fireplace Inside Lights", "HSTouch -Fireplace Inside Cans Selector", newValue)

	'Entrance Light
	TestSet("Entrance Light @ Door", "HSTouch - Foyer Selector", newValue)

	'Light Outside Powder Room
	TestSet("Light Outside Powder Room", "HSTouch - Light Outside Powder Room Selector", newValue)

	'Stairs Light
	TestSet("HSTouch - Stairs Light Selector","Main Stairs Lights @ Top of Steps", newValue)


End Sub
And have it call the script below from a second file

Code:
Sub TestSet(byRef Selector as String, byRef Device as String, byRef , newValue as Integer)

Dim SelectorRef As Integer
Dim DevRef As Integer

	'Get the Device References
	SelectorRef = hs.GetDeviceRefByName(Selector)
	DevRef = hs.GetDeviceRefByName(Device)

	'Set the Device Value if the Device Selector is selected.
	If hs.IsOn (SelectorRef) then
		hs.CAPIControlHandler(hs.CAPIGetSingleControl(DevRef,false,newValue,false,true))
	end if

End Sub
So that I can use the second part in other scripts as well. I will have at least 6 scripts using this same subroutine.

Karl
Reply With Quote
  #2  
Old January 9th, 2017, 12:12 PM
sparkman's Avatar
sparkman sparkman is offline
OverSeer
 
Join Date: Oct 2001
Location: Calgary, Alberta, Canada
Posts: 6,007
Hi Karl,

Yes you can. Just include something like this at the top of the script:

Code:
#Include includes/functions.vb

Sub Main(Parms As Object)
...
I do the same and put them in a directory called Includes under the Scripts directory.

Cheers
Al
__________________
HS3Pro 3.0.0.318 on Jetway JBC501F9Q-Q87-B i7 8GB 1874 Devices, 955 Events, 28 Plugins
Z-Wave 3.0.1.131 Z-Net 105 nodes:Leviton Vizia,Kwikset,FortrezZ Valve/Sensors,Everspring Sensors/Modules/Outlets,CT30 Stats,MIMOLites,Aeotec Smart Switches
RFXCom W800,RFXrec433,RFXtrx433|APCUPSD|Pushover|Squeezebox|weatherXML|HS Phone W2C|APCUPSD|UltraLog
UltraGCIR GC-100|UltraNetcam|UltraPioneer|Ultra1Wire|DSC PC1832|BLLED|BLTVGuide|ImperiHome|jon00 Utilities|MySensors

PHLocation|X10 CM11A IOLinc,etc
Reply With Quote
  #3  
Old January 9th, 2017, 12:14 PM
ksum ksum is offline
Seer Deluxe
 
Join Date: Oct 2006
Location: Bel Air, MD, USA
Posts: 214
GREAT! Thank you, Al! (I need a gif of the old Fat Albert gang cheering...)
Reply With Quote
  #4  
Old July 15th, 2017, 02:03 PM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,624
Hi Al;

I am trying to use the include statement and am getting errors.

Code:
#Include includes/functions.vb
	
 Sub Main(byVal args As String)
 
	Logit("start",1)

	Logit("stop",1)
	
End Sub
Here is my Inclues\functions.vb

Code:
Sub Main(byVal Args As Object)

	Public Sub LogIt(byVal Message As String, byVal Severity As Integer)
		
		Dim ID As String = "Info"
		Dim strScript As String = "Test.vb"
		
		If Severity = 0 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#80800")	'Black
		If Severity = 1 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#0000FF")	'Blue
		If Severity = 2 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#ADD8E6")	'Light Blue
		If Severity = 3 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#FF0000")	'Red
		If Severity = 4 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#FFA500")	'Orange
			
	End Sub

End Sub
The HomeSeer Log error is
PHP Code:
Compiling script test.vb'Logit' is not declaredIt may be inaccessible due to its protection level
Am I using this incorrectly?

Thanks;
Don

Quote:
Originally Posted by sparkman View Post

Code:
#Include includes/functions.vb

Sub Main(Parms As Object)
...
__________________
Don
Reply With Quote
  #5  
Old July 15th, 2017, 09:11 PM
ksum ksum is offline
Seer Deluxe
 
Join Date: Oct 2006
Location: Bel Air, MD, USA
Posts: 214
Been a while since I have coded for HomeSeer. Are the function calls case sensitive? You are calling the function with a lower case I while your declare it with an uppercase I logit vs logIt. Try using logIt in your test file:

Code:
#Include includes/functions.vb
	
 Sub Main(byVal args As String)
 
	LogIt("start",1)

	LogIt("stop",1)
	
End Sub
Reply With Quote
  #6  
Old July 15th, 2017, 10:45 PM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,624
I changed the case to duplicate the method call, and still errors.

Thanks for looking.
Reply With Quote
  #7  
Old July 15th, 2017, 11:56 PM
zwolfpack zwolfpack is offline
Seer Master
 
Join Date: Sep 2015
Location: Orange County, California, USA
Posts: 717
In the included file you are nesting functions. The Main function there isn't necessary, as you already have one in the top-level file. (The included file is inserted "in-line" as if you typed it in there).

So in your functions.vb, if you remove the 1st line
Sub Main(byVal Args As Object)

and the last line
End Sub

it should work.
Reply With Quote
  #8  
Old July 16th, 2017, 02:56 PM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,624
If I understand you correctly, you don't need a main sub in the functions.vb? I tried that and still get the same error. I'll do a google on the #include statement and go from there.

Thanks
Reply With Quote
  #9  
Old July 16th, 2017, 04:21 PM
jon00's Avatar
jon00 jon00 is online now
OverSeer
 
Join Date: Jan 2002
Location: London UK
Posts: 10,975
I tried it here and seems to work:

includes\functions.vb

Code:
        Public Sub LogIt(byVal Message As String, byVal Severity As Integer)
		
		Dim ID As String = "Info"
		Dim strScript As String = "Test.vb"
		
		If Severity = 0 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#80800")	'Black
		If Severity = 1 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#0000FF")	'Blue
		If Severity = 2 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#ADD8E6")	'Light Blue
		If Severity = 3 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#FF0000")	'Red
		If Severity = 4 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#FFA500")	'Orange
			
	End Sub
test.vb

Code:
#Include includes/functions.vb

Sub Main(ByVal Parm As Object)

	Logit("start",1)

	Logit("stop",1)

End Sub
__________________
Jon

Reply With Quote
  #10  
Old July 16th, 2017, 05:03 PM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,624
Wierd. I've got to be doing something wrong.

I am getting this error dealing with the includes statement. Does this make any sense to anyone?

Thanks

PHP Code:
Compiling script test.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn'use any aliases

Last edited by donstephens; July 16th, 2017 at 05:17 PM.
Reply With Quote
  #11  
Old July 16th, 2017, 05:15 PM
jmaddox jmaddox is offline
Seer Plus
 
Join Date: Oct 2010
Location: Dallas, Texas
Posts: 116
dont forget that functions.vb needs to be inside the directory c:/...homeseer hs3/scripts/includes
__________________
HS3 Pro on Hometroller S6 with Z-NET
Number of Devices: 83
Number of Events: 50

Plug-Ins: BLLock, DoorBird, Honeywell WiFi Thermostat, HSTouch Server, Restart, Z-Wave, EasyTrigger, PHLocation, Pushover 3P

External applications: Homebridge-homeseer, Geofency
Reply With Quote
  #12  
Old July 16th, 2017, 05:21 PM
zwolfpack zwolfpack is offline
Seer Master
 
Join Date: Sep 2015
Location: Orange County, California, USA
Posts: 717
Good point, double check the pathname spellings. I noticed that in your initial post you typed "Here is my Inclues\functions.vb". Might be just a typo there, but worth a second look.
Reply With Quote
  #13  
Old July 16th, 2017, 05:27 PM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,624
In my path, the Includes folder is capitalized and under the script folder. Will keep hammering on this.

Quote:
Originally Posted by zwolfpack View Post
Good point, double check the pathname spellings. I noticed that in your initial post you typed "Here is my Inclues\functions.vb". Might be just a typo there, but worth a second look.
Reply With Quote
  #14  
Old July 16th, 2017, 10:11 PM
B1Trash B1Trash is offline
Seer
 
Join Date: Nov 2016
Location: Tx
Posts: 47
I just keep my subs in the same vb file as my parent sub.

Code:
Public sub main(...)
End sub

Public sub run_me(...)
    Do_this(..)
End sub

Public sub run_me_too(...)
    Do_this(..)
End sub

Function Do_this(..)
     Return x
End function
Reply With Quote
  #15  
Old July 17th, 2017, 10:51 AM
ITguyHS ITguyHS is offline
Seer Deluxe
 
Join Date: Oct 2013
Location: NC
Posts: 389
Since you're including the code, the functions sub does not need to be public. I tried it with test.vb in the scripts folder and functions.vb in the includes folder. It works fine when the sub is not declared as public, but errors when it is made public.
__________________
Fred

HomeSeer Pro 3.0.0.318, HS3Touch 3.0.0.68, Zwave 3.0.1.87, Envisalink DSC 3.0.0.33, WeatherXML, Z-stick, CM15A 3.0.0.8, HS phone, Way2Call
Reply With Quote
  #16  
Old July 17th, 2017, 11:32 AM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,624
Can't get it to work, and I seem to be duplicating what works for you guys.

:-(
Reply With Quote
  #17  
Old July 17th, 2017, 11:39 AM
ITguyHS ITguyHS is offline
Seer Deluxe
 
Join Date: Oct 2013
Location: NC
Posts: 389
Quote:
Originally Posted by donstephens View Post
Can't get it to work, and I seem to be duplicating what works for you guys.

:-(
One thing I noticed is that it appears HS doesn't always recompile the script if it hasn't changed. Try renaming test.vb to something else.
Reply With Quote
  #18  
Old July 17th, 2017, 11:49 AM
jon00's Avatar
jon00 jon00 is online now
OverSeer
 
Join Date: Jan 2002
Location: London UK
Posts: 10,975
Are you sure you spelled includes correctly?

In your earlier post, you posted this for your includes code:

Quote:
Here is my Inclues\functions.vb
Reply With Quote
  #19  
Old July 17th, 2017, 12:32 PM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,624
Arrg!

Still no luck. Makes zero sense, works for you guys, but not for me. Please see if you have the same structure as I do.

C:\HomeSeer HS3\scripts\Includes

Calling script: test1.vb

Code:
#Includes Includes/functions.vb
	
 Sub Main(byVal args As String)

	hs.WriteLog("TEST","Starting")

End Sub
functions.vb in scripts\Includes

Code:
	Sub LogIt(byVal Message As String, byVal Severity As Integer)
		
		hs.WriteLog("test","found /include")
		Dim ID As String = "Info"
		Dim strScript As String = "Test.vb"
		
		If Severity = 0 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#80800")	'Black
		If Severity = 1 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#0000FF")	'Blue
		If Severity = 2 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#ADD8E6")	'Light Blue
		If Severity = 3 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#FF0000")	'Red
		If Severity = 4 Then hs.WriteLogEx(ID," -- " & strScript &  " -- " & Message,"#FFA500")	'Orange
			
	End Sub
Thanks to all for your patience.
Reply With Quote
  #20  
Old July 17th, 2017, 12:36 PM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,624
Yeah, my frustrations are moving to the keyboard.

Quote:
Originally Posted by jon00 View Post
Are you sure you spelled includes correctly?

In your earlier post, you posted this for your includes code:
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in pops subroutine jono Jon00's plugins and scripts 19 August 12th, 2010 07:49 AM
Common issues rjh HomeSeer Phone 0 January 26th, 2007 04:17 PM
Named subroutine behaves different than "main" dwoolridge Script & Plug-In Development 10 November 22nd, 2004 11:51 PM
Running a subroutine on an ASP from an include Tom Kern Script & Plug-In Development 4 May 14th, 2004 10:30 AM
Exiting a script from a subroutine. RSLoeb Script & Plug-In Development 2 December 17th, 2003 11:46 AM


All times are GMT -4. The time now is 01:33 PM.


Copyright HomeSeer Technologies, LLC