|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Function call problemI'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 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 > Cor,
I did but It goes on a loop forever ,and I don't see anything wrong with the loop. 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. > ataa***@gmail.com wrote:
> Hey everyone <snip>> 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 <snip>> String, ByVal BaseName As String) > Dim sr As New System.IO.StreamReader(FullPath) > 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. <ataa***@gmail.com> schrieb:
> I'm writing this simple function call from a sub , but for some reason Your code is lacking a 'ReadLine' call inside the loop. Check out the > when I click the file to open, it freezes, can anybody tell me what's > the deal? 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/> <ataa***@gmail.com> wrote in message
Show quoteHide quote news:1146198227.107943.41040@g10g2000cwb.googlegroups.com... sr.Peek never consumes the character it reads. It never moves the pointer > 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 > from the current location. Inside the loop, you don't have anything that moves the pointer forward, just peeks...(no readlines, or reads). Mythran >> LineIn = sr.ReadLine() This line needs to be inside your while loop
At a loss figuring out if an IP is on LAN or INET
update form background color DLL does not load Dynamically DWORDS ? LONG? - I need to create constants for the following Datagrid, binded columns and unbinded columns Can't open a project by iteself? Solution opens every time! Stepping between .Net IDE into a VB6 dll call is this possible... Format Function Invoking apps within VB |
|||||||||||||||||||||||