Link to home
Start Free TrialLog in
Avatar of sumanths_query
sumanths_query

asked on

check box & file operation

i have a check box which if i check i write a value into a file using basic file handling(not file system objects).

is it possible, if i uncheck the checkbox ,to delete the value written to the file while checking the checkbox ,thru code.

Avatar of sumanths_query
sumanths_query

ASKER

can anyone pls give me the code for the operation i have requested to be performed






thanx
Avatar of Ryan Chong
Try:

'!Create/Write File Content
Public Function WriteFileText(ByVal FileName As String, ByVal Source As String) As String
    On Error GoTo EHandler
    Dim Handle As Integer
    Handle = FreeFile
    Open FileName For Output As #Handle
        Print #Handle, Source
        On Error Resume Next
    Close #Handle
    Exit Function
EHandler:
    ShowErrMsg
    On Error Resume Next
    Close #Handle
End Function

In a form:

private sub command1_click()
   dim v as string
   if check1.value = 1 then v = "checked"
   
   WriteFileText "c:\abc.txt",v

end sub

Hope this helps
I am not sure whether this will help you.  I am wondering, are you writing a program setting to a file?  If that is the case, why don't you write the value registry as shown below.

Private Sub Check1_Click()
     ' Save the value to the registry
     SaveSetting App.Title, "Settings", "Check1", Check1.Value
End Sub

Private Sub Form_Load()
     ' load the check box value from the registry
     ' by default it is checked
     Check1.Value = GetSetting(App.Title, "Settings", "Check1", vbChecked)
End Sub

Hope this might have given you some useful info.  Good Luck!
sumanths_query:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
Avatar of YensidMod
YensidMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial