QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: IronMan on March 15, 2020, 02:09:01 am
-
Could someone please help me. I am needing a current text file that has my 7 day weather forecast to be put in a little more user friendly, more readable format. Needs the "." removed at the beginning of each day and a blank line between the days.
>>> Here is what the text file looks like now: <<<
.REST OF TONIGHT...A slight chance of showers late in the
evening, then a chance of showers in the late evening and early
morning. Showers likely and a slight chance of thunderstorms
before sunrise. Cloudy. Lows in the mid 50s. Southeast winds
around 5 mph becoming north after midnight. Chance of rain
60 percent.
.SUNDAY...Showers likely and a slight chance of thunderstorms in
the morning, then a slight chance of showers and thunderstorms in
the afternoon. Cloudy. Highs in the lower 60s. North winds 5 to
10 mph. Chance of rain 60 percent.
.SUNDAY NIGHT...Mostly cloudy. Lows around 50. Northeast winds
5 to 10 mph.
.MONDAY...A slight chance of showers in the morning, then a
chance of showers in the afternoon. Cloudy. Highs around 70. East
winds around 5 mph. Chance of rain 30 percent.
.MONDAY NIGHT...Cloudy with a 40 percent chance of showers. Lows
in the upper 50s. East winds around 5 mph.
.TUESDAY...A chance of showers in the morning, then showers
likely and a slight chance of thunderstorms in the afternoon.
Mostly cloudy. Highs in the mid 70s. Chance of rain 60 percent.
.TUESDAY NIGHT...A chance of showers and a slight chance of
thunderstorms in the evening, then a chance of showers after
midnight. Mostly cloudy. Lows in the upper 50s. Chance of rain
40 percent.
.WEDNESDAY...A chance of showers and a slight chance of
thunderstorms in the morning, then showers likely and a slight
chance of thunderstorms in the afternoon. Mostly cloudy. Highs in
the upper 70s. Chance of rain 60 percent.
.WEDNESDAY NIGHT...Showers likely and a slight chance of
thunderstorms. Lows in the mid 60s. Chance of rain 70 percent.
.THURSDAY...Showers likely and a chance of thunderstorms. Highs
around 80. Chance of rain 70 percent.
.THURSDAY NIGHT...A chance of showers and thunderstorms in the
evening, then showers and thunderstorms likely after midnight.
Mostly cloudy. Lows in the upper 60s. Chance of rain 70 percent.
.FRIDAY...Showers and a chance of thunderstorms in the morning,
then showers likely and a chance of thunderstorms in the
afternoon. Highs in the upper 70s. Chance of rain 80 percent.
.FRIDAY NIGHT...Cooler. Showers likely and a slight chance of
thunderstorms in the evening, then a chance of showers after
midnight. Mostly cloudy. Lows in the lower 50s. Chance of rain
70 percent.
.SATURDAY...Cooler. Mostly sunny with a 20 percent chance of
showers. Highs in the mid 60s.
>>> I would like for it to look more like this:<<<
REST OF TONIGHT...A slight chance of showers late in the
evening, then a chance of showers in the late evening and early
morning. Showers likely and a slight chance of thunderstorms
before sunrise. Cloudy. Lows in the mid 50s. Southeast winds
around 5 mph becoming north after midnight. Chance of rain
60 percent.
SUNDAY...Showers likely and a slight chance of thunderstorms in
the morning, then a slight chance of showers and thunderstorms in
the afternoon. Cloudy. Highs in the lower 60s. North winds 5 to
10 mph. Chance of rain 60 percent.
.SUNDAY NIGHT...Mostly cloudy. Lows around 50. Northeast winds
5 to 10 mph.
MONDAY...A slight chance of showers in the morning, then a
chance of showers in the afternoon. Cloudy. Highs around 70. East
winds around 5 mph. Chance of rain 30 percent.
MONDAY NIGHT...Cloudy with a 40 percent chance of showers. Lows
in the upper 50s. East winds around 5 mph.
TUESDAY...A chance of showers in the morning, then showers
likely and a slight chance of thunderstorms in the afternoon.
Mostly cloudy. Highs in the mid 70s. Chance of rain 60 percent.
TUESDAY NIGHT...A chance of showers and a slight chance of
thunderstorms in the evening, then a chance of showers after
midnight. Mostly cloudy. Lows in the upper 50s. Chance of rain
40 percent.
WEDNESDAY...A chance of showers and a slight chance of
thunderstorms in the morning, then showers likely and a slight
chance of thunderstorms in the afternoon. Mostly cloudy. Highs in
the upper 70s. Chance of rain 60 percent.
WEDNESDAY NIGHT...Showers likely and a slight chance of
thunderstorms. Lows in the mid 60s. Chance of rain 70 percent.
.THURSDAY...Showers likely and a chance of thunderstorms. Highs
around 80. Chance of rain 70 percent.
THURSDAY NIGHT...A chance of showers and thunderstorms in the
evening, then showers and thunderstorms likely after midnight.
Mostly cloudy. Lows in the upper 60s. Chance of rain 70 percent.
FRIDAY...Showers and a chance of thunderstorms in the morning,
then showers likely and a chance of thunderstorms in the
afternoon. Highs in the upper 70s. Chance of rain 80 percent.
FRIDAY NIGHT...Cooler. Showers likely and a slight chance of
thunderstorms in the evening, then a chance of showers after
midnight. Mostly cloudy. Lows in the lower 50s. Chance of rain
70 percent.
SATURDAY...Cooler. Mostly sunny with a 20 percent chance of
showers. Highs in the mid 60s.
Any help is appreciated.
Thanks.
Kent
-
Do you have any code to share showing what you have attempted to do so far?
Welcome to the forum as well :-)
-
IF LEFT$(text$, 1) = "." THEN
PRINT CHR$(13); CHR$(13)
. PRINT MID$(text$, 2); " ";
ELSE
. PRINT text$;
END IF
It looks like you'd want to do something similar to the above after you read in each line (text$).
-
It would appear that Steve (McNeill) has carried over beginning lines with a dot into code (lines 3 & 5)! As Terry says, it would be good to see Kent's efforts so far.
-
It would appear that Steve (McNeill) has carried over beginning lines with a dot into code (lines 3 & 5)! As Terry says, it would be good to see Kent's efforts so far.
Stupid auto-format wants to put a period before 2 spaces... I thought I'd disabled that. /sigh at "helpful technology" and programming. :P
-
I'm using QB64 which to run a SHELL command that executes CURL from the command prompt which retrieves a text file from the NOAA Weather site.
' Getting NOAA 7 day weather text forecast
SHELL "curl https://tgftp.nws.noaa.gov/data/forecasts/zone/ms/msz024.txt >forecast.txt"
It saves it to my hard drive and is called forecast.txt. Just need a small QB64 application to remove the "." from the beginning of each day and put a space (carriage return) between each day so that it would make it less jumbled and more user friendly readable file.
I'm attaching the forecast.txt file for reference if anyone wants to take a look.
Any help is appreciated.
Thank you.
Kent
-
Well @IronMan, do you know how to open a file and read it's contents with QB64?
This kinda sounds like homework.
-
Yea, I know how to open and read the forecast.txt file.
DIM LineTxt AS STRING
CLS
OPEN "forecast.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, LineTxt
PRINT LineTxt
WEND
CLOSE #1
I just need to be able to remove the "." that are at the start of each day, and to put a blank line in between the days and wrote these changes back to the forecast.txt file.
I will continue to do my homework, but please share any ideas.
Thanks
Kent
-
Yea, I know how to open and read the forecast.txt file.
DIM LineTxt AS STRING
CLS
OPEN "forecast.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, LineTxt
PRINT LineTxt
WEND
CLOSE #1
I just need to be able to remove the "." that are at the start of each day, and to put a blank line in between the days and wrote these changes back to the forecast.txt file.
I will continue to do my homework, but please share any ideas.
Thanks
Kent
Reply Number 2. Replace text$ with LineTxt. Remove the 2 idiotic auto- periods my iPad inserted. Put in place of your PRINT line. Compile and done.
-
Hi @IronMan,
I strongly suggest you use:
LINE INPUT will include commas in a line, without LINE, commas will start a new line.
-
Reply Number 2. Replace text$ with LineTxt. Remove the 2 idiotic auto- periods my iPad inserted. Put in place of your PRINT line. Compile and done.
Thank you SMcNeill. Works perfect!
-
Here is what I have so for and it works perfect when printing to screen with the PRINT LineTxt; but I'm needing it to create another text file "test.txt" or whatever that will have the changes made. I tried to do a Close #1 and the Open "test.txt" FOR OUTPUT AS #1 and WRITE #1 LineTxt but that did not seem to work. Will not allow me to open for output until I close the first open statement, and no matter where I seem to put it in my program I get an error.
This is what I have so far:
DIM LineTxt AS STRING
CLS
OPEN "forecast.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, LineTxt
IF LEFT$(LineTxt, 1) = "." THEN
PRINT CHR$(13); CHR$(13)
PRINT MID$(LineTxt, 2); " ";
ELSE
PRINT LineTxt; ' would like this output to go to test.txt instead of screen print
END IF
WEND
Please excuse me for being such a newbie and asking so many questions. I really have studied and tried to figure this out on my own.
All help is appreciated.
Thank you.
Kent
-
Open for output with a different #... wait you closed #1 for input so should be OK to write #1
You probably want to keep the input file open and write to output file (a different #) at same time (and different file name too),
read a line, write a line... repeat until EOF then close both.
-
This is the code I have so far.
DIM LineTxt AS STRING
CLS
OPEN "forecast.txt" FOR INPUT AS #1
OPEN "test.txt" FOR OUTPUT AS #2
WHILE NOT EOF(1)
INPUT #1, LineTxt
IF LEFT$(LineTxt, 1) = "." THEN
PRINT CHR$(13); CHR$(13)
PRINT MID$(LineTxt, 2); " ";
ELSE
WRITE #2, LineTxt 'write output to new file test.txt
PRINT LineTxt; 'prints output to screen
END IF
WEND
CLOSE #1
CLOSE #2
The output to the screen is correct, but when it writes it to the test.txt file, the format is wrong and things are missing from it.
EXAMPLE of test.txt
"afternoon"
"then a slight chance of sprinkles late in the"
"afternoon. Cloudy. Highs in the mid 50s. North winds 5 to 10 mph."
"Chance of rain 20 percent."
"around 5 mph."
"showers. Highs in the upper 60s. Northeast winds around 5 mph."
"in the upper 50s. Light and variable winds."
"then a"
"chance of showers in the afternoon. Mostly cloudy. Highs in the"
"mid 70s. North winds around 5 mph. Chance of rain 40 percent."
"showers. Lows in the upper 50s."
"then a chance of"
Any ideas?
Thank you.
Kent
-
I've always used PRINT #2, text$
WRITE #2 is something different
And everything you PRINT to screen do the exact same PRINT #2 to the file
IF LEFT$(LineTxt, 1) = "." THEN
PRINT CHR$(13); CHR$(13) ' <<<<<<<< this makes empty line PRINT #2, " "
PRINT MID$(LineTxt, 2); " "; '<<< and this PRINT #2, MID$(lineTxt, 2); " ";
ELSE
WRITE #2, LineTxt 'write output to new file test.txt '<<<<<<< PRINT #2, LineTxT
PRINT LineTxt; 'prints output to screen
I just tested with forecaste.txt and looks good with PRINT #2 instead of WRITE #2
-
You're missing parts of it because you're still printing half to the screen and half to the file.
IF LEFT$(LineTxt, 1) = "." THEN
PRINT CHR$(13); CHR$(13) 'HERE YOU ARE PRINTING TO THE SCREEN.
PRINT MID$(LineTxt, 2); " "; 'HERE TOO, THIS IS TO THE SCREEN
ELSE
WRITE #2, LineTxt 'write output to new file test.txt AND YET HERE IS TO THE FILE
PRINT LineTxt; 'prints output to screen
END IF
You'll need to convert all your print statements to the file, and not just part of them. ;)
-
deja vu
-
I've always used PRINT #2, text$
WRITE #2 is something different
And everything you PRINT to screen do the exact same PRINT #2 to the file
IF LEFT$(LineTxt, 1) = "." THEN
PRINT CHR$(13); CHR$(13) ' <<<<<<<< this makes empty line PRINT #2, " "
PRINT MID$(LineTxt, 2); " "; '<<< and this PRINT #2, MID$(lineTxt, 2); " ";
ELSE
PERFECT!
Thank you so much. It was the WRITE command I was using instead of PRINT. I thought if you were send to a file you used WRITE.
Thanks again.
Kent
WRITE #2, LineTxt 'write output to new file test.txt '<<<<<<< PRINT #2, LineTxT
PRINT LineTxt; 'prints output to screen
I just tested with forecaste.txt and looks good with PRINT #2 instead of WRITE #2
-
PERFECT!
That done it. I know now not to sue the WRITE and use the PRINT.
Thanks again, bplus
Kent
-
Glad to help Kent, welcome to forum!