Read Line from TXT-file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Pazan
    Forum Member
    • Feb 2009
    • 21

    Read Line from TXT-file

    Hi,
    I have some files on HDD. Each file consist of 10 lines.
    I read the data of file via the function
    Code:
    result = Dialog.FileBrowse(true, "Open File", _SourceDrive, "Text File (*.txt)|*.txt|All Files(*.*)|*.*|", "", "", false, false);
    if (result[1] ~= "CANCEL") then
    resultthetxt = TextFile.ReadToString(result[1]);
    end
    Questions are:
    1. how to read data from the line "9" of opened file into var raw_9?
    2. select 14 symbols from right in this variable into var raw_9_result

    Thanks
  • mwreyf1
    Indigo Rose Customer
    • Aug 2004
    • 417

    #2
    Can you post what you have now and maybe then we could help.

    Unless someone wants to just do it for you which will not help you in learning how to do this on your own.

    What your asking for is really very basic which would make it a great way for you to learn AMS.

    Comment

    • Teqskater
      Forum Member
      • Apr 2007
      • 175

      #3
      @Pazan
      something like this i guess you want:

      Code:
      raw_9 = resultthetxt[9]
      raw_9_result = String.Right(raw_9, 14);
      @mwreyf1
      which will not help you in learning how to do this on your own.
      I don't agree with you anymore. one year ago i would, but i discovered that the best way to learn is have a look at examples and stuff. and just create what you want to create. And then learn step by step and not just reading the manual and what each function does. Just look at his code. He obviously tries.How you know how to copy 14 characters from the right of one string into another if you don't know wich function could achieve that. What's basic for us wasn't basic the first times we used ams. I just takes some time to get used to the functions that you need and stuff. But there also people that don't try something and ask to write a complete script for them. Those people don't deserve help in my opinion because they don't try. Don't be offended by me please. It's not my intention.

      best regards,

      Teqskater
      Last edited by Teqskater; 02-16-2009, 09:05 AM.

      Comment

      • mwreyf1
        Indigo Rose Customer
        • Aug 2004
        • 417

        #4
        @Teqskater

        On something as SIMPLE (for even a beginner) as what he is asking, there is no reason for him to not at least attempt to get at least part of it on his own.

        If you look at the code he posted that you reffered to as "him trying", none of that code is in no way an attempt at what he was asking for.

        His question:
        Questions are:
        1. how to read data from the line "9" of opened file into var raw_9?
        2. select 14 symbols from right in this variable into var raw_9_result
        I don't see where he made any attempt at either of those questions.

        I agree that it helps to have a helping hand, but when those times come along that are easy code by most standards, then those are the one's that a beginner should try at all cost to figure out on their own. If they can't figure out the most basic then they will never get it.

        Comment

        • Teqskater
          Forum Member
          • Apr 2007
          • 175

          #5
          On something as SIMPLE (for even a beginner) as what he is asking, there is no reason for him to not at least attempt to get at least part of it on his own.
          Your right about that.

          none of that code is in no way an attempt at what he was asking for.
          Ok. That's right. But he was looking into the right direction. I did not say that it would work.

          I don't see where he made any attempt at either of those questions.
          Also i did not say he attempted solving that.

          But ok i get your point right now and i only can say you are right.

          Well at least we need to let him figure out the last part of his puzzle. right?
          When he solves it he's good enough to solve almost everything else.

          Nice to have this discussion with you mwreyf1 :yes

          Comment

          • Pazan
            Forum Member
            • Feb 2009
            • 21

            #6
            Well...
            Button OnClick:
            Code:
            result = Dialog.FileBrowse(true, "Open File", "AutoPlay\\Docs", "Text File (*.txt)|*.txt|All Files(*.*)|*.*|", "", "", false, false);
            if (result[1] ~= "CANCEL") then
            raw_9 = resultthetxt[9]
            raw_9_result = String.Right(raw_9, 14);
            Paragraph.SetText("Paragraph1", raw_9_result);
            end
            What's wrong here?
            OnClick, Line 3: attempt to index global 'resultthetxt' (a nil value)

            Comment

            • Imagine Programming
              Indigo Rose Customer
              • Apr 2007
              • 4252

              #7
              Originally posted by Pazan View Post
              Well...
              Button OnClick:
              What's wrong here?
              OnClick, Line 3: attempt to index global 'resultthetxt' (a nil value)
              Code:
              result = Dialog.FileBrowse(true, "Open File", "AutoPlay\\Docs", "Text File (*.txt)|*.txt|All Files(*.*)|*.*|", "", "", false, false);
              if (result[1] ~= "CANCEL") then
              [COLOR="Red"]resultthetxt = TextFile.ReadToTable(result[1]);[/COLOR][COLOR="Green"] --<< You forgot this... <<[/COLOR]
              raw_9 = resultthetxt[9]
              raw_9_result = String.Right(raw_9, 14);
              Paragraph.SetText("Paragraph1", raw_9_result);
              end
              Bas Groothedde
              Imagine Programming :: Blog

              AMS8 Plugins
              IMXLH Compiler

              Comment

              • Pazan
                Forum Member
                • Feb 2009
                • 21

                #8
                Originally posted by C B programming and webdesign View Post
                ...
                --<< You forgot this <<[/COLOR]
                resultthetxt = TextFile.ReadToTable(result[1]);
                ...
                [/CODE]
                OnClick, Line 5: Argument 1 must be of type string
                Ok, begin again...
                Content of file, from which I try to load line 9:
                data.txt
                Date: 2009-02-11
                Time: 14:48:51
                OS: Windows XP
                User: Admin
                Screen resolution: 1024х768 pix
                Total RAM: 238 MB
                Host name: IOCTO
                IP: 192.168.100.55
                MAC:0007e91674fc
                End Of file here-----
                Button Code OnClick:
                Code:
                result = Dialog.FileBrowse(true, "Open File", "AutoPlay\\Docs", "Text File (*.txt)|*.txt|All Files(*.*)|*.*|", "", "", false, false);
                if (result[1] ~= "CANCEL") then
                resultthetxt = TextFile.ReadToTable(result[1]);
                raw_9 = resultthetxt[9]
                raw_9_result = String.Right(raw_9, 14);
                Paragraph.SetText("Paragraph1", raw_9_result);
                end
                in result I want to get in Paragraph1:
                0007e91674fc
                and nothing anymore
                Last edited by Pazan; 02-17-2009, 04:47 AM.

                Comment

                • mwreyf1
                  Indigo Rose Customer
                  • Aug 2004
                  • 417

                  #9
                  You are getting C:0007e91674fc as a result of asking for code that would get 14 symbols from the right of line 9 of your text file.

                  If that is no longer what you want take a look at the String.Right in the code and change the 14 to whatever you want it to now return.

                  Comment

                  • Imagine Programming
                    Indigo Rose Customer
                    • Apr 2007
                    • 4252

                    #10
                    Why would you want to get that information from a textfile anyway? this is all information you could retrieve yourself.

                    For reviewing it later, you could save it as an ini/xml file.
                    Bas Groothedde
                    Imagine Programming :: Blog

                    AMS8 Plugins
                    IMXLH Compiler

                    Comment

                    • Pazan
                      Forum Member
                      • Feb 2009
                      • 21

                      #11
                      Originally posted by mwreyf1 View Post
                      If that is no longer what you want take a look at the String.Right in the code and change the 14 to whatever you want it to now return.
                      I know how to select symbols from right in the line. I DON'T KNOW HOW TO GET VALUE FROM LINE 9 INTO VARIABLE THAT'S ALL. When I try to do this I get errors. See above.

                      Comment

                      • Pazan
                        Forum Member
                        • Feb 2009
                        • 21

                        #12
                        Originally posted by C B programming and webdesign View Post
                        Why would you want to get that information from a textfile anyway?
                        Because I get information from users in TXT-file.

                        Comment

                        • Bruce
                          Indigo Rose Customer
                          • Jun 2001
                          • 2134

                          #13
                          Originally posted by C B programming and webdesign View Post
                          Why would you want to get that information from a textfile anyway? this is all information you could retrieve yourself.

                          For reviewing it later, you could save it as an ini/xml file.
                          Ahhhh because he wants to?

                          Comment

                          • Imagine Programming
                            Indigo Rose Customer
                            • Apr 2007
                            • 4252

                            #14
                            Originally posted by Bruce View Post
                            Ahhhh because he wants to?
                            I have noticed, yes
                            Last edited by Imagine Programming; 02-18-2009, 03:41 AM. Reason: typo
                            Bas Groothedde
                            Imagine Programming :: Blog

                            AMS8 Plugins
                            IMXLH Compiler

                            Comment

                            • Pazan
                              Forum Member
                              • Feb 2009
                              • 21

                              #15
                              Is this question very difficult for guru

                              Comment

                              Working...
                              X