storing data in csv - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Projects (http://qbasicnews.com/newforum/forum-12.html) +--- Thread: storing data in csv (/thread-743.html) Pages:
1
2
|
storing data in csv - smaug - 05-01-2003 THIS IS THE ORIGANL: 10 CLS:KEY OFF 60 BA = 1016:REM BA = COM ADDRESS 70 TM = TIMER: IF TM > 86370! THEN 70:REM MIDNIGHT TRAP 80 F1 = 0: F2 = 0 90 OUT (BA + 4), 1 + M 100 TM = TIMER: WHILE TIMER < TM + 2: WEND 110 LOCATE 5,6: PRINT "READ TEMPERATURES " 120 OUT BA + 3, 0: TM1 = TIMER: TM2 = TIMER 130 OUT BA + 3, 64 140 IF F1 = 0 AND (INP(BA + 6) AND 128) = 0 THEN F1 = 1: P1 = TIMER - TM1 150 IF F2 = 0 AND (INP(BA + 6) AND 32) = 0 THEN F2 = 1: P2 = TIMER - TM2 160 IF F1 <> 1 OR F2<> 1 THEN 140 170 P1 = P1 * 100: P2 = P2 * 100 180 LOCATE 8,5: PRINT USING "PERIOD (1) = ###.## SECONDS; P1 / 100 190 T1 = 522 - 88.6299 * LOG(P1) + 3.0209 * LOG(P1) ^ 2 200 LOCATE 10, 7RINT USING "TEMP (1) = ###.#"; T1 210 LOCATE 13,5: PRINT USING "PERIOD (2) = ###.## SECONDS; P2 / 100 220 T2 = 522 - 88.6299 * LOG(P2) + 3.0209 * LOG(P2) ^ 2 230 LOCATE 15, 7RINT USING "TEMP (2) = ###.#"; T2 240 LOCATE 5, 6: PRINT "END READ TEMP" What I am looking for is a mod for the code that would track the temp by time and date in time intravls that could be change say five minutes for now. i would like to save the values to a csv file with the values being date time temp1 and temp2. I am good with hardware but my coding is weak any suggestions would be great thanks. Smaug You mean an Excel CSV file, i.e.,... - Glenn - 05-01-2003 a simple text file with commas in between items on each line? I assume you want to write the same stuff to the file that you're now writing to the screen. First, get rid of your LOCATE statements. Then, before you go to output anything to the file, open the file: OPEN "MYFILE.CSV" FOR OUTPUT AS #1 Then, get rid of the LOCATE statements and change your "PRINT ... " statements (or PRINT USING statements) to WRITE#1, ... where "..." simply refers to the list of stuff you want written to a single line in your file. When you're all done, do CLOSE #1 thanks one more? - smaug - 05-01-2003 That sounds perfect. I am leaving the print lines in for now for debugging. 10 CLS:KEY OFF 60 BA = 1016:REM BA = COM ADDRESS 70 TM = TIMER: IF TM > 86370! THEN 70:REM MIDNIGHT TRAP 80 F1 = 0: F2 = 0 90 OUT (BA + 4), 1 + M 100 TM = TIMER: WHILE TIMER < TM + 2: WEND 110 PRINT "READ TEMPERATURES " 120 OUT BA + 3, 0: TM1 = TIMER: TM2 = TIMER 130 OUT BA + 3, 64 140 IF F1 = 0 AND (INP(BA + 6) AND 128) = 0 THEN F1 = 1: P1 = TIMER - TM1 150 IF F2 = 0 AND (INP(BA + 6) AND 32) = 0 THEN F2 = 1: P2 = TIMER - TM2 160 IF F1 <> 1 OR F2<> 1 THEN 140 170 P1 = P1 * 100: P2 = P2 * 100 180 PRINT USING "PERIOD (1) = ###.## SECONDS; P1 / 100 190 T1 = 522 - 88.6299 * LOG(P1) + 3.0209 * LOG(P1) ^ 2 200 PRINT USING "TEMP (1) = ###.#"; T1 210 PRINT USING "PERIOD (2) = ###.## SECONDS; P2 / 100 220 T2 = 522 - 88.6299 * LOG(P2) + 3.0209 * LOG(P2) ^ 2 230 PRINT USING "TEMP (2) = ###.#"; T2 240 OPEN "TEST.CSV" FOR OUTPUT #1 250 WRITE #1, DATE$, TIME$, T1, T2 260 CLOSE #1 How does that look? How should i go about a time comparision so that i am only getting the data in time frames that i want? I would like a varible that could be changed. I want to say thanks I am sure this stuff seems like simple questions to you but I am stumped. Smaug a grumpy local is here to fill you in. - Agamemnus - 05-01-2003 1) If you must have lines, make them 1, 2, 3.. etc. not 10 20 30. 2) Use ' instead of REM. 3) Use lowercase variables. That way they stand out from the functions. EDIT Code: CLS: KEY OFF Don't use line numbers much, do you? - Glenn - 05-01-2003 If you did, you'd know the really obvious reason why contiguous line numbers are a REAL bad idea. (Think about the concept of *insertion*.) As for the rest, that's *his* business too. Quote:1) If you must have lines, make them 1, 2, 3.. etc. not 10 20 30. As for Smaug's time/test question,... - Glenn - 05-01-2003 you could use TIMER, e.g., TESTTIME = TIMER IF LOWTIME <= TESTTIME AND TESTTIME <= HIGHTIME THEN do whatever Or you can use the MID$ and VAL functions to pull the hours, minutes, and seconds out of TIME$ (and the month, day, and year out of DATE$) and test against those. timer? - smaug - 05-02-2003 i am not sure how to go about adding the timer. Quote:Here's one way to get the timer to look more "clock-like": could i use something like this and subtract 5 from the minutes and then do a if x = 0 or x = 5 then write the data to the file. I would cut the code that i dont need of course. An the reason the code has line numbers is that is the way it was written. I just copied it the way it was. I do think that if you use them then you should leave space for modifaction and adding code for an easier reading. Thanks agian Smaug Re: Don't use line numbers much, do you? - na_th_an - 05-02-2003 Quote:If you did, you'd know the really obvious reason why contiguous line numbers are a REAL bad idea. (Think about the concept of *insertion*.) As for the rest, that's *his* business too. Yeah. When you code in GWBASIC or BASICA, where there is no a real editor, you can't simply edit your text and insert a new line. If you use 1, 2, 3, 4... How do you add a line between 1 and 2? And... Why did you suggest use 1,2,3 and not 10,20,30??? I'm still wondering... What's the mysterious reason? storing data in csv - Agamemnus - 05-02-2003 Code: 1.1 PRINT "Hi." Quote:I just copied it the way it was. Yes, that's the way that you do it so that you don't get bugs. Hm... now the time problem. Do you mean you want to measure it more than once, based on some variable time period? EDIT: I think I figured it out. Instead of doing "tm = TIMER + 2" make it "tm = TIMER + dt". Code: CLS: KEY OFF Oh yeah, that makes a lot of sense. - Glenn - 05-02-2003 (Learn to count by 10s. You'll be amazed at what the mental exercise does for your programming abilities.) |