VB6 Checkbox read

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wernerh
    New Member
    • Jul 2007
    • 104

    VB6 Checkbox read

    Good day all, newbie here.

    I have written the code to output the checkbox to a txt file for record purposes. The "Tick"......... . so that at run time it reads the "setting" of this box.

    [CODE=vb]Dim set1 As String
    fileName = App.Path & "\" & "\data\set1.txt "
    set1 = FreeFile
    Open fileName For Output As #set1
    Print #set1, Check1
    Close #set1[/CODE]

    Firstly in my text file the result is listed as " 1" - Is that correct?
    Secondly on reading the data back I am not sure what the parameter should be in the code below marked with "?" error = Method or datamember not found

    [CODE=vb]Dim set1 As Integer
    fileName = App.Path & "\" & "\data\set1.txt "
    set1 = FreeFile
    Open fileName For Input As #set1
    While Not EOF(set1)
    Line Input #set1, tempStr
    Check1.Text ??????? = Check1.Text ???????? & tempStr
    Wend
    Close #set1[/CODE]

    If anyone could shed light it would be appreciated

    Thanks
    Last edited by Killer42; Aug 10 '07, 09:39 AM. Reason: Please use [CODE=vb]...[/CODE] tags around your code.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    I think you're missing a couple of fundamental points here.
    1. When you simply refer to a control, as in Print #set1, Check1 without specifying what property you mean, VB will select the default property. In the case of a checkbox control, that's the Value property. Which mean that you will be writing a 0 or a 1 to the file. (Or possibly a 2, but probably not.)
    2. Checkboxes do not have a Text property. They have a Caption property (the label, displaying such things as "Check1" or "Click here"). In this case though, you are more likely trying to read back the Value property.

    Comment

    • Wernerh
      New Member
      • Jul 2007
      • 104

      #3
      Originally posted by Killer42
      I think you're missing a couple of fundamental points here.
      1. When you simply refer to a control, as in Print #set1, Check1 without specifying what property you mean, VB will select the default property. In the case of a checkbox control, that's the Value property. Which mean that you will be writing a 0 or a 1 to the file. (Or possibly a 2, but probably not.)
      2. Checkboxes do not have a Text property. They have a Caption property (the label, displaying such things as "Check1" or "Click here"). In this case though, you are more likely trying to read back the Value property.
      He he he. I am obviously missing a couple of points, but am trying to understand the logic VB. I am self taught for about a month now, so am trying to get to grips with the lingo. I am still in the dark, are you saying that what i have done is write the value to the text. Ok get that, but then how do i save the "tick" for the checkbox in the application?

      Thanks

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by Wernerh
        He he he. I am obviously missing a couple of points, but am trying to understand the logic VB. I am self taught for about a month now, so am trying to get to grips with the lingo. I am still in the dark, are you saying that what i have done is write the value to the text. Ok get that, but then how do i save the "tick" for the checkbox in the application?
        The "tick" of a checkbox is found in its Value property.

        Your code was (more or less by accident) writing this out correctly to the file. But you were trying to read it back into the Text property - which doesn't exist. You need to read it back into the Value property, where it came from.

        For a "one-monther" I'd say you're doing very well. The real secret is learning to think like a computer. That is, dumb and extremely literal. People always try to work out what a program does as though the computer is sensible, rather than following through precisely what the code says. Just remember computers are stupid, and you'll be fine. :)

        Comment

        • Wernerh
          New Member
          • Jul 2007
          • 104

          #5
          Originally posted by Killer42
          The "tick" of a checkbox is found in its Value property.

          Your code was (more or less by accident) writing this out correctly to the file. But you were trying to read it back into the Text property - which doesn't exist. You need to read it back into the Value property, where it came from.

          For a "one-monther" I'd say you're doing very well. The real secret is learning to think like a computer. That is, dumb and extremely literal. People always try to work out what a program does as though the computer is sensible, rather than following through precisely what the code says. Just remember computers are stupid, and you'll be fine. :)
          Thanks Killer42, I am starting t get the hang of it, but like anything it takes time, practise and a bucket load of patience to get things working. Thanks for the input and thank you for the support.

          Comment

          Working...