12-17-2018 07:13 AM
Hi,
I am updating a set of scripts that were designed to be run independently so that they can also be run as a single continuous piece of code. That is to say, I've written a master script that the user can run and which calls the independent scripts in the right order without further intervention. The independent scripts must also remain viable when used independently.
To determine whether they are being run independently or not, I have defined a global variable called 'flag' in the master script, whose value can be assessed by each independent script to see which action it must take. The problem I have is that I want to check the condition where the flag either doesn't exist or has the value 0 and have used the following code to do that:
If ItemInfoGet("Flag") = False OR Flag = 0 then Call DataDelAll Call FileNameGet( "NAVIGATOR", "FileRead", DataDrvUser,"*.tdm","","","", "Get Data File") If (DlgState = "IDOk") Then ' Dialog closed with Ok Call DataFileLoad(FileDlgName,"","") else Call Autoquit End If End If
However, this doesn't work because if 'flag' hasn't been declared then 'flag = 0' throws an error because 'flag' isn't recognised. How do I correct this code to allow me to check for the existence of 'flag' and its value?
Thanks,
Simon.
12-17-2018 08:20 AM
By way of clarity, the following is the ugly code I've implemented to get around the problem:
If ItemInfoGet("Flag") = True then If Flag = 0 then Call DataDelAll Call FileNameGet( "NAVIGATOR", "FileRead", DataDrvUser,"*.tdm","","","", "Get Data File") If (DlgState = "IDOk") Then ' Dialog closed with Ok Call DataFileLoad(FileDlgName,"","") Else 'Call Autoquit Call Err.Raise (-1) End If End if Else Call DataDelAll Call FileNameGet( "NAVIGATOR", "FileRead", DataDrvUser,"*.tdm","","","", "Get Data File") If (DlgState = "IDOk") Then ' Dialog closed with Ok Call DataFileLoad(FileDlgName,"","") Else 'Call Autoquit Call Err.Raise (-1) End If End if
It turns out that I can refer to a non-existent variable without throwing an error providing it's inside the If statement and not in the If condition as before. So, if Flag exists then it checks for Flag=0 and, if true, carries out some action. If Flag does not exist then it carries out the same action, but I can't find a way of combining these two conditions into one neat line. If Flag=1 then the whole bunch of nested If statements is ignored (as required).
Regards,
Simon.