From: Captain Jack on
"Keith (Southend)G" <keith_harris9(a)hotmail.com> wrote in message
news:7210c10d-eed8-4df0-8844-2a39bf6d8d2b(a)34g2000yqp.googlegroups.com...
> 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)

Well, the error message is complaining that you called the function
InputString with only one argument instead of the two (FileNumber and
CharCount) that it's set up to receive. However, I'm not sure why you're
using InputString for anything... that command is designed to read data from
a file handle, not a stream. It just exists to simulate an old way of
reading data; it's not used with a StreamReader.

I see a problem in your code example above... you should use "IsNot" rather
than "<>" when comparing to Nothing. "Nothing" can't be equated with any
object, so you have to use "Is" and "IsNot" to relate to it.

Other than that, your string variable "input" has the current line of text
from the input file, so you don't need to do anything else that will read
the data from the file. At the point where you've got "*inserted here*" in
your example, you can begin processing the data to see what you want to keep
out of it.

--
Jack


From: Keith (Southend)G on
On Jan 4, 9:17 pm, "Captain Jack" <CaptainJack1...(a)comcast.net> wrote:
> "Keith (Southend)G" <keith_harr...(a)hotmail.com> wrote in message
>
> news:7210c10d-eed8-4df0-8844-2a39bf6d8d2b(a)34g2000yqp.googlegroups.com...
>
>
>
> > 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)
>
> Well, the error message is complaining that you called the function
> InputString with only one argument instead of the two (FileNumber and
> CharCount) that it's set up to receive.  However, I'm not sure why you're
> using InputString for anything... that command is designed to read data from
> a file handle, not a stream. It just exists to simulate an old way of
> reading data; it's not used with a StreamReader.
>
> I see a problem in your code example above... you should use "IsNot" rather
> than "<>" when comparing to Nothing. "Nothing" can't be equated with any
> object, so you have to use "Is" and "IsNot" to relate to it.
>
> Other than that, your string variable "input" has the current line of text
> from the input file, so you don't need to do anything else that will read
> the data from the file. At the point where you've got "*inserted here*" in
> your example, you can begin processing the data to see what you want to keep
> out of it.
>
> --
> Jack

Hi Jack,

Not had a chance all week to look at this, hence tackling it again
now.

If I remove this...
Dim ItemList() As String = Split(InputString, " ")
I get a whole string of errors..

Name 'ItemList' Not Declared

Also if I add <IsNot> to <>Nothing
I get this error message...
Argument not specified for parameter 'CharCount' of 'Public Function
InputString(FileNumber As Integer, CharCount As Integer) As String'.

I must be getting muddled a bit here. I've tried adding and removing
various bits and seem to get more errors.

Sorry to have post it all, but it currently all looks like this...


<snip>

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim FILE_NAME As String = "C:\ogimet.txt"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objReader As New System.IO.StreamReader(FILE_NAME)

RichTextBox1.Text = objReader.ReadToEnd

objReader.Close()
Else
MsgBox("File Does Not Exist")
End If
End Sub


Private Sub TabPage1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs)

End Sub

Private Sub RichTextBox1_TextChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
RichTextBox1.TextChanged

End Sub

Private Sub RichTextBox2_TextChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
RichTextBox2.TextChanged

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Dim FILE_NAME As String = "C:\ogimet.txt"
Dim observation As String = "C:\sorted.txt"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(observation)


Using fs As New System.IO.FileStream _
("C:\ogimet.txt", System.IO.FileMode.Open)


Dim sr As New System.IO.StreamReader(fs)
Dim input As String = sr.ReadLine()
While (input <IsNot> Nothing)


' 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


input = sr.ReadLine()
End While
End Using
objWriter.Close()
MsgBox("Text written to file")
Else
MsgBox("File Does Not Exist")
End If
End Sub
End Class

<snip>

Thanks

Keith (Southend)
From: Captain Jack on
"Keith (Southend)G" <keith_harris9(a)hotmail.com> wrote in message
news:3ab98899-efab-4d8e-8763-1b4129b3edc8(a)j5g2000yqm.googlegroups.com...
On Jan 4, 9:17 pm, "Captain Jack" <CaptainJack1...(a)comcast.net> wrote:
> "Keith (Southend)G" <keith_harr...(a)hotmail.com> wrote in message
>
> news:7210c10d-eed8-4df0-8844-2a39bf6d8d2b(a)34g2000yqp.googlegroups.com...
>
>
>
> > Hi Jack,
>
> > Just added the code as it stands into my existing code and I get two
> > identical errors come up....

Ah, I see where the confusion may lie. In the example code I posted earlier,
I had the assumption that the variable "InputString" would be defined
elsewhere in your code, and was just showing what could be done with it
after that point. Since there is no variable in your code defined as
InputString, VB is looking elsewhere to see if it's defined. It's finding a
function named InputString, and telling you that it's not called correctly.

You'r input variable is called "input", so you'll want to replace the name
"InputString" in my example code with your variable name, "input". On the
"IsNot", the remnants of the not-equal operator (<>) around it would be
causing an error.

These three lines are what need to be changed:

------------------------------------------------------------
-- Change from this:
------------------------------------------------------------
While (input <IsNot> Nothing)
' Assuming InputString is "200912301350 AAXX [...] 333 88/04="
Dim ItemList() As String = Split(InputString, " ")

------------------------------------------------------------
-- To this:
------------------------------------------------------------
While input IsNot Nothing
' Assuming input is "200912301350 AAXX [...] 333 88/04="
Dim ItemList() As String = Split(input, " ")

The loop should correctly build a line of text to send to your output file,
in the variable NewLine. You'll still need to add some code to send that
variable to your output file, after the loop with Counter and before the
next End If.

--
Jack


From: Keith (Southend)G on
On Jan 8, 3:33 pm, "Captain Jack" <CaptainJack1...(a)comcast.net> wrote:
> "Keith (Southend)G" <keith_harr...(a)hotmail.com> wrote in message

> The loop should correctly build a line of text to send to your output file,
> in the variable NewLine. You'll still need to add some code to send that
> variable to your output file, after the loop with Counter and before the
> next End If.
>
> --
> Jack

Thanks Jack, no errors :-)

As you say my output file is empty "sorted.txt", in fact I'm not sure
'observation' really refers to anything?
Dim observation As String = "C:\sorted.txt"
Do I need something like:

The following code demonstrates how to create a text file:
Dim oFile as System.IO.File
Dim oWrite as System.IO.StreamWriter
oWrite = oFile.CreateText(“C:\sample.txt”)

And I
where would it go?

It would be nice to get something working, I must spend over an hour
doing this manually each day.

Thanks

Keith (Southend)
From: Captain Jack on
"Keith (Southend)G" <keith_harris9(a)hotmail.com> wrote in message
news:4e389351-2d6d-497b-b724-32b3dd91de33(a)k17g2000yqh.googlegroups.com...
> Thanks Jack, no errors :-)
>
> As you say my output file is empty "sorted.txt", in fact I'm not sure
> 'observation' really refers to anything?
> Dim observation As String = "C:\sorted.txt"
> Do I need something like:
>
> The following code demonstrates how to create a text file:
> Dim oFile as System.IO.File
> Dim oWrite as System.IO.StreamWriter
> oWrite = oFile.CreateText(�C:\sample.txt�)
>
> And I
> where would it go?

The variable "observation" is fine, it's just a string with the name of the
file. The command you have for creating the StreamWriter is also good,
you're just not sending it any data.

Actually, on second thought, you might want to change the initialization of
the StreamWriter a little bit, to this:

Dim objWriter As New System.IO.StreamWriter(observation, False,
System.Text.Encoding.ASCII)

This is a different way of creating the StreamWriter. In addition to opening
the file named in the variable "observation", you're also telling it that
you want to overwrite the file everytime, and that you want to use ASCII
text. If you want to append to the file everytime instead, you would change
the False to True. I'm pretty sure that by default the StreanWriter is going
to want to use UTF8 instead of ASCII, and you'll get some odd characters in
your file you weren't expecting.

To actually send data to the file, using your example again, you need to
call the WriteLine method of the StreamWriter object. It would go after the
loop that builds the variable NewLine, like this:

Dim NewLine As String = ItemList(2)
For Counter As Integer = 3 To ItemList.Length - 1
NewLine &= " " & ItemList(Counter)
Next
objWriter.WriteLine(NewLine)
End If

That ought to give you some kind of output. Once you're getting something
into the file, you'll want to check it and see if it's formatted the way you
want it to be, and you should be in good shape.

--
Jack