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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save control item values for load later for its

Status
Not open for further replies.

kosta

Programmer
Feb 9, 2001
186
CA
Hi All,
i wantto keep textbox,checkbox,optiongroup,combobox etc. selected or filled values on my query forms and store these values to a .dbf file for use later that users can be load from file and controls will be autofill with saved values . for this target how wouldbe .dbf file structure and how can i save its to the file and restore its from file ?

TIA

Soykan OEZCELIK
 
This is largely a matter of preference/application architecture.

I like having one file for parameters, with a single function for accessing the file, something like:
(now, recognize this code isn't production ready... I didn't put in error checking, etc)
Code:
CREATE Params ( Param C(20), Value C(30) )

* in form.init:
THISFORM.cTextBoxOneValueProperty = ParamValue( 'FirstName',  space(30) )

* in form.close_button.click:
ParamValue( 'FirstName',  THISFORM.cTextBoxOneValueProperty, .t. )

* In form.textboxone property sheet:
ControlSource = "THISFORM.cTextBoxOneValueProperty"

* in your main .PRG file:
FUNCTION ParamValue( tcParam, tvDefValue, tlSet )
LOCAL laRes[1]
  if not used('Params')
    USE PARAMS IN 0 SHARED
  ENDIF
  if tlSet
    UPDATE Params SET value=Seraialize(tvDefValue) WHERE Params.Param LIKE tcParam 
    REUTRN tvDefValue
  else
    SELECT TOP 1 Value FROM Params WHERE Params.Param LIKE tcParam INTO ARRAY laRes
    IF _Tally=0
      INSERT INTO Params ( param, value ) values ( tcParam, Serialize(tvDefValue) )
      RETURN tvDefValue
    ENDIF
    RETURN DeSerialize( laRes[1] )
  ENDIF
ENDFUNC

FUNCTION Serialize( tvValue )
  DO CASE
    CASE type('tvValue')='C'
      RETURN 'C:'+tvValue
    CASE type('tvValue')='D'
      RETURN 'D:{^ '+tran(Year(tvValue))+'/'+tran(month(tvValue))+'/'+Tran(day(tvValue))+'}'
**... etc for each type you care about.
  ENDCASE
ENDFUNC
FUNCTION DeSerialize( tcValue )
  DO CASE
    CASE tcValue='C:'
      RETURN SUBSTR(tcValue,3)
    CASE tcValue='D:'
      RETURN eval(substr(tcValue,3))
**... etc for each type you care about.
  ENDCASE
ENDFUNC

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top