Please login or register.

Login with username, password and session length

Author Topic: SDK in VBA  (Read 9638 times)

vrynh

  • Newbie
  • Helpful Post Rating: 0
  • Posts: 1
SDK in VBA
« on: January 05, 2008, 04:33:32 AM »

I am new to using x10 and I am trying to send simple lamp module on/off commands using the CM15A with a power point VBA macro. I'm trying to translate the VBscript code below to a VBA macro and I'm having trouble.  was wondering if anyone knew how to translate this to a simple macro to execute the on/off when the macro runs?

Thanks.
VRYNH

<HTML>
<HEAD>
<TITLE>ActiveHome VB Scripting</TITLE>
</HEAD>

<BODY BGCOLOR="#ffffff" >
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->

<CENTER><H2>ActiveHome VB Scripting</H2></CENTER>

<FONT FACE="verdana,arial,helvetica" SIZE=1>
    <A href="#" onclick=self.close() CLASS="clsDemo">Close This Test</A>
</FONT><HR>


<OBJECT ID="ActiveHome1" width=0 height=0
    classid="CLSID:001000AF-2DEF-0208-10B6-DC5BA692C858"
    codebase="ahscript.dll"
        standby="Loading X10 net components..."
        type="application/x-oleobject">
</OBJECT>

<FORM NAME="myForm">
    Send Status
   <BR>
   <INPUT TYPE="text" NAME="sendstatus" size="50">

</FORM>


<SCRIPT LANGUAGE="vbscript">
Function doCommand( Command )

    if Command = 1 then
        myForm.sendstatus.value = "e8 On sent"
        ActiveHome1.SendAction "sendplc", "e8 on"
    elseif Command = 2 then
        myForm.sendstatus.value = "e8 Off sent"
        ActiveHome1.SendAction "sendplc", "e8 off"
    end if
End Function


</SCRIPT>

<FORM NAME="myButtons">
  <BR>
  <CENTER>
   <INPUT NAME="btnSendOn" TYPE="Button" VALUE="Send e8 on" onclick="doCommand( 1 );">
   <INPUT NAME="btnSendOff" TYPE="Button" VALUE="Send e8 off" onclick="doCommand( 2 );">
   </CENTER>
  <BR>
</FORM>

<P>
<HR>
<FONT FACE="Arial" SIZE="1" COLOR="BLACK">
© 2004 <A TARGET="_blank" HREF="http://www.x10.com">X10</A>. All rights reserved.
</FONT>

</BODY>
</HTML>
Logged

frasierman

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 10
Re: SDK in VBA
« Reply #1 on: March 14, 2008, 08:36:00 PM »

Sorry, can't hep but when you find out, please post the file!
Logged

schelto

  • Newbie
  • Helpful Post Rating: 0
  • Posts: 1
Re: SDK in VBA
« Reply #2 on: July 24, 2008, 10:50:49 PM »

I’m a newbie to this forum and I’m using Vista 64 bit, so bear with me.
 
I’m assuming this code is the same code that’s published on the X10 SDK site "ahvbview.zip".

I spent a lot of hours trying to get it to work on my 64 bit machine, but finally after replacing all the ”ActiveHome1” with “ActiveHome”, it works fine for me.  Don’t ask me why, but I would like to know what the culprit could be, because I’m also having problems getting Visual Basic 2008 Express to generate an object using the code vbactivehome.zip, but I’ll start a new thread on that.

Thanks for any help
Logged

freedomFighter

  • Newbie
  • Helpful Post Rating: 1
  • Posts: 1
Re: SDK in VBA
« Reply #3 on: August 02, 2008, 01:35:35 AM »

To the Op.

First thing you have to do is go in the vba editor and reference the SDK dll.
press alt-F11 to get the vba editor
click Tools menu > References.
Click the browse button
navigate to the SDK dll, open it
click ok on reference dialog
Create a new module Insert menu > module
Put this code in the module:

Quote
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub testing123()
   'change "b1", 0.6, 8 accordingly
    blinkLights "b1", 0.6, 8
End Sub

Sub blinkLights(mName As String, pTime As Integer, blinks As Integer)
    'mName is name of module "a1".
    'pTime is length of pause time between on/off.
    'blinks is the number of blinks
    'ensures a minimum time of half a second
    Dim AH As New ActiveHome
    Dim i As Integer
    pTime = IIf(pTime < 0.5, 0.5, pTime * 1000)
    For i = 1 To blinks
        Sleep (pTime)
        AH.SendAction "sendplc", mName & " on"
        Sleep (pTime)
        AH.SendAction "sendplc", mName & " off"
    Next i
    Set AH = Nothing
End Sub

Make a button in your application, which ever app that is, that executes the "testing123" sub or just put the cursor within the "testing123" sub and push the play button from the vba editor.
Logged
 

X10.com | About X10 | X10 Security Systems | Cameras| Package Deals
© Copyright 2014-2016 X10.com All rights reserved.