|
-
Oct 10th, 2002, 12:28 PM
#1
Thread Starter
Member
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...
-
Oct 10th, 2002, 12:37 PM
#2
Frenzied Member
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:
Dim strLine as String
Dim lineValues() as String
'Input a line from the file
Line Input #fileNum, strLine
'Put all values into an array
lineValues = Split(strLine, ",")
strClient = lineValues(0)
strProject = lineValues(1)
myDate = CDate(lineValues(2))
myHour = CInt(lineValues(3))
myMin = CInt(lineValues(4))
-
Oct 10th, 2002, 12:42 PM
#3
Thread Starter
Member
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...
-
Oct 10th, 2002, 12:51 PM
#4
Thread Starter
Member
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...
-
Oct 10th, 2002, 12:53 PM
#5
Frenzied Member
Can you change the way the data is saved to the text file in the first place? Or is that not an option?
-
Oct 10th, 2002, 12:56 PM
#6
Thread Starter
Member
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...
-
Oct 10th, 2002, 12:57 PM
#7
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
-
Oct 10th, 2002, 01:01 PM
#8
Thread Starter
Member
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...
-
Oct 10th, 2002, 01:09 PM
#9
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....
-
Oct 10th, 2002, 01:19 PM
#10
Thread Starter
Member
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...
-
Oct 10th, 2002, 02:09 PM
#11
Thread Starter
Member
*bump* i think everyone is at lunch...
-[]v[]adwacker
Thanks in advance...
-
Oct 10th, 2002, 02:28 PM
#12
-= B u g S l a y e r =-
VB Code:
myDate = CDate(Replace(s, """", ""))
-
Oct 10th, 2002, 02:29 PM
#13
Frenzied Member
When outputting to file, try 'writing' like this for the date
This is just a guess i dont have vb where im at right now
-
Oct 10th, 2002, 02:41 PM
#14
Thread Starter
Member
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...
-
Oct 10th, 2002, 02:51 PM
#15
Frenzied Member
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:
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
-
Oct 10th, 2002, 02:53 PM
#16
Thread Starter
Member
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...
-
Oct 10th, 2002, 03:28 PM
#17
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:
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....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|