Im trying to convert some integers to a string (which works fine)
For example
My Funciton MKI is working ok as far as i can tell
Dim v1 as String = MKI(116)
V1 then equals "t
I wish it to equal "t"
Can anyone offer any suggestions please
Im trying to convert some integers to a string (which works fine)
For example
My Funciton MKI is working ok as far as i can tell
Dim v1 as String = MKI(116)
V1 then equals "t
I wish it to equal "t"
Can anyone offer any suggestions please
Converting an Integer to String
bfarr23
This code could fail when you least expect it. Some bad, rainy day, the garbage collector is going to move sTemp in memory just as CopyMemory() is executing. VB.NET has a good alternative to MKI():
Dim V1 As String = Chr(116)
00Negative
Joseph Stalin
I'm going to unsubscribe from this thread and wish you the best of luck.
Stckmn3
Thats good to know nobugz :)
When i have the app "completed" i might have to go back and adjust all the code to use proper .net bits
Don't suppose you know the .net bits for
MKI
MKL
CVI
CVL
CVD
:)
Private Declare Sub CopyMemoryMKL Lib "Kernel32" Alias "RtlMoveMemory" (ByVal hDest As String, ByRef hSource As Integer, ByVal iBytes As Integer) Private Declare Sub CopyMemoryMKI Lib "Kernel32" Alias "RtlMoveMemory" (ByVal hDest As String, ByRef hSource As Short, ByVal iBytes As Integer) Private Declare Sub CopyMemoryCVI Lib "Kernel32" Alias "RtlMoveMemory" (ByRef hDest As Short, ByVal hSource As String, ByVal iBytes As Integer) Private Declare Sub CopyMemoryCVDt Lib "Kernel32" Alias "RtlMoveMemory" (ByRef hDest As Double, ByVal hSource As String, ByVal iBytes As Integer) Private Declare Sub CopyMemoryCVL Lib "Kernel32" Alias "RtlMoveMemory" (ByRef hDest As Integer, ByVal hSource As String, ByVal iBytes As Integer)Leonard Lee
For what your doing your should either using the .tostring method or using a conversion function like Cint, Ctype( , STring)
To convert an integer to a string, sure with option strict off then there will be an implicit conversion but its best to make this conversion explicit and specific.
Without seeing what you Function MKI is actually doing its rather difficult to tell what your problem is.
Turn Option strict on and make sure that you are specifying any conversions.
Thymen
Can-Ann
Only use RtlMoveMemory on unmanaged memory locations. Even then, there are some .NET functions which offer better handling (Marshal) of such copies/moves.
All these declarations are doing is moving at most 4 bytes around. Not sure what you are actually trying to achieve, but look at the Marshal.Copy (as a generic alternative), and associated support functions for locking memory in place. You are probably doing something which has a direct .NET equivalent, though. It just sounds like you are converting strings to numbers and visa versa.
jaimlin
QuantumMischief
Thanks nobugz. :)
It appears that in the short term at least, i will be forced to use the "unsafe code". Not a pleasant thought but i'll just cross my fingers, stick everything in a try loop and log all exceptions that may or may not occur.
I'll post something if i find anything :)
Colmeister
I wouldn't be surprised. This application is a progression of something that was originally started in QB7 and then moved to vb6, now some aspects are being used in .Net.
I take a date (lets say its 08/05/50)
The following code converts the above date into the integer
and i would call it with the following line from somewhere in my code
fgXs = TempX '(tempx = "08/05/50")
FromDate(1, fgXd, fgXs, fgx)
Private Sub FromDate(ByVal gTx As Integer, ByVal tgXd As Double, ByVal tgXs As String, ByVal tgX As Integer)
' tempx is the date we want to change
Tempx = tgXs
Year = Mid$(tgXs$, 7)
If Len(Year) = 2 Then If Val(Year) < 70 ThenYear =
"20" + Year ElseYear =
"19" + Year End IftgXs$ = Mid$(tgXs$, 1, 6) + Year
End IfTempx$ = Mid$(tgXs$, 1, 2) + Mid$(tgXs$, 4, 2) + Mid$(tgXs$, 7, 4)
Dd = Val(Microsoft.VisualBasic.Strings.Left$(Tempx$, 2)) :
If Dd < 1 Or Dd > 31 Then GoTo formerrorMm = Val(Mid$(Tempx$, 3, 2)) :
If Mm > 12 Then GoTo formerror If Mm < 1 Then Mm = Val(Mid$(Dt$, 4, 2))Yy = Val(Microsoft.VisualBasic.Strings.Right$(Tempx$, 4))
If Yy < 1 Then Yy = Val(Mid$(Dt$, 7, 4)) If Yy < 1972 Then GoTo formerrorYy = Yy - 1900
x = Dd + (Yy - 72) * 365 + Int((Yy - 69) / 4) + Val(Mid$(Dq$, 3 * Mm - 2, 3))
If Mm > 2 And (1900 + Yy) / 4 = Int((1900 + Yy) / 4) Then x = x + 1tgXd = x
tgX =
CInt(x)BdateW = tgX
DTW = MKI(tgX)
GoTo edateformerror:
tgXs$ =
"ERROR " : gTx = 0edate:
End Sub ' Converts Datedepending on the date field in question, i am either writing a date value as a integer OR as an integer converted to string
In the above example, we'd end up with 08/05/50 =
bdateW = tgx = 28618 (integer)
DTW = MKI(tgX) = "Eo" as a string
All the other functions are simply to convert the 28618 or the Eo back into their original format
Does that all make sense
Raihan Iqbal
For interests sake this is the MKI function
Private
Declare Sub CopyMemoryMKI Lib "Kernel32" Alias "RtlMoveMemory" (ByVal hDest As String, ByRef hSource As Short, ByVal iBytes As Integer)Shared Function MKI(ByRef Value As Short) As String
Dim sTemp As String = Space(2)CopyMemoryMKI(sTemp, Value, 2I)
Return sTemp End Functionas it turns out, all i had to do was change my code to read
Dim V1 as String = MKI(116).substring(0,1)
and that sorted my problem. Possibly not the safest thing to do, but it works :)