Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[Solved]Reading from DBF file and assigning value to checkbox

Status
Not open for further replies.

AnotherNovice1

Systems Engineer
Feb 9, 2021
17
0
0
DE
Hello everyone,

Is it possible to have a DBF file with some values (e.g. field01...field16 with bool values) and
assign that value (and enabling the checkbox) to a checkbox with similar naming?
The code for the loop doesn't seem to work, the values aren't set, the checboxes are disabled.

My form contains checkboxes with the naming "_chkV01" until "_chkV16".

My example code for that loop:
Code:
SELECT <DBF-file>
SET ORDER TO <order-field>
  SEEK <order-value>
  IF FOUND()
    FOR i = 1 TO 16
      oCheckboxValue = EVALUATE("thisform._chkV"+STRTRAN(STR(i,2),' ','0'))
      oCheckboxValue.Enabled = IIF(EVALUATE("value"+STRTRAN(STR(i,2),' ','0')),.T.,.F.)
      oCheckboxValue.Value = IIF(EVALUATE("value"+STRTRAN(STR(i,2),' ','0')),1,0)
    ENDFOR
  ENDIF

If I do things normally like this (16 times...):
Code:
thisform._chkV01.Value = IIF(value01,1,0)

But it feels so wrong.

EDIT: Ok, it worked, I forgot about another function which checks if the values are plausible...
That was the culprit of it.
 
You'd noirmally use the controlsource property and set it to field names.
I question a record design with 16 bool values, I'd rather have 16 records with each 1 bool values and the you can use a grid.
You see from your code complexity that it's not easy to address a series of checkboxes or numbered fields, this is always bad design.

You could do what you wnt without code with drag % drop from the forms data environment to the form. So
1. modify the form
2. open up the data environment. Many ways to do that, one is by menu "View"->"Data Environment"
3. If you don't have anything in the forms dataenvironment you will be asked to specify a table, use your dbf file there
4. Drag the single bool fields into the form 1 by 1 and with each field you get a label and a checkbox bound to that field.

If you don't want the table to be opened by the data environment you could even delete the dbf file from it, the controls will stay on the form and you may open up the dbf file again in init code or whenever you do now. Still too tedious to do? But you did add 16 checkboxes yourself ad had to name them all.

What's not happening is that the checkboxes with .F. value will be disabled, if you really want that (why?) you could program a checkbox calss that does so in its init:
Code:
This.Enabled = This.Value

A checkbox the is disabled when the value is .f. would now only allow the uncheck a box that's checked and thus enabled. Once it's unchecked it does not automatically disable though. if you want that the same code should be in the interactivechange event, for example.



Chriss
 
Hi!
Thanks for your input!
The problem with the naming is:
I have many products (hundreds) that need some checks (16 items to check if the product is OK).
And the 16 items can vary between each product.

It could be that item 01 can be used to check if product A has the correct outer diameter,
but item 01 can also be used on product B to check if the inner diameter is correct.

And the check has to be double times enabled if the machine does the check AND the human after it has to check that value.
If the machine doesn't have to check the value the human also shouldn't.

That's why I have the bool values numbered, sadly...

Also the problem got solved, I messed up at another part of it when doing a sanity check...
 
That's all not hindering to put the 16 values into 16 records instead of 16 fields.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top