Hello,
The code below is a keyPressed event script of a formatted text field.
I have the problem that the If condition inside the for-loop below is always being executed. I printed the values and there are definitely not the same. So I don't understand what is happening here or am I overlooking something? Thats the whole script for the moment. After the for loop, I later want to check if flowVar is still false and then set the background color of my formatted text field to red, to indicate that the entered ID was not found.
if event.keyCode==event.VK_ENTER:
user_input=event.source.text
folderPath=event.source.parent.dataPath
folderArchiv = folderPath + "/AlarmData/alarmArchiv"
tableName="Alarm_" + str(folderPath.rsplit("/", 1)[1])
start= system.gui.getWindow("Standard Window/Alarms").getRootContainer().getComponent("Cal_Start").date
end= system.gui.getWindow("Standard Window/Alarms").getRootContainer().getComponent("Cal_End").date
count_result=0
duration_result=0
flowVar=False
forderTagPaths=str(folderPath) +"/AlarmData/alarmList"
tagPaths=system.tag.readBlocking(forderTagPaths)[0].value
for x in range(tagPaths.rowCount):
identification = tagPaths.getValueAt(x,0)
if user_input==identification:
count_result=system.db.runNamedQuery("countStop", {"tableName":tableName, "start":start, "end":end , "user_input":user_input})
duration_result = system.db.runNamedQuery("calculateDurationStop", {"tableName":tableName, "start":start, "end":end , "user_input":user_input})
if duration_result==None:
duration_result=0
event.source.parent.getComponent("lblnumberStops").text=str(count_result)
event.source.parent.getComponent("lbltotalDur").text=shared.Func_Dataset.format_duration(duration_result)
flowVar=True
system.gui.messageBox(user_input)
system.gui.messageBox(identification)
Of course the input changes. That is an input component, so each time the user type an ID and valide it through ENTER the script get executed. The users can enter what ever the want as as it is numbers and the lengh is 13 (validation Mode: regular expression)
But it doesn't change IN the script. Which makes comparing to it in a loop pointless.
this:
for x in range(tagPaths.rowCount):
identification = tagPaths.getValueAt(x,0)
if user_input==identification:
can be written like this:
if user_input in tagPaths.getColumnAsList(0):
No need for a loop. Unless the input can be in in tagPaths more than once ?
Actually, even if it appears more than once, the exact same operations would get repeated, which is pointless.
I'm not sure but there are a few weirdnesses with assigning components content to variables in scripts.
I've been burn by terribly counter-intuitive behavior, but I don't think it applies there.
Maybe someone else will have an answer for you...
here:
Edit:
Actually it does apply there.
If something changed the value in your input component...
You'd expect the input to be a constant, but it's actually not.
But there's no reason it would work with the in version...
This problem is really driving me crasy. It doesn't work anymore. The same problem still persists. I have to finish work now. I will open a new topic on monday. Thats how the script looks now
I have also printed the value of event.source.text and the value is always the same that I enter in the formatted text field. And it is also easy to know that a value is not available in my IDs database because all the IDs start with (just an example) 00000 and I will enter something starting with 22222 in the field. I have also printed the value of flowVar and it is always True.
Maybe I should mention that the script is in an inheritable project?
Update:
when I remove the event.keyCode==event.VK_ENTER: at the beginning of script, it works. Also when I move the script to a mouseClicked event for example. It sounds absurd, but maybe the problem is the if-loop inside the if-loop?