From: Keith (Southend)G on 30 Dec 2009 18:34 > > Dim observation As String = "" > > Which initializes the variable to a value at the same time as it's declared. > > Second: > > Your original file is being erased because you're opening a StreamWriter on > it in the Button2 event handler, here: > > Dim objWriter As New System.IO.StreamWriter(FILE_NAME) > > Because FILE_NAME was set to the the same file name that you were originally > reading a few lines above that. The StreamWriter is emptying out the file in > preparation for sending data to it. Since there's no code (in this sample, > anyway) that's sending any data down the StreamWriter, the file ends up > empty. Ah ah, I've got it to create the new file 'sorted.txt' without overwriting the 'ogimet.txt' file by declaring it as FILE_NAME2 as follows: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim observation As String = "" Dim FILE_NAME As String = "C:\ogimet.txt" Dim FILE_NAME2 As String = "C:\sorted.txt" If System.IO.File.Exists(FILE_NAME) = True Then Dim objWriter As New System.IO.StreamWriter(FILE_NAME2) It may seem a little, but I do feel I have made some progress in understanding this. I won't give up :-) Keith (Southend)
From: Captain Jack on 4 Jan 2010 10:35 "Keith (Southend)G" <keith_harris9(a)hotmail.com> wrote in message news:566f2267-13bc-4627-93ef-a42f58767144(a)upsg2000gro.googlegroups.com... > Yes, your description just about sums up what I'm trying to do. > Ok Jack, I'll try to explain what I'm trying to achieve, but I imagine > it will be more involved, I maybe asking to much of you. Even so, as > there is so much that I'm sure I could do I am keen to pick VB up and > develop things further, just need to get a head start, see some > examples etc. Basically, the idea is to save a lot of time I spend > doing things manually. It's a hobby I've had since I was 17, I'm now > knocking on 50 :-) > > There are thousands of locations that provide synop code (weather), > but for this example I will use 2 locations, the first is the nearest > to where I live and the other is just randomly chosen from Spain. > > What I want to do is have a separate file for each time. > 1. The date/time '200912301350' etc can be ignored. > 2. The date/time of importance is the AAXX 30144 etc. (AAXX means land > station, 30 is date (30th) 14 is time (14:00), the last '4' can be > ignored, this can sometimes be a 0, 1, 3 or 4, it tells you whether > windspeed is reported in mph, mps or knots. So AAXX 30094 is 30th > 09:00 hours etc. > 3. The numbers 03693 or 08360 is the wmo (World Meteorological > Organisations) station number, this number I would want at the start > of each line. > 4. The '=' signifies the end of each line of code. > 5. The resulting file(s) / file names I want to then look like, see > bottom of this post... I was born in 1961, so I feel your pain. :-D If I were doing it, I'd probably create a class which would accept an input line from the file and expose the separate elements as properties. Then, I'd add them to a SortedList with the date field as the key, then read through the list to send the data to my output file. That may be more coding that you want to do, though, I don't know. I can't quite tell the best way to parse your data, because I can't tell where there are line feeds in the file and where line feeds were added during the process of the source data being posted to the newsgroup. If you can get a string of data that consists of one line from the date/time value to the "=" sign, a quick way to parse it would be to use the Split function with a space character as the delimiter. The Split function will convert your string into an array of smaller strings, broken up at the spaces. Something like this: ' Assuming InputString is "200912301350 AAXX [...] 333 88/04=" Dim ItemList() As String = Split(InputString, " ") If ItemList.Length > 2 AndAlso ItemList(1) = "AAXX" Then Dim Year As Integer = CInt(ItemList(0).SubString(0,4)) Dim Month As Integer = CInt(ItemList(0).SubString(4,2)) Dim Day As Integer = CInt(ItemList(2).SubString(0,2)) Dim Hours As Integer = CInt(ItemList(2).SubString(2,2)) Dim LineDate As Date = DateSerial(Year, Month, Day).AddHours(Hours) Dim NewLine As String = ItemList(2) For Counter As Integer = 3 To ItemList.Length - 1 NewLine &= " " & ItemList(Counter) Next End If If you then stick the line's date into a SortedList as the key and your calculated text line as the data, then when you read back from the SortedList, your data will be sorted by the date and you can write it into the appropriate file already sorted. You may not want to take the year and day from the computer's date/time; if you ever process the data one a different day than you download the data, you may get incorrect output. There may be better ways to do that, too, but that would work with the assumptions that I've made about the input data. Unless you really need to see all of this in a text box on the screen, I'd probably write this as a console application. If the file won't parse that way, or if it's arranged more oddly than it looks like in your post, you can either attach a copy of the file to a message or post how to download one, and I can look directly at the file and maybe write some more specific code. -- Jack
From: Keith (Southend)G on 4 Jan 2010 12:54 On Jan 4, 3:35 pm, "Captain Jack" <CaptainJack1...(a)comcast.net> wrote: > "Keith (Southend)G" <keith_harr...(a)hotmail.com> wrote in message > > news:566f2267-13bc-4627-93ef-a42f58767144(a)upsg2000gro.googlegroups.com... > > > > > Yes, your description just about sums up what I'm trying to do. > > Ok Jack, I'll try to explain what I'm trying to achieve, but I imagine > > it will be more involved, I maybe asking to much of you. Even so, as > > there is so much that I'm sure I could do I am keen to pick VB up and > > develop things further, just need to get a head start, see some > > examples etc. Basically, the idea is to save a lot of time I spend > > doing things manually. It's a hobby I've had since I was 17, I'm now > > knocking on 50 :-) > > > There are thousands of locations that provide synop code (weather), > > but for this example I will use 2 locations, the first is the nearest > > to where I live and the other is just randomly chosen from Spain. > > > What I want to do is have a separate file for each time. > > 1. The date/time '200912301350' etc can be ignored. > > 2. The date/time of importance is the AAXX 30144 etc. (AAXX means land > > station, 30 is date (30th) 14 is time (14:00), the last '4' can be > > ignored, this can sometimes be a 0, 1, 3 or 4, it tells you whether > > windspeed is reported in mph, mps or knots. So AAXX 30094 is 30th > > 09:00 hours etc. > > 3. The numbers 03693 or 08360 is the wmo (World Meteorological > > Organisations) station number, this number I would want at the start > > of each line. > > 4. The '=' signifies the end of each line of code. > > 5. The resulting file(s) / file names I want to then look like, see > > bottom of this post... > > I was born in 1961, so I feel your pain. :-D > > If I were doing it, I'd probably create a class which would accept an input > line from the file and expose the separate elements as properties. Then, I'd > add them to a SortedList with the date field as the key, then read through > the list to send the data to my output file. That may be more coding that > you want to do, though, I don't know. > > I can't quite tell the best way to parse your data, because I can't tell > where there are line feeds in the file and where line feeds were added > during the process of the source data being posted to the newsgroup. If you > can get a string of data that consists of one line from the date/time value > to the "=" sign, a quick way to parse it would be to use the Split function > with a space character as the delimiter. The Split function will convert > your string into an array of smaller strings, broken up at the spaces. > Something like this: > > ' Assuming InputString is "200912301350 AAXX [...] 333 88/04=" > Dim ItemList() As String = Split(InputString, " ") > If ItemList.Length > 2 AndAlso ItemList(1) = "AAXX" Then > Dim Year As Integer = CInt(ItemList(0).SubString(0,4)) > Dim Month As Integer = CInt(ItemList(0).SubString(4,2)) > Dim Day As Integer = CInt(ItemList(2).SubString(0,2)) > Dim Hours As Integer = CInt(ItemList(2).SubString(2,2)) > Dim LineDate As Date = DateSerial(Year, Month, Day).AddHours(Hours) > Dim NewLine As String = ItemList(2) > For Counter As Integer = 3 To ItemList.Length - 1 > NewLine &= " " & ItemList(Counter) > Next > End If > > If you then stick the line's date into a SortedList as the key and your > calculated text line as the data, then when you read back from the > SortedList, your data will be sorted by the date and you can write it into > the appropriate file already sorted. You may not want to take the year and > day from the computer's date/time; if you ever process the data one a > different day than you download the data, you may get incorrect output. > > There may be better ways to do that, too, but that would work with the > assumptions that I've made about the input data. > > Unless you really need to see all of this in a text box on the screen, I'd > probably write this as a console application. > > If the file won't parse that way, or if it's arranged more oddly than it > looks like in your post, you can either attach a copy of the file to a > message or post how to download one, and I can look directly at the file and > maybe write some more specific code. > > -- > Jack Jack, You are a mere youngster :-) Thank you for taking the time to look at this, I can digest it all over the next few days and try to apply it what I've already created. I find with many things I just need to get over a hurdle, understand a bit, then slowly move on, bit by bit. It's getting over the first hurdle ;-) Incidentally, this is where I get the data from... http://www1.ogimet.com/synopsc.phtml.en Many thanks and a very Happy New Year to you. Keith (Southend) ps: some interesting weather over the next few days....
From: Captain Jack on 4 Jan 2010 13:35 "Keith (Southend)G" <keith_harris9(a)hotmail.com> wrote in message news:b06ce155-f668-406a-a9a7-7e6d6c0ef7ea(a)v25g2000yqk.googlegroups.com... > Jack, > > You are a mere youngster :-) Thanks, I'll try to keep that in mind. :-) > Thank you for taking the time to look at this, I can digest it all > over the next few days and try to apply it what I've already created. > I find with many things I just need to get over a hurdle, understand a > bit, then slowly move on, bit by bit. It's getting over the first > hurdle ;-) Sounds good. I looked at the web site and a sample of the data. As long as they stick to that format, I think that it would be pretty straightforward to read the data a line at a time, looking for lines that start with a four digit number, then continuing to read until you get a line that ends with an equals sign. Join the resulting lines togiether into one string separated by spaces, and you can parse it as I suggested. If you want me have another go at it, or want to talk over some more code, I'd be happy to see it. > Many thanks and a very Happy New Year to you. And to yourself. -- Jack
From: Keith (Southend)G on 4 Jan 2010 15:59
Hi Jack, Just added the code as it stands into my existing code and I get two identical errors come up.... <snip> Error 1 Argument not specified for parameter 'CharCount' of 'Public Function InputString(FileNumber As Integer, CharCount As Integer) As String'. C:\Documents and Settings\Keith\My Documents\Visual Studio 2008\Projects\Open Text\Open Text\Form1.vb 46 54 Open Text Error 1.... <snip> Line 46 Column 54 points to '(InputString)', I assume I need to add something else somewhere, or declare something ? Thanks I'd inserted that code in between the following: Dim sr As New System.IO.StreamReader(fs) Dim input As String = sr.ReadLine() While (input <> Nothing) *inserted here* input = sr.ReadLine() End While End Using objWriter.Close() Many thanks Keith (Southend) |