Announcement
Collapse
No announcement yet.
hs.getinisetting issue
Collapse
X
-
very good !
send you a pm , that one works on this script , but this script is old , i send you the correct script in a pm
regards
//sended right now
Leave a comment:
-
Change your script to this:
PHP Code:Sub pir(ByVal Parms As Object)
Dim pirdisabled_count As Integer = 0
Dim pirenabled_count As Integer = 0
Dim pir_name As String = ""
Dim pstr As String = ""
Dim dv As Scheduler.Classes.DeviceClass = Nothing
Dim array_pir() As String = hs.GetINISetting("xml", "Devices", "", INI_FILE).split(",")
Try
pirdisabled_count = 0
pirenabled_count = 0
pir_name = ""
pstr = ""
For Each devp As String In array_pir
Select Case hs.DeviceValue(devp)
Case 0
dv = hs.GetDeviceByRef(devp)
pir_name = dv.Name(hs)
pirenabled_count = pirenabled_count + 1
hs.speak(pir_name & " standby")
Case 1
hs.speak("person detected in the **")
Case 11
pirdisabled_count = pirdisabled_count + 1
Case 15
hs.speak("P I R in the ** is Enabled")
Case Else 'Optional
hs.speak("P I R in the garden has an error please check the battery")
End Select
Next
If pirdisabled_count > 0 Then
hs.speak("found some")
Else
hs.speak("no count")
End If
hs.speak(pirdisabled_count, True, "$SONOS$TTS")
hs.writelog("Array", "enabled pir's: " & pirenabled_count)
hs.writelog("Array", "disabled pir's: " & pirdisabled_count)
Catch ex As Exception
hs.WriteLog("Array", "Error: " & ex.Message)
End Try
End Sub
Devices=2212,2212,2216
Leave a comment:
-
ok , i want to use the dynamic way but it doesnt work
i always get an error
i show you what kind of script im using :
PHP Code:Dim array_pir() As String = {"2704", "2698", "2517"}
Dim pirdisabled_count As Integer = 0
Dim pirenabled_count As Integer = 0
Dim pir_name As String = ""
Dim pstr As String = ""
Dim dv As Scheduler.Classes.DeviceClass = Nothing
Sub pir(ByVal Parms As Object)
Try
pirdisabled_count = 0
pirenabled_count = 0
pir_name = ""
pstr = ""
For Each devp As String In array_pir
Select Case hs.DeviceValue(devp)
Case 0
dv = hs.GetDeviceByRef(devp)
pir_name = dv.Name(hs)
pirenabled_count = pirenabled_count + 1
hs.speak(pir_name & " standby")
Case 1
hs.speak("person detected in the **")
Case 11
pirdisabled_count = pirdisabled_count + 1
Case 15
hs.speak("P I R in the ** is Enabled")
Case Else 'Optional
hs.speak("P I R in the garden has an error please check the battery")
End Select
Next
If pirdisabled_count > 0 Then
hs.speak("found some")
Else
hs.speak("no count")
End If
hs.speak(pirdisabled_count, True, "$SONOS$TTS")
hs.writelog("Array", "enabled pir's: " & pirenabled_count)
hs.writelog("Array", "disabled pir's: " & pirdisabled_count)
Catch ex As Exception
hs.WriteLog("Array", "Error: " & ex.Message)
End Try
End Sub
this line :
Dim array_pir() As String = {"2704", "2698", "2517"}
i want that it reads from the ini file instead of hardcoding it
it still gives me errors
PHP Code:Aug-18 15:24:16 Array Error: Object reference not set to an instance of an object.
Originally posted by rmasonjr View PostThe use of the curly braces is for hard-coding the array list in the code.
The method I posted was for a dynamic way of passing in a list of values.
For testing purposes, you can use:
Devices=2212,2212,2216
Dim Devices As String = hs.GetINISetting("xml","Devices","", INI_FILE)
Dim x As Integer
''Dim ary() As String = Devices.Split(",")
dim ary() as string = {"1234","5678"}
For x = 0 To ary.Length - 1
hs.Speak(ary(x)
Next
Leave a comment:
-
The use of the curly braces is for hard-coding the array list in the code.
The method I posted was for a dynamic way of passing in a list of values.
For testing purposes, you can use:
Devices=2212,2212,2216
Dim Devices As String = hs.GetINISetting("xml","Devices","", INI_FILE)
Dim x As Integer
''Dim ary() As String = Devices.Split(",")
dim ary() as string = {"1234","5678"}
For x = 0 To ary.Length - 1
hs.Speak(ary(x)
Next
Leave a comment:
-
thanks ,
i still get this error
Aug-18 15:24:16 Array Error: Object reference not set to an instance of an object.
normal my script needs to read the array like this when u pt it manual in there :
dim array_pir() as string = {"2623","2622","2626"}
but i want to use a ini instead
the hs.speak was only for testing the output
Originally posted by rmasonjr View PostYou should be able to use:
Devices=2212,2212,2216
Then just convert it to an array using Split:
Dim Devices As String = hs.GetINISetting("xml","Devices","", INI_FILE)
Dim x As Integer
Dim ary() As String = Devices.Split(",")
For x = 0 To ary.Length - 1
hs.Speak(ary(x)
Next
Leave a comment:
-
You should be able to use:
Devices=2212,2212,2216
Then just convert it to an array using Split:
Dim Devices As String = hs.GetINISetting("xml","Devices","", INI_FILE)
Dim x As Integer
Dim ary() As String = Devices.Split(",")
For x = 0 To ary.Length - 1
hs.Speak(ary(x)
Next
Leave a comment:
-
i did also try this Inside the sub main :
PHP Code:dim devices as string = hs.GetINISetting("xml","Devices","", INI_FILE)
hs.speak (devices)
dim array_pir() as string = {devices}
PHP Code:[XML]
Devices="2212","2212","2216"
PHP Code:Aug-18 13:57:13 Array Error: Conversion from string "2212","2212","2216" to type 'Integer' is not valid.
Aug-18 13:57:08 TTS Speak ():2212","2212","2216
i really out of options here , dont know what to do , i know its possible
Leave a comment:
-
hs.getinisetting issue
SOlved!
Hi all
i have build many scripts that contain hs.getinisetting
but here is a problem with reading it .
it needs to read the array from an ini file
in the ini file it looks like this
PHP Code:[XML]
Devices={"2212"}
this is in the very beginning ,
Const INI_FILE As String = "PIR_TEST.ini"
dim devices as string = hs.GetINISetting("xml","Devices","", INI_FILE)
dim array_pir() as string = devices
THis gives this error :
PHP Code:Value of type 'String' cannot be converted to '1-dimensional array of String'.
it looks like he doesnt accept devices as an array string , how can i solve it ?
RegardsTags: None
Leave a comment: