Home All Groups Group Topic Archive Search About

Function call problem

Author
28 Apr 2006 4:23 AM
ataanis
Hey everyone
I'm writing this simple function call from a sub , but for some reason
when I click the file to open, it freezes, can anybody tell me what's
the deal?
Thanks

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            Dim FullPath As String
            Dim BaseName As String
            Dim Location As String
            FullPath = OpenFileDialog1.FileName
            BaseName = Path.GetFileNameWithoutExtension(FullPath)
            Location = Path.GetDirectoryName(FullPath)
            MakeReadable(Location, FullPath, BaseName)
        End If


    End Sub
    Function MakeReadable(ByVal Location As String, ByVal FullPath As
String, ByVal BaseName As String)
        Dim sr As New System.IO.StreamReader(FullPath)
        Dim oFile As System.IO.File
        Dim oWrite As System.IO.StreamWriter
        oWrite = oFile.CreateText(Location + "\" + BaseName + ".txt")
        Dim LineIn As String
        LineIn = sr.ReadLine()
        Dim FrLong As Integer
        Dim FrLat As Integer
        Dim ToLong As Integer
        Dim ToLat As Integer
        Dim feFirP As String
        Dim feName As String
        Dim feType As String
        Dim feDirS As String
        Dim tlId As Long
        Dim version As Short
        Dim side1 As Boolean
        Dim cfcc As String
        While sr.Peek <> -1

            'Converting coordinates
            feType = LineIn.Substring(55, 1)
            FrLong = 180000000 + CInt(LineIn.Substring(191, 9))
            FrLat = 90000000 - CInt(LineIn.Substring(200, 9))
            ToLong = 180000000 + CInt(LineIn.Substring(210, 9))
            ToLat = 90000000 - CInt(LineIn.Substring(219, 9))

            'writing new coordinates to new file
            oWrite.Write(FrLong / 1000000)
            oWrite.Write(" ")
            oWrite.Write(FrLat / 1000000)
            oWrite.Write(" ")
            oWrite.Write(ToLong / 1000000)
            oWrite.Write(" ")
            oWrite.Write(ToLat / 1000000)
            oWrite.Write(" ")
            'If feType = "A" Then
            '    oWrite.Write("hwy")
            'Else : oWrite.Write("no")
            'End If
            oWrite.Write(vbCrLf)
            'oWrite.BaseStream.Seek(0, SeekOrigin.End)

        End While
        oWrite.Close()
        MessageBox.Show("Coordinates written to file")
    End Function

Author
28 Apr 2006 4:41 AM
Cor Ligthert [MVP]
Ataanix,

Why don't you not debug it using the tools.

Set a breakpoint at If OpenFileDialog and see than with clicking at the F11
where it stops.

I hope this helps,

Cor

<ataa***@gmail.com> schreef in bericht
Show quoteHide quote
news:1146198227.107943.41040@g10g2000cwb.googlegroups.com...
> Hey everyone
> I'm writing this simple function call from a sub , but for some reason
> when I click the file to open, it freezes, can anybody tell me what's
> the deal?
> Thanks
>
> Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MenuItem2.Click
>        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
>            Dim FullPath As String
>            Dim BaseName As String
>            Dim Location As String
>            FullPath = OpenFileDialog1.FileName
>            BaseName = Path.GetFileNameWithoutExtension(FullPath)
>            Location = Path.GetDirectoryName(FullPath)
>            MakeReadable(Location, FullPath, BaseName)
>        End If
>
>
>    End Sub
>    Function MakeReadable(ByVal Location As String, ByVal FullPath As
> String, ByVal BaseName As String)
>        Dim sr As New System.IO.StreamReader(FullPath)
>        Dim oFile As System.IO.File
>        Dim oWrite As System.IO.StreamWriter
>        oWrite = oFile.CreateText(Location + "\" + BaseName + ".txt")
>        Dim LineIn As String
>        LineIn = sr.ReadLine()
>        Dim FrLong As Integer
>        Dim FrLat As Integer
>        Dim ToLong As Integer
>        Dim ToLat As Integer
>        Dim feFirP As String
>        Dim feName As String
>        Dim feType As String
>        Dim feDirS As String
>        Dim tlId As Long
>        Dim version As Short
>        Dim side1 As Boolean
>        Dim cfcc As String
>        While sr.Peek <> -1
>
>            'Converting coordinates
>            feType = LineIn.Substring(55, 1)
>            FrLong = 180000000 + CInt(LineIn.Substring(191, 9))
>            FrLat = 90000000 - CInt(LineIn.Substring(200, 9))
>            ToLong = 180000000 + CInt(LineIn.Substring(210, 9))
>            ToLat = 90000000 - CInt(LineIn.Substring(219, 9))
>
>            'writing new coordinates to new file
>            oWrite.Write(FrLong / 1000000)
>            oWrite.Write(" ")
>            oWrite.Write(FrLat / 1000000)
>            oWrite.Write(" ")
>            oWrite.Write(ToLong / 1000000)
>            oWrite.Write(" ")
>            oWrite.Write(ToLat / 1000000)
>            oWrite.Write(" ")
>            'If feType = "A" Then
>            '    oWrite.Write("hwy")
>            'Else : oWrite.Write("no")
>            'End If
>            oWrite.Write(vbCrLf)
>            'oWrite.BaseStream.Seek(0, SeekOrigin.End)
>
>        End While
>        oWrite.Close()
>        MessageBox.Show("Coordinates written to file")
>    End Function
>
Author
28 Apr 2006 4:51 AM
ataanis
Cor,
I did but It goes on a loop forever ,and I don't see anything wrong
with the loop.
Author
28 Apr 2006 5:37 AM
Cor Ligthert [MVP]
The least you can tell than where it goes in the loop?

Cor

<ataa***@gmail.com> schreef in bericht
Show quoteHide quote
news:1146199909.645133.4150@i39g2000cwa.googlegroups.com...
> Cor,
> I did but It goes on a loop forever ,and I don't see anything wrong
> with the loop.
>
Author
28 Apr 2006 6:13 AM
Branco Medeiros
ataa***@gmail.com wrote:
> Hey everyone
> I'm writing this simple function call from a sub , but for some reason
> when I click the file to open, it freezes, can anybody tell me what's
> the deal?
<snip>
>     Function MakeReadable(ByVal Location As String, ByVal FullPath As
> String, ByVal BaseName As String)
>         Dim sr As New System.IO.StreamReader(FullPath)
<snip>
>         LineIn = sr.ReadLine()
<snip>
>         While sr.Peek <> -1
<snip>
>         End While
<snip>

You must read the line from inside the loop:

  While sr.Peek <> -1
    LineIn = sr.ReadLine()
    '.
    '.
    '.
  End While

Regards,

Branco.
Author
28 Apr 2006 11:36 AM
Herfried K. Wagner [MVP]
<ataa***@gmail.com> schrieb:
> I'm writing this simple function call from a sub , but for some reason
> when I click the file to open, it freezes, can anybody tell me what's
> the deal?

Your code is lacking a 'ReadLine' call inside the loop.  Check out the
anatomy of line-by-line file reading code here:

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

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
28 Apr 2006 3:38 PM
Mythran
<ataa***@gmail.com> wrote in message
Show quoteHide quote
news:1146198227.107943.41040@g10g2000cwb.googlegroups.com...
> Hey everyone
> I'm writing this simple function call from a sub , but for some reason
> when I click the file to open, it freezes, can anybody tell me what's
> the deal?
> Thanks
>
> Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MenuItem2.Click
>        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
>            Dim FullPath As String
>            Dim BaseName As String
>            Dim Location As String
>            FullPath = OpenFileDialog1.FileName
>            BaseName = Path.GetFileNameWithoutExtension(FullPath)
>            Location = Path.GetDirectoryName(FullPath)
>            MakeReadable(Location, FullPath, BaseName)
>        End If
>
>
>    End Sub
>    Function MakeReadable(ByVal Location As String, ByVal FullPath As
> String, ByVal BaseName As String)
>        Dim sr As New System.IO.StreamReader(FullPath)
>        Dim oFile As System.IO.File
>        Dim oWrite As System.IO.StreamWriter
>        oWrite = oFile.CreateText(Location + "\" + BaseName + ".txt")
>        Dim LineIn As String
>        LineIn = sr.ReadLine()
>        Dim FrLong As Integer
>        Dim FrLat As Integer
>        Dim ToLong As Integer
>        Dim ToLat As Integer
>        Dim feFirP As String
>        Dim feName As String
>        Dim feType As String
>        Dim feDirS As String
>        Dim tlId As Long
>        Dim version As Short
>        Dim side1 As Boolean
>        Dim cfcc As String
>        While sr.Peek <> -1
>
>            'Converting coordinates
>            feType = LineIn.Substring(55, 1)
>            FrLong = 180000000 + CInt(LineIn.Substring(191, 9))
>            FrLat = 90000000 - CInt(LineIn.Substring(200, 9))
>            ToLong = 180000000 + CInt(LineIn.Substring(210, 9))
>            ToLat = 90000000 - CInt(LineIn.Substring(219, 9))
>
>            'writing new coordinates to new file
>            oWrite.Write(FrLong / 1000000)
>            oWrite.Write(" ")
>            oWrite.Write(FrLat / 1000000)
>            oWrite.Write(" ")
>            oWrite.Write(ToLong / 1000000)
>            oWrite.Write(" ")
>            oWrite.Write(ToLat / 1000000)
>            oWrite.Write(" ")
>            'If feType = "A" Then
>            '    oWrite.Write("hwy")
>            'Else : oWrite.Write("no")
>            'End If
>            oWrite.Write(vbCrLf)
>            'oWrite.BaseStream.Seek(0, SeekOrigin.End)
>
>        End While
>        oWrite.Close()
>        MessageBox.Show("Coordinates written to file")
>    End Function
>

sr.Peek never consumes the character it reads.  It never moves the pointer
from the current location.  Inside the loop, you don't have anything that
moves the pointer forward, just peeks...(no readlines, or reads).

Mythran
Author
28 Apr 2006 8:14 PM
Chris Dunaway
>> LineIn = sr.ReadLine()

This line needs to be inside your while loop