Results 1 to 17 of 17

Thread: Extracting Vars from a Text File [RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Northern CA
    Posts
    38

    Extracting Vars from a Text File [RESOLVED]

    Hi-
    Right now I'm writing the following to a text file:
    Client Name, Project Name,Today's Date, Hours and Mins

    with the method Open blah for Append as fileNum

    Print #1, Client, Project, cDate, cHour, cMin

    When I want to extract those variables back out of the text file so that I can format them and print them out in a nice fashion, I don't know how to grab and seperate them back into variables.
    Last edited by Madwacker; Oct 10th, 2002 at 02:57 PM.
    -[]v[]adwacker
    Thanks in advance...

  2. #2
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    Well, if the data in the file is seperated by commas you can do the following. (Avoid using CDate as a variable name as its a command in vb!)

    VB Code:
    1. Dim strLine as String
    2. Dim lineValues() as String
    3.  
    4. 'Input a line from the file
    5. Line Input #fileNum, strLine
    6.  
    7. 'Put all values into an array
    8. lineValues = Split(strLine, ",")
    9.  
    10. strClient = lineValues(0)
    11. strProject = lineValues(1)
    12. myDate = CDate(lineValues(2))
    13. myHour = CInt(lineValues(3))
    14. myMin = CInt(lineValues(4))

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Northern CA
    Posts
    38
    Cool, I shall try that out and let ya know how it goes.

    And yea, I knew about "cDate" ....I just changed my VarNames for posting and randomly stuck a letter in there, happend to be a 'c'
    -[]v[]adwacker
    Thanks in advance...

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Northern CA
    Posts
    38
    Whoops, looked past that. No the data isn't seperated by commas, just by huge tab spaces. Not sure how to make it seperated by commas (I knew once, but it's been a while).
    -[]v[]adwacker
    Thanks in advance...

  5. #5
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    Can you change the way the data is saved to the text file in the first place? Or is that not an option?

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Northern CA
    Posts
    38
    I can do whatever needs to be done to make it right. I'm the only programmer and it's my project
    -[]v[]adwacker
    Thanks in advance...

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by Madwacker
    Whoops, looked past that. No the data isn't seperated by commas, just by huge tab spaces. Not sure how to make it seperated by commas (I knew once, but it's been a while).
    Don't use the Print # statement... .try using the Write # instead.....

    see This page on MSDN for more details
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Northern CA
    Posts
    38
    Ok using Write# this is my new output

    client Name, Project, Today's Date, Hours Mins

    "test","test2",#2002-10-10#,0,0

    whats up with the # sign?
    -[]v[]adwacker
    Thanks in advance...

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by Madwacker
    Ok using Write# this is my new output

    client Name, Project, Today's Date, Hours Mins

    "test","test2",#2002-10-10#,0,0

    whats up with the # sign?
    Signifies a date ..... the variable must have been dimmed as Date ..... try using the FORMAT$ function or converting to a string somehow..... or leave it... just make sure to use a DATE variable to read it back in....
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Northern CA
    Posts
    38
    Ok so far so good. I changed where I set my var to format Date as Date$

    When I get down to ae_jester's code of:

    myDate = CDate(lineValues(2))

    my program breaks with a Run-time Error '13'; type mismatch. I highlighted that line and it shows:

    lineValues(2) = ""10-10-2002""

    This line has double quotes, which is what I think is crashing it. I commented out this line and the program is smooth.
    Last edited by Madwacker; Oct 10th, 2002 at 01:46 PM.
    -[]v[]adwacker
    Thanks in advance...

  11. #11

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Northern CA
    Posts
    38
    *bump* i think everyone is at lunch...
    -[]v[]adwacker
    Thanks in advance...

  12. #12
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. myDate = CDate(Replace(s, """", ""))
    -= a peet post =-

  13. #13
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    When outputting to file, try 'writing' like this for the date

    VB Code:
    1. Write #1, CStr(myDate)

    This is just a guess i dont have vb where im at right now

  14. #14

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Northern CA
    Posts
    38
    ae_jester: Thanks, that worked great.

    1 problem left. The variables that are strings, when I put them back into variables, and print them out they print such as:

    CLIENT NAME PROJECT
    "microsoft" "website setup"


    do I need to convert it to a non-string..or?
    -[]v[]adwacker
    Thanks in advance...

  15. #15
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    That's what happens when you use Write instead of print

    You could still use print if you wanted like this, which would get rid of all of the """"""""""""""""""""""'s everywhere

    VB Code:
    1. Print #fileNum, strClient & "," & strProject & "," & myDate & "," & myHour & "," & myMin

    this adds commas which act as hte delimiter and t hen you don't get " surrounding the data when you input it

  16. #16

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Northern CA
    Posts
    38
    You know I was gonna try that yesterday, but wasn't sure it would work correctly. I'll give THAT a whirl and see how it goes.


    Thankyou Thankyou guys
    -[]v[]adwacker
    Thanks in advance...

  17. #17
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by ae_jester
    That's what happens when you use Write instead of print

    You could still use print if you wanted like this, which would get rid of all of the """"""""""""""""""""""'s everywhere

    VB Code:
    1. Print #fileNum, strClient & "," & strProject & "," & myDate & "," & myHour & "," & myMin

    this adds commas which act as hte delimiter and t hen you don't get " surrounding the data when you input it
    Which will work fine until there's a comma in the middle of one of the fields.... then things get all mucked up....
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

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



Click Here to Expand Forum to Full Width