|
-
July 4th, 2001, 11:29 PM
#1
Typecast
i want to typecase a string into a double variable in VB ie i have retrieved 8 bytes from a data file in an string but it represents a double value so i want to now typecast the same to double keeping the byte code same as that of string.Please tell me how to do this
-
July 5th, 2001, 12:15 AM
#2
Re: Typecast
private Declare Sub RtlMoveMemory Lib "kernel32" (Des as Any, Src as Any, byval Length as Long)
private Sub Form_Load()
Dim i as Double
Dim s as string
Dim b(7) as Byte
Dim k as Long
s = "12345678" ' here replace with ur string with 8 bytes.
for k = 0 to 7
b(k) = Asc(mid(s, i + 1, 1))
next k
RtlMoveMemory i, VarPtr(b(0)), 8
Debug.print i
End Sub
HTH
cksiow
http://vblib.virtualave.net - share our codes
-
July 5th, 2001, 01:06 AM
#3
Re: Typecast
Thanks a lot for the reply...
Please tell me where I can find more info about "RtlMoveMemory "
My program needs to be compatible with both windows95 and 2000.Will this API serve my purpose?
Can I do typecasting without using any API's?
-
July 5th, 2001, 01:39 AM
#4
Re: Typecast
rtlmovememory is undocumented. and you are not support to use it in VB, because it might crash the program if use wrongly.
The code doesn't actually do casting, it move the data from one location of memory to another location. if need casting vb got a lot of functions, e.g.
dim s as string
dim l as long
s = "12"
l = clng(s) 'l = 12
HTH
cksiow
http://vblib.virtualave.net - share our codes
-
July 5th, 2001, 01:45 AM
#5
Re: Typecast
sorry on the term, it is copy data from one location to another, not Move, and this API should work for both platform.
HTH
cksiow
http://vblib.virtualave.net - share our codes
-
July 5th, 2001, 03:53 AM
#6
Re: Typecast
"Clng" is a conversion function.I need to typecast a string to double and not convert.
We need to keep the byte code same so that say "3" in string will not be 3 in integer rather it would be the ascii value of 3
-
July 7th, 2001, 11:03 PM
#7
Re: Typecast
private Type Str8Byte
Value as string
End Type
private Type MyDbl
Value as Double
End Type
public Function TypeCast(sTmp as string) as double
Dim s8Tmp as Str8Byte
Dim dTmp as MyDbl
s8Tmp.Value = sTmp
LSet dTmp = s8Tmp
TypeCast = dTmp.Value
End Function
If your string has more than 8 bytes, you will get a type mismatch on the LSet command.
Hope this helps.
Spectre
-
July 9th, 2001, 05:17 AM
#8
Re: Typecast
Thanks a lot for your reply.....
Can you please give me the code to typecast a double into a string variable?
-
July 9th, 2001, 05:24 AM
#9
Re: Typecast
private Declare Sub RtlMoveMemory Lib "kernel32" (Des as Any, Src as Any, byval Length as Long)
private Sub Form_Load()
Dim i as Double
Dim s as string
Dim b(7) as Byte
Dim k as Long
s = ""
i = 123
RtlMoveMemory b(0), i, 8
for k = 0 to 7
s = s & Chr(b(k))
next k
Debug.print s
End Sub
HTH
cksiow
http://vblib.virtualave.net - share our codes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|