Announcement

Collapse
No announcement yet.

Beginners help in scripting C# vs VB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Beginners help in scripting C# vs VB

    Hi,
    I just switched over from Vera to Homeseer. I know my way around with LUA and programming plugins in Vera but HomeSeer is a whole new ball game. I've never scripted in C# nor VB.
    I hope someone can answer some of my questions.

    I'm running HS3Pro on a Linux Debian Jessie VM.

    1. VB vs C#
    The HomeSeer documentation states that C# offers better performance over vb scripting still all scripts that are on the updates are written in vb why?

    2. Are there other benefits other then performance writing in VB vs C#

    3. Where and how should I start?
    Should I install Windows with HS3 and Visual studio as a dev client and use the created scripts in the event window of HomeSeer or are there other possibilities for testing the created scripts/plugins.

    4. I wanted to start recreating some of my Lua scripts. example doorbell is pressed create 4 variables that saves the picture and push 1 picture by ftp to my server and send 4 pictures to my mail. clear the variables.
    just to pick one element of the script. the sendmail is possible in various options
    a. the hs.SendEmail (only allows 1 attachement)
    b. objEmail.Send (haven't tested this yet.
    c. c# new MailMessage(); (see below)

    I tried to use

    Code:
    public void email_send()
    {
        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient("SMTP-SERVER");
        mail.From = new MailAddress("FROM-EMAIL");
        mail.To.Add("TO-EMAIL");
        mail.Subject = "Test Mail - 1";
        mail.Body = "test";
        SmtpServer.Port = 25;
        SmtpServer.Send(mail);
    
    }
    But this gives me the error
    Code:
    he type or namespace name `MailMessage' could not be found. Are you missing a using directive or an assembly reference? {interactive}(17,5): error CS0246: The type or namespace name `SmtpClient' could not be found.
    Is this because I'm missing some dependencies?

    5. Last question. What is the best practice in creating events.
    Use the GUI as much as possible or create a script that will do the same?

    #2
    Hi Alan,

    Historically VBScript and vb.net scripts were supported in HS so most long time users are more familiar with them. I typically only create vb.net scripts now as the vbscript ones are not supported under linux/mono. The help file does state that c# scripts should run better on linux, but I suspect the difference is negligible. I have seen some reports of memory leaks with c# scripts though. From what I've seen, people that post scripts they need help with, get much better response with vb.net than with c#, because more people are familiar with them. There's a great tool called Tenscripting that integrates with Visual Studio and HS and allows you to step through and test scripts: https://forums.homeseer.com/showthread.php?t=160484.

    For your example, I do believe you are missing a dependency. When I get back to my desk, I'll take a look unless someone jumps in before.

    I use scripting extensively to minimize the number of events needed. However, there's no wrong or right way, just do it the way you are most comfortable with.

    Cheers
    Al
    Last edited by sparkman; January 3, 2017, 12:00 PM. Reason: sp
    HS 3.0.0.548: 1990 Devices 1172 Events
    Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

    Comment


      #3
      Just to add to Al's post, Homeseer is actually written in VB.NET so all the examples use that language.

      The performance thing with C# is a red herring IMO. VB.NET may take slightly longer to compile than C# (on Linux) but once done, it runs just as fast.

      Rich (who wrote HS3) stated this in a recent post:

      Note, you can use vb.net on the Zee, its slow the first time its run, but after that it will be quick since it will be compiled.
      As Al has stated, several people have reported Memory leaks with the C# compiler. Example post: https://board.homeseer.com/showpost....26&postcount=3

      Homeseer has built-in zip capability so you can send your images zipped as an attachment if you want.

      The functions to create an event via scripting is limited. It far better to use the GUI for this.
      Jon

      Comment


        #4
        If you plan on writing many scripts, than I would recommend using .vb and viewing these videos.

        tenholde
        tenholde

        Comment


          #5
          Best to use C#.
          Microsoft has started to kill off VB for making new projects in Visual Studio 2015 under the latest version of .Net.

          Comment


            #6
            Originally posted by dtsouers View Post
            Best to use C#.
            Microsoft has started to kill off VB for making new projects in Visual Studio 2015 under the latest version of .Net.
            I'm not sure how that is relevant since HS3 is written in .NET4?
            Jon

            Comment


              #7
              Im still learning myself, but the biggest reason I go with VB vs C# is it's easier to read. C# is truncated a lot and as a beginner, it was hard for me to completely understand what was happening under the hood.

              VB to me reads like a book and is much easier to code in.

              Comment


                #8
                Thanks everyone for the feedback it's been really helpfull

                Originally posted by sparkman View Post
                There's a great tool called Tenscripting that integrates with Visual Studio and HS and allows you to step through and test scripts: https://forums.homeseer.com/showthread.php?t=160484.
                Al
                This is exactly what I was looking for thank you. Just too bad I can only use the HS3 license just once. I'll just take a snapshot and revert back each time I want to test a script.

                Originally posted by jon00 View Post
                As Al has stated, several people have reported Memory leaks with the C# compiler. Example post: https://board.homeseer.com/showpost....26&postcount=3
                I'll stay away from C# till that's fixed. The reason I moved away from Vera is because of the many memory leaks.

                Originally posted by dtsouers View Post
                Best to use C#.
                Microsoft has started to kill off VB for making new projects in Visual Studio 2015 under the latest version of .Net.
                I'll take my chance on this one. Silverlight supposelly should be end of life since 2012 but is even used in new Ms application.
                Also Waynehead99 statement that learning vbnet is easer makes the choice for vb.net more logicall for me.

                Comment


                  #9
                  Originally posted by alan_smithee View Post
                  This is exactly what I was looking for thank you. Just too bad I can only use the HS3 license just once. I'll just take a snapshot and revert back each time I want to test a script.
                  You're welcome! You can run Visual Studio and tenscripting on a different system than your HS3 system, so no need to take a snapshot or use a separate license.

                  Cheers
                  Al
                  HS 3.0.0.548: 1990 Devices 1172 Events
                  Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                  Comment


                    #10
                    Originally posted by sparkman View Post
                    For your example, I do believe you are missing a dependency. When I get back to my desk, I'll take a look unless someone jumps in before.
                    I think you need to add:

                    Code:
                    Imports System.Web.Mail
                    at the beginning of a vb.net file. Not sure about syntax for c# for that. You may need to add:

                    Code:
                    Imports System.IO
                    for the attachments.

                    Cheers
                    Al
                    HS 3.0.0.548: 1990 Devices 1172 Events
                    Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                    Comment


                      #11
                      Originally posted by sparkman View Post
                      I think you need to add:

                      Code:
                      Imports System.Web.Mail
                      at the beginning of a vb.net file. Not sure about syntax for c# for that. You may need to add:

                      Code:
                      Imports System.IO
                      for the attachments.

                      Cheers
                      Al

                      Thank you again. I'll start testing when I finished installing tenscripting and Visual Studio.

                      Comment


                        #12
                        Originally posted by waynehead99 View Post
                        Im still learning myself, but the biggest reason I go with VB vs C# is it's easier to read. C# is truncated a lot and as a beginner, it was hard for me to completely understand what was happening under the hood.

                        VB to me reads like a book and is much easier to code in.
                        I'm a C# developer and find VB.NET awkward. Unfortunately HS's C# support is so quirky I usually give up and use VB.NET.

                        Comment

                        Working...
                        X