Important Message

You are browsing the archived Lancers Reactor forums. You cannot register or login.
The content may be outdated and links may not be functional.


To get the latest in Freelancer news, mods, modding and downloads, go to
The-Starport

Float values in VB

The general place to discuss MOD''ing Freelancer!

Post Thu Apr 03, 2003 8:52 pm

Float values in VB

I've almost finished the first part of an INI editor using VB. Unfortunately, I've run into a pretty big stumbling block. I can't get VB to treat the floating point values correctly. For example, in the first section of the light_equip.ini file there is a line with an attribute name of bulb_size. The value should be 0.20000. However, with a hex value of 0x3E4CCCCD (this has to be &H3E4CCCCD in V I get 1045220557 as a value when I try to convert to a Double. Obviously, there is a problem with the floating type conversion.

Any thoughts? Thank you for the help in adavance.

Scott E. Corbett
[email protected]

Post Fri Apr 04, 2003 11:22 am

Use Single data type (which is 4 bytes) and not Double(which is 8 bytes)

Post Fri Apr 04, 2003 4:40 pm

Using a single data type is almost right. VB still doesn't want to interpret the hex code anything other than a large number. I need someway to tell VB that this hexadecimal code should not be treated as a single large number, but ratehr a combination of a set of exponents and fractions.

Post Fri Apr 04, 2003 5:16 pm

Could you give a specific example of what you are trying to make?
Particularly, why are you using hex numbers to begin with? As far as I know, you don't really need hex numbers unless you are trying to convert resource's string ids.

Post Fri Apr 04, 2003 5:16 pm

can you get it to treat it as scientific notation?
ie 2e-1?


- All we see or seem, is but a dream within a dream. -

Post Fri Apr 04, 2003 5:19 pm

Is there a Vb forum we can move this post to?

Post Fri Apr 04, 2003 7:05 pm

Try changing the value from .2 to 100 and get the Hex value. Then change the number to 100.2 and see the difference.

Post Fri Apr 04, 2003 7:05 pm

<pre><font size=1 face=Courier>Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)

Dim MyHex As Long, MySingle As Single
MyHex = &H3E4CCCCD
CopyMemory MySingle, MyHex, 4

MsgBox MySingle ' = 0.2 </font></pre>

Post Fri Apr 04, 2003 9:30 pm

Dixi,

Cool. As I said in my email, that bit of code works great for numbers that only have a fractional component. Hexadecimal values that could have both en exponent and fractional part, or just an exponent still come back incorrectly. Hopefully, we'll be able to figure this one out. Again, thanks.

Scott E. Corbett
[email protected]

Post Sat Apr 05, 2003 1:29 am

Eh. Why read the value in as a number at all? Why not use the native WinAPI to read the value in as a string, manipulate it, and write it back as a string?

Below is a snippet from the form/module code for the editor i was working on:

Declare Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

I used these API functions to fashion my own functions (for convenience):

Private Sub WriteConfig(ByVal HEADER As String, ByVal KEY As String, ByVal DATA As String, PATH As String)
Dim wcResult As Long
wcResult = WritePrivateProfileString(HEADER, KEY, DATA, App.PATH + PATH)
End Sub

Private Function GetConfig(ByVal HEADER As String, ByVal KEY As String, PATH As String) As String
Dim uname As String
Dim slength As Long
uname = Space(255)
slength = GetPrivateProfileString(HEADER, KEY, "UNKNOWN", uname, 255, App.PATH + PATH)
uname = Left(uname, slength)
GetConfig = uname
End Function

Hope this helps!

Return to Freelancer General Editing Forum