read and write variables from textfile

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Per Juul Larsen

    read and write variables from textfile

    Hi.
    My Textfile looks like this

    Variable 1
    Variable 2
    Variable 3
    Variable 4

    On opening the application it will read the textfile, and assign each
    line of variable to at textfield in VB and then close the file.
    How can I do this


  • Reverend Fuzzy

    #2
    Re: read and write variables from textfile

    There's a trick to it... just in case you're a student
    trying to get us to do his homework for him, I'll not
    give you actual code... but I'll tell you the secret....

    Read it in the same way you wrote it, same variable
    types and all. open, read1,read2,rea d3,read4,close.

    Now assuming you're not a cheating student, you
    should now have all the information you need.

    If you're NOT a cheating student, e-mail me a
    copy of your ID, to prove it, and I'll send you some
    actual code. :)

    --
    Reverend Fuzzy
    Panama City, FL
    reverend.fuzzy@ msbdatasystems. com
    God, Jesus, Baptism, Funeral, Officiant, Wedding, Marriage, Minister, Me, Christian, Church, Churches, Near, Hattiesburg, Columbia, Petal, Wiggins, Purvis, Lumberton, Poplarville, Picayune, jobs, free



    "Per Juul Larsen" <juul@larsen.dk wrote in message
    news:8244c$48a7 fff0$57486c0a$3 591@news.comxne t.dk...
    Hi.
    My Textfile looks like this
    >
    Variable 1
    Variable 2
    Variable 3
    Variable 4
    >
    On opening the application it will read the textfile, and assign each
    line of variable to at textfield in VB and then close the file.
    How can I do this
    >
    >

    Comment

    • Per Juul Larsen

      #3
      Re: read and write variables from textfile

      Reverend Fuzzy skrev:
      There's a trick to it... just in case you're a student
      trying to get us to do his homework for him, I'll not
      give you actual code... but I'll tell you the secret....
      >
      Read it in the same way you wrote it, same variable
      types and all. open, read1,read2,rea d3,read4,close.
      >
      Now assuming you're not a cheating student, you
      should now have all the information you need.
      >
      If you're NOT a cheating student, e-mail me a
      copy of your ID, to prove it, and I'll send you some
      actual code. :)
      >
      Thank You for a kind answer. No I am not a student. I am retired long
      ago.(65) Just try to keep up what I have lost long ago. I used to open
      file for input to a textbox or array etc... but wondering if there is an
      easier way to do it.
      thanks
      regards pjl

      Comment

      • Reverend Fuzzy

        #4
        Re: read and write variables from textfile

        You may want to consider using a data structure.
        There's a tiny bit more setup, but it will allow you
        to read/write all your variables in one shot, as
        opposed to multiple reads/writes.

        As an example, I had written an appliance parts
        database a long time ago, in regular BASIC, in
        which I DIMmed my variables, as such....

        DIM A As String * 32
        DIM B As String * 32
        (originally longer list)

        then did a PRINT# x, A : print# x, A to write
        and/or a LINEINPUT #x, A : LINEINPUT #x, B
        to read it back.

        When I found my original source code, and started
        converting it to VB6, I changed to a structure, so I
        started with setting up a record variable...

        Public Type Record
        PartNumber As String * 32
        PartDescription As String * 32
        End Type

        and ...
        Dim r As Record

        Then, I was able to open the database file at the start
        of the program via an Open App.Path + "\db.pdb" For Random As #dBase Len =
        Len(r)
        which would allow me to SEEK directly to a specified
        record number, and do a PUT #x, ,r or GET #x, r to
        read or write the data, which was then accessed
        as r.PartNumber or r.PartDescripti on

        Am I going too fast for you? If you'd like a copy of the final code
        to disassemble, and learn from, send me an e-mail, and I'll
        reply with a .zip of it in an attachment.

        --
        Reverend Fuzzy
        Panama City, FL
        reverend.fuzzy@ msbdatasystems. com
        God, Jesus, Baptism, Funeral, Officiant, Wedding, Marriage, Minister, Me, Christian, Church, Churches, Near, Hattiesburg, Columbia, Petal, Wiggins, Purvis, Lumberton, Poplarville, Picayune, jobs, free



        "Per Juul Larsen" <juul@larsen.dk wrote in message
        news:e2e7e$48a8 4654$57486c0a$3 1366@news.comxn et.dk...
        Reverend Fuzzy skrev:
        >There's a trick to it... just in case you're a student
        >trying to get us to do his homework for him, I'll not
        >give you actual code... but I'll tell you the secret....
        >>
        >Read it in the same way you wrote it, same variable
        >types and all. open, read1,read2,rea d3,read4,close.
        >>
        >Now assuming you're not a cheating student, you
        >should now have all the information you need.
        >>
        >If you're NOT a cheating student, e-mail me a
        >copy of your ID, to prove it, and I'll send you some
        >actual code. :)
        >>
        Thank You for a kind answer. No I am not a student. I am retired long
        ago.(65) Just try to keep up what I have lost long ago. I used to open
        file for input to a textbox or array etc... but wondering if there is an
        easier way to do it.
        thanks
        regards pjl

        Comment

        • Raoul Watson

          #5
          Re: read and write variables from textfile

          Per Juul Larsen wrote:
          Hi.
          My Textfile looks like this
          >
          Variable 1
          Variable 2
          Variable 3
          Variable 4
          >
          On opening the application it will read the textfile, and assign each
          line of variable to at textfield in VB and then close the file.
          How can I do this
          >
          I may be missing something but would this work?


          Open "yourfile.t xt" for input as #3

          input #1, text1.text
          input #2, text2.text
          input #3, text3.text
          input #3, text4.text

          close #3

          Comment

          • Per Juul Larsen

            #6
            Re: read and write variables from textfile

            Raoul Watson skrev:
            Per Juul Larsen wrote:
            >Hi.
            >My Textfile looks like this
            >>
            >Variable 1
            >Variable 2
            >Variable 3
            >Variable 4
            >>
            >On opening the application it will read the textfile, and assign each
            >line of variable to at textfield in VB and then close the file.
            >How can I do this
            >>
            >
            I may be missing something but would this work?
            >
            >
            Open "yourfile.t xt" for input as #3
            >
            input #1, text1.text
            input #2, text2.text
            input #3, text3.text
            input #3, text4.text
            >
            close #3
            >
            Thank You

            I saw the light...

            I read line by line until it comes to end of the file like this
            Dim a, b, c, d
            Open "C:\users\publi c\temp\ok.txt" For Input As #1

            While Not EOF(1)
            Line Input #1, a
            Text1.Text = a
            Line Input #1, b
            Text2.Text = b
            Line Input #1, c
            Text3.Text = c
            Line Input #1, d
            Text4.Text = d

            Wend
            Close #1

            regards pjl

            Comment

            • Per Juul Larsen

              #7
              Re: read and write variables from textfile

              Reverend Fuzzy skrev:
              You may want to consider using a data structure.
              There's a tiny bit more setup, but it will allow you
              to read/write all your variables in one shot, as
              opposed to multiple reads/writes.
              >
              As an example, I had written an appliance parts
              database a long time ago, in regular BASIC, in
              which I DIMmed my variables, as such....
              >
              DIM A As String * 32
              DIM B As String * 32
              (originally longer list)
              >
              then did a PRINT# x, A : print# x, A to write
              and/or a LINEINPUT #x, A : LINEINPUT #x, B
              to read it back.
              >
              When I found my original source code, and started
              converting it to VB6, I changed to a structure, so I
              started with setting up a record variable...
              >
              Public Type Record
              PartNumber As String * 32
              PartDescription As String * 32
              End Type
              >
              and ...
              Dim r As Record
              >
              Then, I was able to open the database file at the start
              of the program via an Open App.Path + "\db.pdb" For Random As #dBase Len =
              Len(r)
              which would allow me to SEEK directly to a specified
              record number, and do a PUT #x, ,r or GET #x, r to
              read or write the data, which was then accessed
              as r.PartNumber or r.PartDescripti on
              >
              Am I going too fast for you? If you'd like a copy of the final code
              to disassemble, and learn from, send me an e-mail, and I'll
              reply with a .zip of it in an attachment.
              >
              hi

              Sometimes the answer is right in front of you and you can not see it!!!!.
              Thank you for your reply ... I have solved the task by reading the text
              file and then line by line store the line to variables and then insert
              them in the application.
              my email is juul@larsen.dk

              kind regards pjl

              Comment

              Working...