943,682 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 865
  • VB.NET RSS
Mar 1st, 2008
0

For the love of GOD! Someone please help me!!!

Expand Post »
You VB .NET developers out there,
I have posted 3 threads requesting help on reading floating point values from a binary file but did not get any reply at all. Is it because I am asking a stupid question or noone really have a clue about the question I asked? I am pretty sure that many of you know the answer. For the love of GOD, please give me some pointers on this. Following code just throws an exception at the first FOR NEXT loop where reading starts (Pls see the code below). I did manage reading integers from a binary file but just can't get it work to read floating point values.

Let me try to explain what I am trying to do. My program should read floating point values (values range between -1.00 and +1.00) from a binary file. After reading those floating point values, it will do some basic math with the values and then will write them into file.
Here is the code:
VB.NET Syntax (Toggle Plain Text)
  1. Dim s1 As FileStream 'Load file 1
  2. Dim s3 As FileStream 'Save output
  3.  
  4. If System.IO.File.Exists(TextBox19.Text) Then
  5. System.IO.File.Delete(TextBox19.Text)
  6. End If
  7. s1 = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read)
  8. s3 = New FileStream(TextBox19.Text, FileMode.CreateNew, FileAccess.Write)
  9.  
  10. Dim br1 As BinaryReader
  11. Dim bw As BinaryWriter
  12.  
  13. br1 = New BinaryReader(s1)
  14. bw = New BinaryWriter(s3)
  15.  
  16. Dim fLen1 As Integer
  17. Dim f1 As New System.IO.FileInfo(TextBox1.Text)
  18.  
  19.  
  20. fLen1 = f1.Length
  21.  
  22. Dim snglRead1(fLen1) As Single
  23. Dim snglOutput(fLen1) As Single 'wıll hold results from division
  24. Dim i As Integer
  25. Dim j As Integer
  26. Dim k As Integer
  27. Dim m As Integer
  28. For i = 0 To fLen1 - 1
  29. snglRead1(i) = br1.ReadSingle() 'EXCEPTION thrown right here
  30. Next
  31.  
  32. For j = 0 To fLen1 - 1
  33. snglOutput(j) = snglRead1(j)
  34. bw.Write(snglOutput(j))
  35. Next
  36.  
  37.  
  38. s1.Close()
  39. s3.Close()
  40. MessageBox.Show("file created succesfully!", "Done")
  41. Me.Close()
  42. End If
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
cs_tx_usa is offline Offline
26 posts
since Dec 2007
Mar 1st, 2008
0

Re: For the love of GOD! Someone please help me!!!

>I have posted 3 threads requesting help on reading floating
>point values from a binary file but did not get any reply at all.
So you've flooded the forum with threads asking the same question? That alone will cause people to ignore you.

>Following code just throws an exception
What exception? That's somewhat important information.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 1st, 2008
1

Re: For the love of GOD! Someone please help me!!!

Quote ...
For i = 0 To fLen1 - 1
snglRead1(i) = br1.ReadSingle() 'EXCEPTION thrown right here
Next
maybe you trying to read while you reached the end of file ,
Quote ...
fLen1 = f1.Length
i think this return length on byte , try this
VB.NET Syntax (Toggle Plain Text)
  1. fLen1 = Int(f1.Length / 4)
Reputation Points: 37
Solved Threads: 17
Junior Poster
manal is offline Offline
122 posts
since Mar 2006
Mar 3rd, 2008
0

Re: For the love of GOD! Someone please help me!!!

Thank you Manal for your reply. As you suggested, I divided f1.Length by 4 and it worked. I appreciate it...
Reputation Points: 10
Solved Threads: 0
Light Poster
cs_tx_usa is offline Offline
26 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Results from Select statement differ in VB.NET and Access
Next Thread in VB.NET Forum Timeline: Automatic Files Sorting and Folders Creation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC