Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts

    Read from A Flat Text Database

    I have a n application that reads and writes text files to a network drive on an intranet. I currently pull all of my info from multiple text files. (each record is it's own file). I'm not allowed to use any server side scripting access DB, SQL basically anything you would normally use for a DB is not allowed. The real question I had here is in regards to flat-text databases. I see I can probably do the same thing I am doing with one file rather than (getting on a 1000 now) multiple files. I've found lots of tutorials on using flat-text with PHP and ASP but none for Active-X and Javascript, probably because it is a bit unorthodox, but does any one know how I can pull my records in this manner?

    I just don't know how to get it to display the line in question. How do I tell it to grab the line where the ID is 3. Once I get that down I can pretty much take it from there.

    Here is the code I have for my DB:

    ID|name|rockwell|shift_date|shift_time|req_date|req_time|log_date|log_time|req_status|log_status
    1|Bob Makie|11665|11-9-03|6:00am-7:00am|open|open|open|open|n|n
    2|Shift Open|open|11-10-03|10:00am-11:00am|open|open|open|open|n|n
    3|Shift Open|open|11-10-03|12:00pm-1:00pm|open|open|open|open|n|n
    4|Shift Open|open|11-11-03|2:00pm-3:00pm|open|open|open|open|n|n

    Any help is much appreciated.

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    i'm not sure it's even doable. generally, the rule is no file i/o with javascript. with the addition of ActiveX, it might be possible, but i've never seen it done.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To get that flat text file into Javascript you'd have to load it into the page somehow. Using a hidden iframe you could load it and then using javascript read through each line of text, parse each line into it's individual fields and then store them into an array or arrays. The basic problems with this idea is that as the file grows larger the responsiveness of your web page will go down since more data has to be transferred to the client which will be really bad for dialup users.
    Another problem stems from the fact that you can't update the text file from the web page either. So any use of that data would be read-only.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As I understood, you are not allowed to use databases (even Access?).

    If I misunderstood you, this works:
    Code:
    var conn = new ActiveXObject("ADODB.Connection");
    var connString = "dsnTest";
    conn.open(connString);
    var rs = conn.Execute("SELECT Name FROM Test WHERE ID=" + 3 + "");
    if (!rs.EOF){
        name = rs("Name").Value;
    } else {
        alert("User not found.");
    }
    conn.Close();
    Otherwise you should be able to use the FileSystemObject. I don't have it installed on my computer, so I can't test it. I have only used it in JScript in ASP.
    Something like this should do it in that case:
    Code:
    function readFile(pFile, filterField, filterValue) {
        var str = "";
        var i = 0;
        var fieldNames = [];
        var records = [];
        var tempFields = [];
        var filterFieldNr = -1;
        while (!pFile.AtEndOfStream){
            str = pFile.ReadLine() + "\n";
            if (i == 0) {
                fieldNames=str.split("|");
                for (var j=0;j<fieldNames.length;j++) {
                    if (fieldNames[j] == filterField) {
                        filterFieldNr = j;
                    }
                }
            }
            tempFields=str.split("|");
            if (records[filterFieldNr] == filterValue) {
                records[records.length]=tempFields;
            }
            i++;
        }
        return records;
    }
    
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var datafile = fso.OpentextFile("db.txt", 1,false,0);
    var rs = readFile( datafile, "ID", 3 );
    Last edited by Danne; 10-09-2003 at 11:20 PM.
    /Daniel

  • #5
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    That is just what I was looking for Danne. Thanks a million!

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No problem. Just remeber that the object(s) needs to be installed on all clientcomputers.
    /Daniel

  • #7
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    They are, currently I am using pretty much the same method just from multiple files. Seems as though this will be a nice work around.

  • #8
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    OK, I have another question in regards to this. Looks like I am going to have this working off the single file. In order to update a record in the file I am basically reading the whole file parsing it into an array updating the array elements based on the user's input and then writing the info back into the text file, overwriting it. What effect will it have if I have multiple users doing things at the same time? Could one person overwrite another persons entry if the timing was right? Again this is all working off a network drive on an intranet using active-x and javascript, entirely client side. Did I make this clear please let me know if it is not.

    Thanks,
    Basscyst

  • #9
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    yes, that set up could easily lead to problems with overwriting, entries. that's why this sort of thing isn't normally done with javascript; it's not really designed for this
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #10
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm, yes if you want to write to the file it becomes complex with multiusers.

    One solution would be to have a global varible indicating if another user has changed the file and in that case prevent the user from saving it. Like a lastChangeTime-variable. Since the program runs on each client, you can't really use a global var, but you can put it in a file. So everytime the user tries to save you need to check that variable.

    If it has been changed since the user read it you need to decide what to do. If you should allow the user to overwrite another users changes, or if the user should lose his/hers changes. Or try to update only the records that were changed.

    To do so:
    In the client you could keep track of which records have been changed using a unique id. That way it's possible to read the file again and avoid losing data by not replacing the users changed records - only the others.

    There's still a problem of overwriting if the same record was changed.

    Maybe you got some ideas anyway...
    /Daniel

  • #11
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Thanks for the reply loos like I'll have to re-think this a bit.

  • #12
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Does your intranet use IE 4.0+? If so, this might be of help.

    Hope that helps!

    Happy coding!

  • #13
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    nolachrymose you are my new best friend. I found a site outlining that a while back and couldn't find it again. That is EXACTLY the information I was looking for.

  • #14
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hehe...glad to help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •