Bug #101

Create scenario respond null object

Added by MrGoodFriend 3 months ago. Updated 21 days ago.

Status:Closed Start date:02/23/2012
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:DomotiGa
Target version:-
Resolution:

Description

When creating a new scenario a null object error message appear.

Looking in the code it's appear even wwhen a new thermostat is created, the name is compare to the current scenario name (which doesn't exist)

current code :

PUBLIC SUB btnSave_Click()

DIM rResultUpdate AS Result
DIM sSql AS String
DIM iRet AS Integer
IF NOT tbName.Text THEN
Balloon(("Please enter a name for this scenario!"), tbName)
RETURN
ENDIF
' name has changed
IF rResult!name <> tbName.Text THEN
IF ScenarioNameExist(tbName.Text) THEN
Balloon(("Please enter a unique name for this scenario!"), tbName)
RETURN
ENDIF
ENDIF
IF NOT (chkEnabled.Value) AND rResult!name = Main.GlobalVar["Thermostat_Mode"] THEN
iRet = Message.Question(("There will be no more enabled scenario, are you sure you want to continue ?"), ("Yes"), ("No"))
IF iret = 1 THEN
Main.GlobalVar["Thermostat_Mode"] = ""
ENDIF
IF iRet = 2 THEN
chkEnabled.Value = TRUE
RETURN
ENDIF
ENDIF
IF bAddScenario THEN
' create new scenario row
sSql = "INSERT INTO thermostat_scenarii SET name = &1, description= &2"
rResultUpdate = Main.hDB.Exec(sSql, tbName.Text, txtDescription.Text)
IF chkEnabled.Value THEN
IF Main.GlobalVar["Thermostat_Mode"] <> tbName.Text THEN
Main.GlobalVar["Thermostat_Mode"] = tbName.Text
Thermostat.DeleteAllDerogateHeating()
ENDIF
ENDIF
ELSE
' update new event details
sSql = "UPDATE thermostat_scenarii SET name = &1, description= &2 WHERE id = &3"
rResultUpdate = Main.hDB.Exec(sSql, tbName.Text, txtDescription.Text, rResult!id)
IF chkEnabled.Value THEN
IF Main.GlobalVar["Thermostat_Mode"] <> tbName.Text THEN
Main.GlobalVar["Thermostat_Mode"] = tbName.Text
Thermostat.DeleteAllDerogateHeating()
ENDIF
ENDIF
ENDIF
FThermostat.GetThermList()
bAddScenario = FALSE
ME.Close

END

Proposed code :

PUBLIC SUB btnSave_Click()

DIM rResultUpdate AS Result
DIM sSql AS String
DIM iRet AS Integer
IF NOT tbName.Text THEN
Balloon(("Please enter a name for this scenario!"), tbName)
RETURN
ENDIF
IF bAddScenario = FALSE THEN
' name has changed
IF rResult!name <> tbName.Text THEN
IF ScenarioNameExist(tbName.Text) THEN
Balloon(("Please enter a unique name for this scenario!"), tbName)
RETURN
ENDIF
ENDIF
IF NOT (chkEnabled.Value) AND rResult!name = Main.GlobalVar["Thermostat_Mode"] THEN
iRet = Message.Question(("There will be no more enabled scenario, are you sure you want to continue ?"), ("Yes"), ("No"))
IF iret = 1 THEN
Main.GlobalVar["Thermostat_Mode"] = ""
ENDIF
IF iRet = 2 THEN
chkEnabled.Value = TRUE
RETURN
ENDIF
ENDIF
ENDIF
IF bAddScenario = TRUE THEN
IF ScenarioNameExist(tbName.Text) THEN
Balloon(("Please enter a unique name for this scenario!"), tbName)
RETURN
ENDIF
' create new scenario row
sSql = "INSERT INTO thermostat_scenarii SET name = &1, description= &2"
rResultUpdate = Main.hDB.Exec(sSql, tbName.Text, txtDescription.Text)
IF chkEnabled.Value THEN
IF Main.GlobalVar["Thermostat_Mode"] <> tbName.Text THEN
Main.GlobalVar["Thermostat_Mode"] = tbName.Text
Thermostat.DeleteAllDerogateHeating()
ENDIF
ENDIF
ELSE
' update new event details
sSql = "UPDATE thermostat_scenarii SET name = &1, description= &2 WHERE id = &3"
rResultUpdate = Main.hDB.Exec(sSql, tbName.Text, txtDescription.Text, rResult!id)
IF chkEnabled.Value THEN
IF Main.GlobalVar["Thermostat_Mode"] <> tbName.Text THEN
Main.GlobalVar["Thermostat_Mode"] = tbName.Text
Thermostat.DeleteAllDerogateHeating()
ENDIF
ENDIF
ENDIF
FThermostat.GetThermList()
bAddScenario = FALSE
ME.Close

END

History

Updated by rdnzl 3 months ago

I added your fix to r835.
Thanks!

Updated by rdnzl 21 days ago

  • Status changed from New to Closed

Also available in: Atom PDF