Hello Amor,
Please note that the first record is filled up using ResultSetCurrentPosition ( ) and formfieldValue ( ). And after doing that the rest of the records are filled up using FormNewRecord ( ) using Loop.
var vRSHandle as Int
var nn as Int
var n as Int
var vLoop as Int
var vMedicine as String
var vInstruction as String
var vKey as String
var vNextNumber as String
If @Mode ( ) = 0 then
{
vRSHandle = @XResultSetSearch("Data\MedicalTest.db", "Index", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!RecNumber=" + RecNumber)
if(vRSHandle > -1)
{
// In table view the First Record is always there and it empty. Loop can be used only after that is filled out.
vMedicine = @xResultSetValue (vRSHandle, "M1" )
vInstruction = @xResultSetValue (vRSHandle, "I1")
If vMedicine <> "" and @FormFieldValue ("Scripts", "Medicine", 1) = "" then
{
FormResultsetCurrentPosition ("Scripts", 1)
FormFieldValue ("Scripts", "Medicine", 1, vMedicine)
FormFieldValue ("Scripts", "Instruction", 1, vInstruction)
FormFieldValue ("Scripts", "RecNumber", 1, RecNumber)
vNextNumber = @ToNumber (@GlobalValue ("ScriptNumber")) + 1 //Create Unique Number for Key field
//WriteLn ("This is Next Number " + vNextNumber)
GlobalValue ("ScriptNumber", vNextNumber)
vNextNumber = @text (7 - @Len (vNextNumber), "0") + vNextNumber
vKey = vNextNumber
FormFieldValue ("Scripts", "Key", 1, vKey)
FormCommit ("Scripts")
}
For vLoop = 2 to 15
vMedicine = @xResultSetValue (vRSHandle, "M" + @Str (vLoop))
vInstruction = @xResultSetValue (vRSHandle, "I" + @Str (vLoop))
If vMedicine <> "" and @FormFieldValue ("Scripts", "Medicine", vLoop) = "" then
{
nn = @FormNewRecord ("Scripts")
//WriteLN ("vLoop = " + @str (vLoop))
//WriteLN ("nn = " + @str (nn))
FormFieldValue ("Scripts", "Medicine", vLoop, vMedicine)
FormFieldValue ("Scripts", "Instruction", vLoop, vInstruction)
FormFieldValue ("Scripts", "RecNumber", vLoop, RecNumber)
vNextNumber = @ToNumber (@GlobalValue ("ScriptNumber")) + 1 //Create Unique Number for Key field
//WriteLn ("This is Next Number " + vNextNumber)
GlobalValue ("ScriptNumber", vNextNumber)
vNextNumber = @text (7 - @Len (vNextNumber), "0") + vNextNumber
vKey = vNextNumber
FormFieldValue ("Scripts", "Key", vLoop, vKey)
FormCommit ("Scripts")
}
Else if vMedicine = "" then //If no more Regular Medicine then ends the loop
{
vLoop =15
}
Next
XResultSetClose(vRSHandle)
//WriteLN (" vRSHandle is Closed")
}
}