Results 1 to 4 of 4

Thread: Need help convert VB 2005 Import to TB

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    Rep Power
    15

    Need help convert VB 2005 Import to TB

    i need help to convert VB 2005 Import to TB Declare.
    If you know Vbasic maybe you can help me out?

    [VB code]


    Imports ActiveHomeScriptLib
    Imports System
    Module Module1
    Dim WithEvents ActiveHomeObj As ActiveHome
    <MTAThread()> Sub Main()

    'create ActiveHome object
    Try
    ActiveHomeObj = CreateObject("X10.ActiveHome")
    Catch exc As Exception
    Console.WriteLine("err num: " & Str(Err.Number) & " '" & exc.ToString & "'")
    Finally
    End Try

    'send a1 on
    Try
    ActiveHomeObj.SendAction("sendplc", "a1 on")
    Catch exc As Exception
    Console.WriteLine("err num: " & Str(Err.Number) & " '" & exc.ToString & "'")
    Finally
    End Try

    'wait for events
    Dim nRead
    While True
    System.Threading.Thread.Sleep(0)
    nRead = Console.Read()
    End While

    End Sub

    'events from ActiveHome: write out received event
    Sub ActiveHome_RecvAction(ByVal bszRecv As Object _
    , ByVal vParm1 As Object _
    , ByVal vParm2 As Object _
    , ByVal vParm3 As Object _
    , ByVal vParm4 As Object _
    , ByVal vParm5 As Object _
    , ByVal vReserved As Object) Handles ActiveHomeObj.RecvAction
    Console.WriteLine("RecvAction: " & bszRecv & " " & vParm1 & " " & vParm2 & " " & vParm3 & " " & vParm4 & " " & vParm5)
    End Sub

    End Module

    [/code]

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    If this is COM object, you might have a look at examples in ThinBASIC/SampleScripts/COM.

    I wanted to help you with the translation, but sadly I do not have the X10.ActiveHome on my PC installed. To instantiate it, you would need something like:
    Uses "COM"
    
    ' -- Create object
    DWord retVal
    DWord ActiveHomeObj = COM_CREATEOBJECT("X10.ActiveHome", RetVal)
    
    ' -- Call method (parameters should be supplied in form of Variant array)
    Dim Params() As Variant
    Params(1) = "sendplc"
    Params(2) = "a1 on"
    COM_CallMethod(ActiveHomeObj, "SendAction", 2, Params(1))
    
    ...
    
    
    ' -- Release it before script ends
    COM_RELEASE(ActiveHomeObj)
    
    But as I said, I cannot test the rest, as I do not have this interface on my PC. The mentioned sample scripts should help you, I hope.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    Rep Power
    15

    Send Works

    OK Petr, Thanks for your help!
    The send works with three minor changes -

    Uses "COM" ' -- Create object
    Dim RetVal As Variant '<---------------------
    'DWord retVal
    DWord ActiveHomeObj = COM_CREATEOBJECT("X10.ActiveHome", RetVal)
    ' -- Call method (parameters should be supplied in form of Variant array)
    Dim Params(2) As Variant '<------------------
    Params(1) = "sendplc"
    Params(2) = "B09 off"
    COM_CALLMETHOD(ActiveHomeObj, "SendAction", 2, Params(1), RetVal) '<-----

    Will this cause an event to be generated for Receive?
    or do I need a While loop to test it?

    There are 2 Params to send and 6 Params for Receive.

    More info here: http://www.activehomepro.com/sdk/sdk-info.html
    Last edited by steinie; 06-09-2011 at 19:38.

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    Hi Steinie,

    I am sorry, but regarding receiving event, I never did this in ThinBASIC.
    Maybe worth some time to check examples in SampleScripts/Oxygen/COM, my experience with COM is limited, maybe Charles Pegge could know more?


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. Need help with convert Blitz3D code to thinBasic
    By Bagamut in forum Shout Box Area
    Replies: 10
    Last Post: 18-06-2010, 16:55

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •