+ Post New Thread
Results 1 to 7 of 7
Scripts Thread, altering text files with vb script in Coding and Web Development; say i have a text file like below (but with multiple lines) is there anyway i can read in a ...
  1. #1


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,222
    Thank Post
    218
    Thanked 813 Times in 695 Posts
    Rep Power
    274

    altering text files with vb script

    say i have a text file like below (but with multiple lines) is there anyway i can read in a line replace most of it but keep the end say. So say i have a script that fills in certain bits but i want to be able to manually add stuff to it it wont wipe it out

    example

    pc01,hp compaq 610,4gb,120gb,80gb,serialno,12-12-2010,3,12-12-2013

    so whats in red is readded by script at intervals the black text is manually added by me at some point

  2. #2
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,943
    Thank Post
    115
    Thanked 272 Times in 250 Posts
    Rep Power
    104
    If it's just just the dates you want to keep hold of you could use a regular expression or if it's the last two entries just look for the position of the comma and chop it there.
    Last edited by ChrisH; 24th January 2014 at 12:52 PM.

  3. #3


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,222
    Thank Post
    218
    Thanked 813 Times in 695 Posts
    Rep Power
    274
    Quote Originally Posted by ChrisH View Post
    If it's just just the dates you want to keep hold of you could use a regular expression or if it's the last two entries just look for the position of the comma and chop it there.
    ok i think i get the idea if no the execution lol

    so basically get it to count ,s and copy anything after , 6 to a new variable and then just write it back?

  4. #4
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,943
    Thank Post
    115
    Thanked 272 Times in 250 Posts
    Rep Power
    104
    Yes that would be one way of doing it using the right or left function once you get the position of the relevant comma. It would all depend on if the number of entries per line were the same eg there will only be two dates etc. Using a regular expression to pick out the dates would probably be the proper way to do it though.

  5. #5


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,222
    Thank Post
    218
    Thanked 813 Times in 695 Posts
    Rep Power
    274
    Quote Originally Posted by ChrisH View Post
    Yes that would be one way of doing it using the right or left function once you get the position of the relevant comma. It would all depend on if the number of entries per line were the same eg there will only be two dates etc. Using a regular expression to pick out the dates would probably be the proper way to do it though.
    ok but thats a new one one me looks like some more googlefu is needed. The entries per line should always be identical as the way the content is generated even if it returns a null value it will insert the , as a field separator

  6. #6
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,943
    Thank Post
    115
    Thanked 272 Times in 250 Posts
    Rep Power
    104
    If it is the same number of entries in the same order then you could simply use the split function which will use the comma as a qualifier and put the line into an array so

    Code:
    pc01,hp compaq 610,4gb,120gb,80gb,serialno,12-12-2010,3,12-12-2013
    fed to the split function would end up like

    Code:
    myArray = Split(strLineFromFile,",")
    
    Which would populate the array like below :
    
    myArray(0) = "pc01"
    myArray(1) = "hp compaq 610"
    myArray(2) = "4gb"
    myArray(3) = "120gb"
    myArray(4) = "80gb"
    myArray(5) = "serialno"
    myArray(6) = "12-12-2010"
    myArray(7) = "12-12-2013"

  7. Thanks to ChrisH from:

    sted (24th January 2014)

  8. #7


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,222
    Thank Post
    218
    Thanked 813 Times in 695 Posts
    Rep Power
    274
    cheers i looked into regular expressions and gave up lo

SHARE:
+ Post New Thread

Similar Threads

  1. help with vbs script
    By sted in forum Scripts
    Replies: 14
    Last Post: 24th February 2012, 11:23 PM
  2. Replies: 4
    Last Post: 12th February 2012, 11:26 PM
  3. Disable OWA with VB Script
    By davidphillips0120 in forum Scripts
    Replies: 3
    Last Post: 25th March 2010, 06:36 PM
  4. List computers in Domain in a text file with vbs
    By FatBoy in forum How do you do....it?
    Replies: 5
    Last Post: 15th February 2010, 12:29 PM
  5. Replies: 3
    Last Post: 18th January 2008, 01:46 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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