PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WB18] Check if {"tablename."+ fieldvar} exists
[WB18] Check if {"tablename."+ fieldvar} exists
Débuté par Randall, 16 juil. 2014 18:23 - 8 réponses
Posté le 16 juillet 2014 - 18:23
There are some numbered fields in a table, i.e. field1, field2,field3,...,field8,etc.

I understand how the fieldname could be referenced using indirection and an incrementing integer, but how could it be checked to see if it exists?

Thanks in advance for any help on this...
Posté le 16 juillet 2014 - 19:35
Hi Randall

with ControlExist ?

Best regards
Posté le 16 juillet 2014 - 20:05
Hi Fabrice,

Thank you for your reply... but none of these "field1", "field2","field3", etc. have any controls associated with them. They are used to basically divide up a number. Think of the number as being a pie that is divided into several pieces... and someone decides to divide one of the pieces in half, so another "field4", or "field5", etc. is added. It's hard-coded for the time being, but the number of fields is subject to change. How would I be able to check how many of these fields exist?

Thanks again...
Posté le 17 juillet 2014 - 01:24
Hello Randall

You could build an array of the table columns names to use as a lookup or use an exception to trap the error when you try to use a non existant column ?

Regards
Al
Posté le 17 juillet 2014 - 10:28
list the items of the table using HListItem
Posté le 17 juillet 2014 - 15:42
Hi Randall

in the windev world, a table is a control on a window or a page. I am now guessing that you are talking about a FILE.

To check what fields exist in a FILE, the best way is to use hlistitem on the FILE then search for the field name in the resulting string

Best regards
Posté le 17 juillet 2014 - 22:39
you could do:

when exception in sContent={'File.Item",indItem} do sContent="" end if sContent<>"" then info(sContent) end
Posté le 21 juillet 2014 - 21:25
Hi Forum,

Thank you... HListItem is what I was looking for.

I'm not sure if this is the most efficient way of going about it, but it got me where I was going...
sFieldList is string = HListItem(filename) lastfield is int = 1 FOR EACH STRING sField OF sFieldList SEPARATED BY CR IF Position(sFieldList,"FIELD"+ NumToString(lastfield)) > 0 THEN lastfield++ ELSE BREAK END END Sorry about the earlier confusion of referring to a File as a Table... that reference is going to die hard.

Thanks again...
Posté le 21 juillet 2014 - 22:35
Hi Randall,

The most efficient way would be to specifically read the field number. Here is a pseudo-code:

sFieldList is string = HListItem(filename) lastfield is int FOR EACH STRING sField OF sFieldList SEPARATED BY CR IF sField [~ "FIELD" THEN lastfield = Max(Val(sField[[6 TO]]),lastfield) END END
Best regards,
Alexandre Leclerc