Dim con as new oledb.oledbconnection("PROVIDER=Microsoft.jet.oledb.4.0;Data Source = C:\Program Files (x86)\HomeSeer HS3\scripts\sample.mdb") Const sRefMapFileName = "HS2_2_HS3_ref_map.ini" Sub Main(parm as object) Dim Cmd As OleDb.OleDbCommand Dim Reader As OleDb.OleDbDataReader Dim dv As Scheduler.Classes.DeviceClass Dim EN As Scheduler.Classes.clsDeviceEnumeration Dim hc As String Dim dC As String Dim sql As String Dim s As String Try hs.writelog("HS2->HS3", "# Start Mapping Devices By HC/DC #") con.open() EN = hs.GetDeviceEnumerator dv = EN.GetNext Do While Not EN.finished hc = left(dv.code(Nothing), 1) ' mid(dv.code(Nothing), len(dv.code(Nothing)) - 3, 1) dC = right(dv.code(Nothing), 2) hs.writelog("HS2->HS3 ", "Checking Name='" & dv.name(Nothing) & "' HC='" & hc & "' AND DC='" & dc & "'") ' Count sql = "Select COUNT(*) AS Ant FROM Devices WHERE hc = '" & hc & "' AND dc='" & DC & "'" Cmd = New OleDb.OleDbCommand(sql, Con) Reader = Cmd.ExecuteReader() If Reader.Read() Then If Reader.Item("Ant") > 1 Then hs.writelog("HS2->HS3 Error", "More than ONE device found with this Device HC='" & hc & "' AND DC='" & dc & "'") ElseIf Reader.Item("Ant") = 1 Then ' Get data sql = "Select * FROM Devices WHERE hc = '" & hc & "' AND dc='" & DC & "'" Cmd = New OleDb.OleDbCommand(sql, Con) Reader = Cmd.ExecuteReader() If Reader.Read() Then ' Ref mapping hs.writelog("HS2->HS3", "Mapping Device HC='" & hc & "' AND DC='" & dc & "'") s = Reader.Item("ref").ToString hs.SaveINISetting("Ref HS2 to HS3", s, dv.Ref(Nothing), sRefMapFileName) hs.SaveINISetting("Ref HS3 to HS2", dv.Ref(Nothing), s, sRefMapFileName) End If Else hs.writelog("HS2->HS3 Error", "Found Nr of devices = " & Reader.Item("Ant").tostring & " in HS2 database for Device HC='" & hc & "' AND DC='" & dc & "' Name=" & dv.name(Nothing)) End If Else hs.writelog("HS2->HS3 Error", "Cant find Device with this HC='" & hc & "' AND DC='" & dc & "'") End If ' text dv = EN.GetNext Loop con.close() hs.writelog("HS2->HS3", "# Done Mapping Devices By HC/DC #") Catch ex As Exception hs.WriteLog("HS2->HS3 Error", "Exception in script: " & ex.Message) End Try End Sub