Home All Groups Group Topic Archive Search About
Author
1 Apr 2005 9:13 PM
raulavi
I need to search a string in some  text files.
(any good routines out there?)

then, I created a mysearch.exe with a method that will  search for a String
in a fileName.
I want "string to search" and "fileName" to be  the params in mysearch.exe /
method.
Is there any way to call  mysearch.exe from another exe using
mysearch.exe("searchthisstring","inthisfile.txt") 
if so... how?, any ideas or tips are accepted.
Thanks


The exception that is thrown when one of the arguments provided to a method
is not valid.

Author
1 Apr 2005 9:54 PM
Herfried K. Wagner [MVP]
"raulavi" <raul***@discussions.microsoft.com> schrieb:
>I need to search a string in some  text files.
> (any good routines out there?)

Basic file reading samples (text, binary):

Reading a text file line-by-line or blockwise with a progress indicator
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>

You can use 'InStr' to check if a certain string is contained in each line.

> then, I created a mysearch.exe with a method that will  search for a
> String
> in a fileName.
> I want "string to search" and "fileName" to be  the params in mysearch.exe
> /
> method.

\\\
Public Module Program
    Public Function Main(ByVal Args() As String) As Integer
        For Each Arg As String In Args
            Console.WriteLine(Arg)
        Next Arg
    End Function
End Module
///

Select 'Sub Main' as startup object in the project properties.

> Is there any way to call  mysearch.exe from another exe using
> mysearch.exe("searchthisstring","inthisfile.txt")
> if so... how?, any ideas or tips are accepted.

\\\
Imports System.Diagnostics
..
..
..
Process.Start( _
    "mysearch.exe", _
    """searchthis string"" ""inthisfile.txt""" _
)
///

BTW:  Applications are no methods, so throwing an exception doesn't make
much sense.  However, you can write an information message to the console
and set the exit code ('Return <exit code>') in 'Function Main'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
4 Apr 2005 7:49 PM
raulavi
thanks
>>BTW:  Applications are no methods, so throwing an exception doesn't make
much sense.  However, you can write an information message to the console
and set the exit code ('Return <exit code>') in 'Function Main'. <<
Could you detail a litlle bit more on how to do it...I need to receive a
text...
(what is the statement that will return a string to my caller.)
what really goes into the caller and what goes into the called ...I know
this must be easy routines for many developers, but there are so many ways to
do it, and I need the one taht will always will.

Thanks again



Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "raulavi" <raul***@discussions.microsoft.com> schrieb:
> >I need to search a string in some  text files.
> > (any good routines out there?)
>
> Basic file reading samples (text, binary):
>
> Reading a text file line-by-line or blockwise with a progress indicator
> <URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>
>
> You can use 'InStr' to check if a certain string is contained in each line.
>
> > then, I created a mysearch.exe with a method that will  search for a
> > String
> > in a fileName.
> > I want "string to search" and "fileName" to be  the params in mysearch.exe
> > /
> > method.
>
> \\\
> Public Module Program
>     Public Function Main(ByVal Args() As String) As Integer
>         For Each Arg As String In Args
>             Console.WriteLine(Arg)
>         Next Arg
>     End Function
> End Module
> ///
>
> Select 'Sub Main' as startup object in the project properties.
>
> > Is there any way to call  mysearch.exe from another exe using
> > mysearch.exe("searchthisstring","inthisfile.txt")
> > if so... how?, any ideas or tips are accepted.
>
> \\\
> Imports System.Diagnostics
> ..
> ..
> ..
> Process.Start( _
>     "mysearch.exe", _
>     """searchthis string"" ""inthisfile.txt""" _
> )
> ///
>
> BTW:  Applications are no methods, so throwing an exception doesn't make
> much sense.  However, you can write an information message to the console
> and set the exit code ('Return <exit code>') in 'Function Main'.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>
Author
4 Apr 2005 7:53 PM
raulavi
thanks
>>BTW:  Applications are no methods, so throwing an exception doesn't make
much sense.  However, you can write an information message to the console
and set the exit code ('Return <exit code>') in 'Function Main'. <<

Could you detail a litlle bit more on how to do it...I need to receive a
text...
(what is the statement that will return a string to my caller.)
what really goes into the caller and what goes into the called ...I know
this must be easy routines for many developers, but there are so many ways to
do it
Thanks again



Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "raulavi" <raul***@discussions.microsoft.com> schrieb:
> >I need to search a string in some  text files.
> > (any good routines out there?)
>
> Basic file reading samples (text, binary):
>
> Reading a text file line-by-line or blockwise with a progress indicator
> <URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>
>
> You can use 'InStr' to check if a certain string is contained in each line.
>
> > then, I created a mysearch.exe with a method that will  search for a
> > String
> > in a fileName.
> > I want "string to search" and "fileName" to be  the params in mysearch.exe
> > /
> > method.
>
> \\\
> Public Module Program
>     Public Function Main(ByVal Args() As String) As Integer
>         For Each Arg As String In Args
>             Console.WriteLine(Arg)
>         Next Arg
>     End Function
> End Module
> ///
>
> Select 'Sub Main' as startup object in the project properties.
>
> > Is there any way to call  mysearch.exe from another exe using
> > mysearch.exe("searchthisstring","inthisfile.txt")
> > if so... how?, any ideas or tips are accepted.
>
> \\\
> Imports System.Diagnostics
> ..
> ..
> ..
> Process.Start( _
>     "mysearch.exe", _
>     """searchthis string"" ""inthisfile.txt""" _
> )
> ///
>
> BTW:  Applications are no methods, so throwing an exception doesn't make
> much sense.  However, you can write an information message to the console
> and set the exit code ('Return <exit code>') in 'Function Main'.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>

"Herfried K. Wagner [MVP]" wrote:

> "raulavi" <raul***@discussions.microsoft.com> schrieb:
> >I need to search a string in some  text files.
> > (any good routines out there?)
>
> Basic file reading samples (text, binary):
>
> Reading a text file line-by-line or blockwise with a progress indicator
> <URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>
>
> You can use 'InStr' to check if a certain string is contained in each line.
>
> > then, I created a mysearch.exe with a method that will  search for a
> > String
> > in a fileName.
> > I want "string to search" and "fileName" to be  the params in mysearch.exe
> > /
> > method.
>
> \\\
> Public Module Program
>     Public Function Main(ByVal Args() As String) As Integer
>         For Each Arg As String In Args
>             Console.WriteLine(Arg)
>         Next Arg
>     End Function
> End Module
> ///
>
> Select 'Sub Main' as startup object in the project properties.
>
> > Is there any way to call  mysearch.exe from another exe using
> > mysearch.exe("searchthisstring","inthisfile.txt")
> > if so... how?, any ideas or tips are accepted.
>
> \\\
> Imports System.Diagnostics
> ..
> ..
> ..
> Process.Start( _
>     "mysearch.exe", _
>     """searchthis string"" ""inthisfile.txt""" _
> )
> ///
>
> BTW:  Applications are no methods, so throwing an exception doesn't make
> much sense.  However, you can write an information message to the console
> and set the exit code ('Return <exit code>') in 'Function Main'.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>
Author
2 Apr 2005 12:07 PM
Cor Ligthert
"raulavi"

Reading a text file line-by-line or blockwise with a progress indicator

Reading a text file line-by-line:

\\\
Imports System.IO
..
..
..
Dim Reader As New StreamReader("C:\WINDOWS\WIN.INI")
Do While Reader.Peek > -1
    Debug.WriteLine(Reader.ReadLine())
Loop
Reader.Close()
///
You can use 'IndexOf' to check if a certain string is contained in each
line.

I hope this helps,

Cor
Author
2 Apr 2005 12:13 PM
Cor Ligthert
Roulavi,

I copied the wrong one

\\\
Imports System.IO
Imports System.Text
..
..
..
Dim Reader As New BinaryReader( _
    New FileStream("C:\WINDOWS\WIN.INI", IO.FileMode.Open) _
)
Dim Buffer() As Byte
Me.ProgressBar1.Minimum = 0
Me.ProgressBar1.Maximum = Reader.BaseStream.Length
Dim BytesRead As Long
Const BlockSize As Integer = 1024   ' Read blocks of 1,024 bytes.
Do While BytesRead < Reader.BaseStream.Length
    Buffer = Reader.ReadBytes(BlockSize)
    Debug.Write(System.Text.Encoding.Default.GetString(Buffer))
    BytesRead = BytesRead + Buffer.Length
    Me.ProgressBar1.Value = BytesRead
Loop
Reader.Close()
///

You can use 'IndexOf' to check if a certain string is contained in each
line.

I hope this helps,

Cor