I am using below code to construct the variable name using “String Concat” and get the value of the constructed variable. Is it possible?
Code :
[i]# Min values
ThresholdMinId0 = event.source.parent.getComponent(‘Numeric Text Field 29’).doubleValue
ThresholdMinId1 = event.source.parent.getComponent(‘Numeric Text Field 32’).doubleValue
ThresholdMinId2 = event.source.parent.getComponent(‘Numeric Text Field 34’).doubleValue
ThresholdMinId3 = event.source.parent.getComponent(‘Numeric Text Field 36’).doubleValue
Max values
ThresholdMaxId0 = event.source.parent.getComponent(‘Numeric Text Field 29’).doubleValue
ThresholdMaxId1 = event.source.parent.getComponent(‘Numeric Text Field 32’).doubleValue
ThresholdMaxId2 = event.source.parent.getComponent(‘Numeric Text Field 34’).doubleValue
ThresholdMaxId3 = event.source.parent.getComponent(‘Numeric Text Field 36’).doubleValue
for i in range(4):
IdFound = system.db.runScalarQuery("SELECT Id from table_thresholds where Id = " + “’” + str(i) + “’”)
ThresholdMinValue = Value(“ThresholdMinId%s”) %i
ThresholdMaxValue = “ThresholdMaxId%s” %i
print ThresholdMinValue, ThresholdMaxValue[/i]
Hi Dhananjay,
This is something that would actually be better handled by a list:
[code]#Initialize Lists
ThresholdMinId=ThresholdMaxId=[0.0]*4
Min values
ThresholdMinId[0] = event.source.parent.getComponent(‘Numeric Text Field 29’).doubleValue
ThresholdMinId[1] = event.source.parent.getComponent(‘Numeric Text Field 32’).doubleValue
ThresholdMinId[2] = event.source.parent.getComponent(‘Numeric Text Field 34’).doubleValue
ThresholdMinId[3] = event.source.parent.getComponent(‘Numeric Text Field 36’).doubleValue
Max values
ThresholdMaxId[0] = event.source.parent.getComponent(‘Numeric Text Field 29’).doubleValue
ThresholdMaxId[1] = event.source.parent.getComponent(‘Numeric Text Field 32’).doubleValue
ThresholdMaxId[2] = event.source.parent.getComponent(‘Numeric Text Field 34’).doubleValue
ThresholdMaxId[3] = event.source.parent.getComponent(‘Numeric Text Field 36’).doubleValue
for i in range(4):
IdFound = system.db.runScalarQuery(“SELECT Id from table_thresholds where Id = '” + str(i) + “’”)
ThresholdMinValue = ThresholdMinId[i]
ThresholdMaxValue = ThresholdMaxId[i]
print ThresholdMinValue, ThresholdMaxValue
[/code]
A brief explanation of the first line-- something I just learned this morning while thinking this through!
[0.0]*4 returns a list four elements long, each with a value of 0 (0.0 coerces it to float) This way, you can predefine the size of the list. 