Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
9
Erster Beitrag:
vor 11 Monaten
Letzter Beitrag:
vor 10 Monaten, 4 Wochen
Beteiligte Autoren:
Bill Quinn, Al, Allard

For Each Row skipping table records

Startbeitrag von Bill Quinn am 29.12.2016 18:56

Hi All,

Using WD21...I have a window for a parent/child relation. I collect the parent data and have a table to collect the child data. I enter 2 children and can see them both using WDMap. In the Validate button on the parent window the following code only processes the first child table record. The TableSave does work. But after the first record, it continues to the code following the loop ignoring the second record. Any thoughts?

ScreenToFile()

HSave(BlastingLog)

FOR EACH ROW OF TABLE_BlastingLogDetail
TABLE_BlastingLogDetail.COL_BlastingLogID = BlastingLog.BlastingLogID
TABLE_BlastingLogDetail.COL_JobID = BlastingLog.JobID

TableSave(TABLE_BlastingLogDetail)
END



Thanks, Bill

Antworten:

Update... I've found that if I click on a header in the child table to sort the records, the For Each processes all the records. What am I missing?

Bill

von Bill Quinn - am 29.12.2016 19:31
Hi

Quote
Bill
FOR EACH ROW OF TABLE_BlastingLogDetail
TABLE_BlastingLogDetail.COL_BlastingLogID = BlastingLog.BlastingLogID
TABLE_BlastingLogDetail.COL_JobID = BlastingLog.JobID

TableSave(TABLE_BlastingLogDetail)


you are assigning values form the BlastingLog file to the chield table. I donnot think this is what you want to do in the validate button. If this is a button to save a file.

You talk about entering in the child values and being able to see the values in WD map? So your table saves input directly? The table is bound by databinding I guess?

In you rcode you ad new values to the tabel and then do a table save(). The table save() will do save the new entry through the data binding.
Your code does the same thing but first enters new values in the table.



I would take an other approuch.

Add a table and donnot bind it and save the table


FOR EACH ROW OF TABLE_BlastingLogDetail
BlastingLogDetail.BlastingLogID = BlastingLog.BlastingLogID

end
hadd(BlastingLogDetail)

REGARDS
ALLARD

von Allard - am 29.12.2016 20:17
Thanks Allard but I actually have it set up so that the child table is on the window of the parent. Under the table are New/Modify/Delete buttons that open a window bound to the BlastingLogDetail file. The data for the detail record is entered and then shown on the table control on the parent. The table control's columns are bound to the respective columns in the file.

The For Each is to assign the parent's ID to the child records.

FYI - I'm using HFSQL classic.

Bill

von Bill Quinn - am 29.12.2016 20:41
Hello Bill

In my experience, the For Each construction doesn't work if you change a value in the table row because as soon as you do that, it exits.

Try using the older method

TCount is int = Tablecount(TABLE_BlastingLogDetail)
i is int
FOR i = 1 to TCount
TABLE_BlastingLogDetail.COL_BlastingLogID = BlastingLog.BlastingLogID
TABLE_BlastingLogDetail.COL_JobID = BlastingLog.JobID

TableSave(TABLE_BlastingLogDetail)
END //FOR i = 1 to TCount

Regards
Al


von Al - am 29.12.2016 21:46
Thanks Al!! Your suggestion worked (along with a TableSelectPlus at the top of the loop).

Strange thing is, I have 2 other windows for other parent/child pairs that use the same For Each concept without any issues.

von Bill Quinn - am 29.12.2016 22:11
Hello Bill

Glad it worked - sorry about forgetting the TableSelectPlus()

Regards
Al

von Al - am 29.12.2016 22:59
No problem Al....still learning WD so it was a nice simple test!

Bill

von Bill Quinn - am 29.12.2016 23:25
Hi Bill,

Glad it works for you.

You can also put in the row exit code of the table:

TABLE_BlastingLogDetail.COL_BlastingLogID = BlastingLog.BlastingLogID
TABLE_BlastingLogDetail.COL_JobID = BlastingLog.JobID

This will add and ID to the table when you change a row

Regards
Allard

von Allard - am 30.12.2016 10:18
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.