Function call problem

A

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
 
C

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
 
A

ataanis

Cor,
I did but It goes on a loop forever ,and I don't see anything wrong
with the loop.
 
B

Branco Medeiros

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?
Function MakeReadable(ByVal Location As String, ByVal FullPath As
String, ByVal BaseName As String)
Dim sr As New System.IO.StreamReader(FullPath)
LineIn = sr.ReadLine()
While sr.Peek <> -1
End While
<snip>

You must read the line from inside the loop:

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

Regards,

Branco.
 
M

Mythran

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top