Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

vb.net converting integers etc..

Thread Tools
 
Search this Thread
 
Old 26 December 2002, 03:06 PM
  #1  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

Im going brain dead today..

im trying to read a byte from a file...

say the value I want to read out is 71 (hex)

this is 113 dec.

I then want to do the following conversions

(((113 * 8) - 750)/750.6) * 14.5

So I have tried the following...


Dim fstream As FileStream = New FileStream("c:\file.bin", FileMode.Open)

Dim breader As BinaryReader = New BinaryReader(fstream)

fstream.Seek("35136", SeekOrigin.Begin)
Dim u As Integer
u = System.Convert.ToSingle(breader.ReadByte)
u = u * 8
u = ((u - 750) / 750.6) * 14.5
MSFlexGrid2.set_TextMatrix(row, col, u)
' close files
breader.Close()
fstream.Close()

obviously Ive snipped a bit of code here and there.. so row and col arent important...

which works ok execpt it returns 3. not 2.97 as I expect..

Im sure its the convert to single.. as the help says

Converts the value of the specified 8-bit unsigned integer to the equivalent single-precision floating point number.

so I presume its the single precision bit...

what should I be doing???

Help.. otherwise im hitting the bottle

David
Old 26 December 2002, 07:57 PM
  #2  
Fosters
Scooby Regular
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
Post

I've not done much .Net yet, but am I correct in thinking that the convert to single actually converts 'u' to a Single. If it does I'm stuck, but if not that's why you're getting the 3.

Don't need to use a format statement on it do you?

(I'll get me coat )
Old 26 December 2002, 08:58 PM
  #3  
nigelward
Scooby Regular
 
nigelward's Avatar
 
Join Date: Oct 2001
Posts: 831
Likes: 0
Received 0 Likes on 0 Posts
Post

Dim u As Integer

Shouldn't that be:

Dim u As Single

Nigel
Old 27 December 2002, 10:10 AM
  #4  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

tried that dim u as single.

still gives 3 and not 2.7 or whatever...

David
Old 27 December 2002, 10:14 AM
  #5  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

ok tried that again and it worked.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
dpb
Non Scooby Related
14
03 October 2015 10:37 AM
ally d
ScoobyNet General
6
01 October 2015 09:22 PM
makkink
General Technical
10
01 October 2015 05:41 PM
Aaron_P85
Lighting and Other Electrical
1
28 September 2015 09:24 PM



Quick Reply: vb.net converting integers etc..



All times are GMT +1. The time now is 10:24 AM.