Get a Function's Return value When in a Loop


This is probably related to the ‘Getting Wait Cursor to Display’ issue. I have a loop that loads an array that will be a source for a grid. While loading I want to check if a photo exists for the data points in each row of the array. I am using PhoneGap’s File system Plugin. Everything works, but the timing and sequence is off such that the array loads before the photo exists function can return a value for each row. There are two rows evaluated below. Any guidance would be appreciated.

Sub gridDisplay_dataHandler(transaction, result) 
    gLastNumber = 0
    If DBRecords.rows.length > 0 Then
    For i=0 To DBRecords.rows.length-1
      picExists = "No"
      row["id"] = i;    
      row["DISPLAYNBR"] = record["DisplayNbr"]
      varPicture = Trim(gSelectedBroker) & "-" & Trim(record["Principal"]) & "-" & Trim(gSelectedChainNumber) & "-" & Trim(gSelectedStoreNumber) & "-" & CStr(Year(varDate)) & PhotoMonth & PhotoDay & "-" & CStr(record["DisplayNbr"])
      varPicture = gfolder & "/" &  varPicture & ".jpg"
      console.log(varPicture)   ' correctly Concatenated Line#:5914 
      gfileSystem.root.getFile(varPicture, {create: False}, FileEntryExists, FileEntryFails)
      console.log(picExists) ' reads "No"  Line#:  5914
      row["PIC"] = picExists
      data[i] = row 
    source = {localdata: data, datatype: "array"}
    dataAdapter = new $.jqx.dataAdapter(source)
    NSB.jqxSettings["gridDisplay"].source = dataAdapter
    End If
End Sub

Function FileEntryExists()
picExists = "Yes"
console.log("I am here in exists:" & picExists)  ' Line#: 5944
End Function

Function FileEntryFails()
picExists = "No"
console.log("I am here in Fails:" & picExists)  ' Line#:5950
End Function
Android/data/com.nsbasic.Meyes/files/Photos/NY-xBNGF-055-00214-20180130-1.jpg  --- code.js:5909

No  --- code.js:5914 

Android/data/com.nsbasic.Meyes/files/Photos/NY-xBNGF-055-00214-20180130-2.jpg --- code.js:5909

No --- code.js:5914 

Android/data/com.nsbasic.Meyes/files/Photos/NY-xBNGF-055-00214-20180130-3.jpg  ---code.js:5909 

No --- code.js:5914 

 I am here in exists:Yes  --- code.js:5944
 I am here in Fails:No  --- code.js:5950


You’re correct: the call to find out if the image exists is asynchronous: it won’t return until after the grid is drawn.

You will need to modify the affected cell in the grid using setcellvalue in your callback functions.


can it be set with cellrenderer function ?


I don’t know - I’m no expert on jqWidgets.

It seems to me cellrenderer is used in the initialization of the grid contents, not subsequent updating.