VB.NET Sample Program with SDK .NET Wrapper

From ActiveWiki
Revision as of 15:46, 28 July 2021 by Tomas (talk | contribs) (Created page with "Visual Studio VB.NET This example is used on Windows Forms. Place the files aw.dll and AW.Core.dll in the folder from where the exe will run in i.e. [app name]/bin/Release (o...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Visual Studio VB.NET

This example is used on Windows Forms. Place the files aw.dll and AW.Core.dll in the folder from where the exe will run in i.e. [app name]/bin/Release (or Debug) Go the applications properties/references and click on the "add" button Then click on "browse" and go to the folder where you put those .dll files and choose the AW.Core.dll (No need to do anything with the aw.dll) Then move back up in the properties to "Compile". There change the "Target CPU" to "x86" (The wrapper will not support x64)

Imports AW


Public Class Form1
    Public WithEvents bot As AW.Instance
    Private Sub ButtonLogin_Click(sender As Object, e As EventArgs) Handles ButtonLogin.Click
        Dim result As AW.Result
        bot = New Instance()

        AddHandler bot.EventAvatarAdd, AddressOf AW_EventAvatarAdd

        bot.Attributes.LoginName = "Name of the bot"
        bot.Attributes.LoginPrivilegePassword = "Password"
        bot.Attributes.LoginOwner = 12345
        result = bot.Login()

        If Not result = AW.Result.Success Then
            MsgBox("Error: " & result.ToString)
            bot.Dispose()
            bot = Nothing
            Exit Sub
        End If

        result = bot.Enter("Name of the world")

        If Not result = AW.Result.Success Then
            MsgBox("Error: " & result.ToString)
            Exit Sub
        End If

        bot.Attributes.MyX = 0 'X position of the bot in centimeters (W positive/E negative)  
        bot.Attributes.MyY = 0 'Y position of the bot in centimeters (height)  
        bot.Attributes.MyZ = 0 'Z position of the bot in centimeters (N positive/S negative)  
        bot.Attributes.MyYaw = 0 'In tenths of a degree. (0 to 3599)
        result = bot.StateChange()

        If Not result = AW.Result.Success Then
            MsgBox("Error: " & result.ToString)
        End If
    End Sub

    Private Sub AW_EventAvatarAdd(ByVal sender As AW.Instance)

        Dim session As Integer = sender.Attributes.AvatarSession
        Dim name As String = sender.Attributes.AvatarName

        sender.Say("Greetings " & name & "! Welcome to Active Worlds :-)")
        'Or whisper to the user:
        'sender.Whisper(session, "Greetings " & name & "! Welcome to Active Worlds :-)")
    End Sub

    Private Sub AWTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AWTimer.Tick
        Utility.Wait(0)
    End Sub

End Class