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

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 19
Reputation: cs_tx_usa is an unknown quantity at this point 
Solved Threads: 0
cs_tx_usa's Avatar
cs_tx_usa cs_tx_usa is offline Offline
Newbie Poster

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

 
0
  #1
Mar 1st, 2008
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:
  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
“Remember: If you’re not experiencing failure, you’re not working hard enough!”
Jeffrey J. Mayer
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,817
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

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

 
0
  #2
Mar 1st, 2008
>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.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 122
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

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

 
1
  #3
Mar 1st, 2008
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 ,
fLen1 = f1.Length
i think this return length on byte , try this
  1. fLen1 = Int(f1.Length / 4)
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 19
Reputation: cs_tx_usa is an unknown quantity at this point 
Solved Threads: 0
cs_tx_usa's Avatar
cs_tx_usa cs_tx_usa is offline Offline
Newbie Poster

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

 
0
  #4
Mar 3rd, 2008
Thank you Manal for your reply. As you suggested, I divided f1.Length by 4 and it worked. I appreciate it...
“Remember: If you’re not experiencing failure, you’re not working hard enough!”
Jeffrey J. Mayer
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC