Comparing Strings and Numbers

I have a piece of lab equipment that has a carousel they load tests on. As they load the samples, they enter the sample data in a table on my FPMI interface. My application reads data from the lab equipment and matches them up to the samples in the carousel. Sometimes, they pull the next sample from the carousel and replace it with a higher priority sample. When they do that, they enter the new sample number and slot they put the new sample in. When I get the new information from an input box, I check that there is not already a value in the table with that record number or in that slot. The problem is that I never get a match on the record number or slot entered vs the numbers in the table. I think the problem might be that they are entering the value as a string and I am compairing it with an integer. Can I cast the input value as a number before doing the compairson?

Ttable = event.source.parent.getComponent('tblIdent')
existingDataSet = fpmi.db.toPyDataSet(Ttable.data) 

recNum = fpmi.gui.inputBox("Enter ID you want this test entered as","")
for row in existingDataSet:
    if recNum == row[0]:
        ErrorFlag = 1

if ErrorFlag:
    fpmi.gui.errorBox("Test ID number already present in the list","Data Error Found")

If I add a print statement to see the values, I do see that they match, but they are never equal. (recNum = 1,row = 1)

Your hunch was right - “1” does not equal 1.

you can cast the string to an int with the int() function, so the relevant line would look like:

if int(recNum) == row[0]:

Works perfect. I knew I had seen it somewhere, but could not find it. I’ll write it down for next time. You guys are the best…