473,499 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function call problem

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

Apr 28 '06 #1
7 971
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

<at*****@gmail.com> schreef in bericht
news:11*********************@g10g2000cwb.googlegro ups.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

Apr 28 '06 #2
Cor,
I did but It goes on a loop forever ,and I don't see anything wrong
with the loop.

Apr 28 '06 #3
The least you can tell than where it goes in the loop?

Cor

<at*****@gmail.com> schreef in bericht
news:11********************@i39g2000cwa.googlegrou ps.com...
Cor,
I did but It goes on a loop forever ,and I don't see anything wrong
with the loop.

Apr 28 '06 #4
at*****@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.

Apr 28 '06 #5
<at*****@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/>

Apr 28 '06 #6

<at*****@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.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

Apr 28 '06 #7
>> LineIn = sr.ReadLine()

This line needs to be inside your while loop

Apr 28 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
2435
by: Jacek Generowicz | last post by:
I have a program in which I make very good use of a memoizer: def memoize(callable): cache = {} def proxy(*args): try: return cache except KeyError: return cache.setdefault(args,...
3
4779
by: Janross | last post by:
I'm having trouble with a query that's prohibitively slow. On my free-standing office computer it's fine (well, 2-4 seconds), but on the client's network, it takes at least 5 minutes to run. ...
9
3260
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
6
5880
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
9
23719
by: Morten Lemvigh | last post by:
Is it possible to pass a pointer to a constructor or a class definition as argument to a function? Maybe in a way similar to passing function pointers...? The function should construct a number...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.