Announcement

Collapse
No announcement yet.

text file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • text file

    i am trying to create a log file this is a .txt file ...what i need is to add text each time on a different line..... write now i can get text to the file using TextFile.WriteFromString but each time it is added to the end of the line and i need it to be on a seperate line each time ap ver5

  • #2
    Hi bufobill and welcome to the forum,
    an easy way to append a text file is to read to table and append the next log file line
    Here I've done an example for you
    Text_Files_And_Tables.apz
    Have a play and Cheers

    Comment


    • #3
      thank you so much for your input, im kind of a beginner at this ............but what if i didnt want the user to have any control over entering text in the log.txt file .... i would have the date and time that he started in this log and the time he ended by clicking stop button and then the next time he logged in it would be on the line under the last one ..... and so on and so on .

      Comment


      • #4
        in version 4 i was able to accomplish this by using this command

        Comment


        • #5
          Can you post a sample of how you are recording the user logging on.
          If I get time later I'll show an example of log file for you , but it would be better if I see how you doing it

          Comment


          • #6
            OK you didn't get back
            Try this quick example, modify to suit
            LogOn to TextFile.apz

            Comment


            • #7
              wow thats even better than i thought.... i think i can make this work ....... thank you so much you are awesome !!!!!!!

              Comment


              • #8
                ok ... so what if i wanted the text file to be located in a folder like c:\kelly\login.txt instead of the desktop.... i know you was using the desktop as an example but i cant figure out how to change the path

                Comment


                • #9
                  Hi Again,
                  OK the variable myDT is the path to desktop

                  Code:
                  myDT = Shell.GetFolder(SHF_DESKTOP);
                  so change myDT to

                  Code:
                  c:\\kelly
                  OR
                  you don't have to use myDT but could use Path = C:\\kelly then
                  change line TextFile.WriteFromTable(myDT.."\\login.txt", tblResult, false);

                  to TextFile.WriteFromTable(Path.."\\login.txt", tblResult, false);

                  Cheers


                  Comment


                  • #10
                    do you mean like this? if so i get an error on line 1

                    Path = C:\\kelly


                    if (File.DoesExist(Path.."\\login.txt")) then
                    tblResult = TextFile.ReadToTable(Path.."\\login.txt");
                    tcount = Table.Count(tblResult);
                    snLine = tcount + 1
                    else

                    tblResult = {}
                    snLine = 1
                    end
                    sEndTime = System.GetTime(TIME_FMT_MIL);--Get time logout
                    --Concat string for user / login /logout
                    sOut = sUserName.." - Logged in : "..sInstallDateTime.." Logged Out : "..sEndTime

                    --insert string at end of table

                    Table.Insert(tblResult,snLine , sOut);


                    TextFile.WriteFromTable(Path.."\\login.txt", tblResult, false);

                    Dialog.TimedMessage("Please Wait...", "Now Logging "..sUserName.." OFF", 2000, MB_ICONINFORMATION);


                    Application.Exit(0);

                    Comment


                    • #11
                      My mistake going BLIND Path = "C:\\kelly" has to have quotation marks for a string , don't know how I left them out
                      Also if you are going to write to C drive you may have to run as admin

                      Comment


                      • #12
                        Yes! Yes! Yes! You did it again ........ thank you again you have been so much help

                        Comment


                        • #13
                          Just in case you don't have a kelly folder on C drive then use

                          Code:
                          Path = "C:\\kelly"
                          myfolder = Folder.DoesExist("C:\\kelly");
                          if not myfolder then
                          Folder.Create("C:\\kelly");
                          end
                          Cheers

                          Comment


                          • #14
                            ok thanks good to know

                            Comment

                            Working...
                            X
                            😀
                            🥰
                            🤢
                            😎
                            😡
                            👍
                            👎