Announcement

Collapse
No announcement yet.

Pass Parameters to VB Script

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

  • #16
    I tried the split function after passing the single variable. It failed. There was no information in the string.
    the parameters in the event were ("Main","Temp Out,5")
    per the example specified.

    Comment


    • #17
      Try replacing the comma separator with a |
      -Rupp
      sigpic

      Comment


      • #18
        OK. Not a VB genius here, that's a given. But I usually get by reading and copying examples. I read and read and read this post again, and still getting no love passing multiple parameters to a VB.net script.

        Here are the parameters: ("Main","tester1,tester2,tester3")

        Here is the code:

        Code:
        Sub Main(ByVal parm as Object)
        
        Dim parms() As String
        dim st1 as String
        dim st2 as String
        dim st3 as String
        
        parms = Split(parm.ToString,",")
        st1 = parms(1)
        st2 = parms(2)
        st3 = parms(3)
        
        'If UBound(parm) > 2 then
        '      st1 = parm(1)
        '      st2 = parm(2)
        '      st3 = parm(3)
        'End If
        
        hs.WriteLog("Test Script", st1)
        hs.WriteLog("Test Script", st2)
        hs.WriteLog("Test Script", st3)
        
        End Sub
        I tried both the Split and Ubound methods, with and without ByVal parm and ByVal parm().

        How do I make this work?

        -BD

        Comment


        • #19
          Try testing it one step at a time by writing some stuff into the log

          hs.writelog("", parm.ToString) - does the log entry look like the parameter?
          hs.writelog("", UBound(parms)) - after you have split it of course, what is written in the log?

          Do you get any errors in the log?
          My Plugins:

          Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
          Yeelight 3P | Nanoleaf 3P

          Comment


          • #20
            Originally posted by BrunDog View Post
            parms = Split(parm.ToString,",")
            st1 = parms(1)
            st2 = parms(2)
            st3 = parms(3)
            You got it except for one simple mistake! In .NET, most everything is zero based (as it should be). When you created the array of 3 objects with the split command, they are in parms 0, 1, and 2 - not 1, 2, 3.

            When troubleshooting in the future, surround big chunks of code with Try/Catch until you see where it is failing, then break that section into smaller chunks until you find the problem. Here is an example of how you could have found this:

            Try
            parms = Split(parm.ToString,",")
            st1 = parms(1)
            st2 = parms(2)
            st3 = parms(3)

            Catch Ex As Exception
            hs.WriteLog("MyScript Error","Script exception in section 1 is:" & Ex.Message)
            End Try

            It would have shown an "out of bounds" exception as soon as it hit parms(3).


            Hope this helps.
            Regards,

            Rick Tinker (a.k.a. "Tink")

            Comment


            • #21
              Thought I replied to this earlier...

              Thank you so much for the correction... that resolved it! Also, thanks for the coding tip!

              -BD

              Comment


              • #22
                Thread necro...but this helped me

                Code:
                Sub Main(ByVal parm as Object)
                
                Dim parms() As String
                
                parms = Split(parm.ToString,",")
                
                For Each parm_string As String in parms
                  hs.WriteLog("Test Script", "Method A: " + parm_string)
                Next 
                
                For index As Integer = 0 To parms.Length -1
                  hs.WriteLog("Test Script", "Method B: " + parms(index))
                Next 
                
                
                End Sub
                Attached Files

                Comment

                Working...
                X