Inconsistent results in simple script

Richard Gaskin ambassador at fourthworld.com
Wed Nov 16 16:07:35 EST 2016


JOHN PATTEN wrote:

 > I have two, two column lists. Each list has the same barcode item
 > (item 1). The second item in the first list is a username, and the
 > second item in the second list is a serial number. I am trying to
 > combine the username and serial number into one list. I have about
 > 1000 lines in each list. However, I have cut my username list down to
 > about 30. My script is leaving out username/serial number
 > combinations that are common in each list. I am not sure why?
 >
 > For example:
 >
 > List 1
 >
 > 12345,johndoe
 > 11234,maryjane
 > 12234,stevesmith
 >
 > List 2
 >
 > 12345,SDTKNY12345
 > 12234,SDTKLL54RR2
 > 11234,SDKTHYUPTO9
 >
 > I’m sure there are more elegant ways to do this, but here is my
 > script:
 >
 > on mouseUp
 >    lock screen
 >    put cd fld "csv1" into tcsv1
 >    repeat for number of lines in tcsv1
 >       put line 1 of tcsv1 into tStudentInfo
 >       put item 1 of tStudentInfo into tbarcode
 >       put the number of chars of tBarcode into tCharCount
 >       --    if tCharCount > 5 then
 >       --       delete char 1 of tbarcode
 >       --    end if
 >       put cd fld "csv2" into tcsv2
 >       find tBarcode in cd fld "csv2"
 >       if the result is empty then
 >          put the foundLine into tLine
 >          select tLine
 >          --put the selectedText of tcsv2 into tdeviceInfo
 >          put the selectedText of cd fld "csv2" into tDeviceInfo
 >          delete char 1 of item 2 of tDeviceInfo
 >          put item 2 of tStudentInfo & "," & item 2 of tDeviceInfo & 
return after tUploadFile
 >                else
 >       end if
 >       put empty into tStudentInfo
 >       put empty into tbarcode
 >       put empty into tCharCount
 >       put empty into tLine
 >       put empty into tDeviceInfo
 >       delete line 1 of tcsv1
 >    end repeat
 >    put tUploadFile into cd fld "Upload File"
 >    unlock screen
 > end mouseUp
 >
 >
 > Any suggestions would be helpful.


Try this:

on mouseUp
    put fld "csv1" into tStudentArray
    split tStudentArray by cr and comma
    put fld "csv2" into tDeviceArray
    split tDeviceArray by cr and comma
    repeat for each key tStudentID in tStudentArray
       put tStudentArray[tStudentID] into tStudentName
       put tDeviceArray[tStudentID] into tDeviceID
       put tStudentID &","& tStudentName &","& tDeviceID &cr \
           after tCombinedList
    end repeat
    delete last char of tCombinedList -- trailing CR
    put tCombinedList into fld "Upload File"
end mouseUp


-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the Use-livecode mailing list