All,
In vb6.0, some of our co-developers used the following ...
Private Declare Sub MoveMemory Lib "kernel32.dll"
Alias "RtlMoveMemory" (ByVal dst As Any, ByVal src As
Any, ByVal cb As Long)
This gave us some errors when we tried to use in VS.Net.
We did change it to typed:
Private Declare Sub MoveMemory Lib "kernel32.dll"
Alias "RtlMoveMemory" (ByVal dst As Byte, ByVal src As
String, ByVal cb As Long)
However, now we're getting
An unhandled exception of
type 'System.NullReferenceException' occurred in
ConsoleApplication2.exe
Additional information: Object reference not set to an
instance of an object.
Pardon the length, but code follows. Any help - this is
urgent ...
Thx
John
Module Module1Attribute
Private Declare Sub MoveMemory Lib "kernel32.dll"
Alias "RtlMoveMemory" (ByVal dst As Byte, ByVal src As
String, ByVal cb As Long)
Private Declare Sub ReMoveMemory Lib "kernel32.dll"
Alias "RtlMoveMemory" (ByVal src As String, ByVal dst As
Byte, ByVal cb As Long)
Sub Main()
Dim message As String
message = "Junk Junk Junk Junk"
Console.WriteLine(EncodeString(message))
End Sub
Public Function EncodeString(ByVal InString As
String, Optional ByVal StringToBinaryConv As Boolean =
False) As String
Dim OutString As String
Dim I As Long
Dim UnCodedArray() As Byte
Dim CodedArray() As Byte
' Begin:SCR #35900; Developer: Mag 05/08/2003
12:32 PM
If Trim$(InString) = "" Then
EncodeString = ""
Exit Function
End If
' End: SCR #35900;
'To handle compressed encounter data
'If StringToBinaryConv Then
'InString = StrConv(InString, vbUnicode)
'End If
'Pad will null characters if necessary
If Len(InString) Mod 3 <> 0 Then
Dim x As Int32
For x = 1 To (3 - Len(InString) Mod 3)
InString = InString & vbNullChar
Next
'nString = InString & String(3 - Len
(InString) Mod 3, Chr(0))
End If
'Convert string to a byte array. This is MUCH
faster than the Asc/Chr combo.
StringToByteArray(InString, UnCodedArray)
'Make sure our output array is the correct size
ReDim CodedArray(((Len(InString) / 3) * 4) - 1)
For I = 0 To (Len(InString) / 3) - 1
'Encode 4 bytes at a time
CodedArray(I * 4 + 0) = UnCodedArray(I * 3 +
0) \ 4 + 32
CodedArray(I * 4 + 1) = ((UnCodedArray(I * 3
+ 0) Mod 4) * 16) + (UnCodedArray(I * 3 + 1) \ 16 + 32)
CodedArray(I * 4 + 2) = ((UnCodedArray(I * 3
+ 1) Mod 16) * 4) + (UnCodedArray(I * 3 + 2) \ 64 + 32)
CodedArray(I * 4 + 3) = (UnCodedArray(I * 3 +
2) Mod 64) + 32
'Check for spaces and eliminate them
If CodedArray(I * 4 + 0) = 32 Then CodedArray
(I * 4 + 0) = 96
If CodedArray(I * 4 + 1) = 32 Then CodedArray
(I * 4 + 1) = 96
If CodedArray(I * 4 + 2) = 32 Then CodedArray
(I * 4 + 2) = 96
If CodedArray(I * 4 + 3) = 32 Then CodedArray
(I * 4 + 3) = 96
Next I
ByteArrayToString(CodedArray, OutString)
'Replace characters that cannot be sent in XML
'OutString = FilterRtfToXml(OutString)
EncodeString = OutString
End Function
Private Sub StringToByteArray(ByVal StringIn As
String, ByVal ByteArray() As Byte)
Dim lBytes As Long
If Len(StringIn) = 0 Then Exit Sub
lBytes = Len(StringIn)
ReDim ByteArray(lBytes - 1)
MoveMemory(ByteArray(0), StringIn, lBytes)
End Sub
Private Sub ByteArrayToString(ByVal ByteArray() As
Byte, ByVal StringOut As String)
Dim lBytes As Long
If LBound(ByteArray) > 0 Then Exit Sub 'lBound
MUST be 0
lBytes = UBound(ByteArray) + 1
StringOut = Convert.ToString(lBytes, 0)
ReMoveMemory(StringOut, ByteArray(0), lBytes * 2)
End Sub
End Module 5 7487
John,
I suggest you use one of the System.Text.Encoding subclasses for
converting String <-> Byte() instead.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
John,
In addition to what Mattias stated about using System.Text.Encoding to
convert Strings to Byte.
If you want to move elements of one array to another array, use
System.Buffer.BlockCopy. You can use System.Buffer.ByteLength to find out
how many bytes there are. String has a ToCharArray to convert the String to
an array of Char.
Note BlockCopy will move 2 bytes for each Char, while Encoding may convert 1
Char to 1 Byte.
Buffer.BlockCopy is the .NET equivalent of RtlMoveMemory!
Hope this helps
Jay
"John Koisch" <jk*****@hotmail.com> wrote in message
news:45****************************@phx.gbl... All,
In vb6.0, some of our co-developers used the following ...
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Any, ByVal src As Any, ByVal cb As Long)
This gave us some errors when we tried to use in VS.Net. We did change it to typed:
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Byte, ByVal src As String, ByVal cb As Long)
However, now we're getting
An unhandled exception of type 'System.NullReferenceException' occurred in ConsoleApplication2.exe
Additional information: Object reference not set to an instance of an object.
Pardon the length, but code follows. Any help - this is urgent ...
Thx John
Module Module1Attribute
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Byte, ByVal src As String, ByVal cb As Long)
Private Declare Sub ReMoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal src As String, ByVal dst As Byte, ByVal cb As Long)
Sub Main() Dim message As String
message = "Junk Junk Junk Junk"
Console.WriteLine(EncodeString(message)) End Sub
Public Function EncodeString(ByVal InString As String, Optional ByVal StringToBinaryConv As Boolean = False) As String Dim OutString As String Dim I As Long Dim UnCodedArray() As Byte Dim CodedArray() As Byte
' Begin:SCR #35900; Developer: Mag 05/08/2003 12:32 PM If Trim$(InString) = "" Then EncodeString = "" Exit Function End If ' End: SCR #35900;
'To handle compressed encounter data 'If StringToBinaryConv Then 'InString = StrConv(InString, vbUnicode) 'End If
'Pad will null characters if necessary If Len(InString) Mod 3 <> 0 Then Dim x As Int32 For x = 1 To (3 - Len(InString) Mod 3) InString = InString & vbNullChar Next 'nString = InString & String(3 - Len (InString) Mod 3, Chr(0)) End If
'Convert string to a byte array. This is MUCH faster than the Asc/Chr combo. StringToByteArray(InString, UnCodedArray)
'Make sure our output array is the correct size ReDim CodedArray(((Len(InString) / 3) * 4) - 1)
For I = 0 To (Len(InString) / 3) - 1 'Encode 4 bytes at a time CodedArray(I * 4 + 0) = UnCodedArray(I * 3 + 0) \ 4 + 32 CodedArray(I * 4 + 1) = ((UnCodedArray(I * 3 + 0) Mod 4) * 16) + (UnCodedArray(I * 3 + 1) \ 16 + 32) CodedArray(I * 4 + 2) = ((UnCodedArray(I * 3 + 1) Mod 16) * 4) + (UnCodedArray(I * 3 + 2) \ 64 + 32) CodedArray(I * 4 + 3) = (UnCodedArray(I * 3 + 2) Mod 64) + 32
'Check for spaces and eliminate them If CodedArray(I * 4 + 0) = 32 Then CodedArray (I * 4 + 0) = 96 If CodedArray(I * 4 + 1) = 32 Then CodedArray (I * 4 + 1) = 96 If CodedArray(I * 4 + 2) = 32 Then CodedArray (I * 4 + 2) = 96 If CodedArray(I * 4 + 3) = 32 Then CodedArray (I * 4 + 3) = 96 Next I ByteArrayToString(CodedArray, OutString)
'Replace characters that cannot be sent in XML 'OutString = FilterRtfToXml(OutString)
EncodeString = OutString End Function
Private Sub StringToByteArray(ByVal StringIn As String, ByVal ByteArray() As Byte) Dim lBytes As Long
If Len(StringIn) = 0 Then Exit Sub
lBytes = Len(StringIn) ReDim ByteArray(lBytes - 1)
MoveMemory(ByteArray(0), StringIn, lBytes) End Sub Private Sub ByteArrayToString(ByVal ByteArray() As Byte, ByVal StringOut As String) Dim lBytes As Long
If LBound(ByteArray) > 0 Then Exit Sub 'lBound MUST be 0 lBytes = UBound(ByteArray) + 1 StringOut = Convert.ToString(lBytes, 0) ReMoveMemory(StringOut, ByteArray(0), lBytes * 2) End Sub
End Module
Thanks for your comments. We are, however, in the not
unheard of situation of having to deal with OPC (other
people's code). This actually comes to us from a
different shop in the enterprise, and they are offering
no support, etc. SO, to make this process work, we are 1)
stuck with a bad process, and 2) stuck with their code.
Otherwise, I would be happy to use other, better, faster
solutions.
So, any more thoughts on the nature of our error?
John -----Original Message----- John, In addition to what Mattias stated about using
System.Text.Encoding toconvert Strings to Byte.
If you want to move elements of one array to another
array, useSystem.Buffer.BlockCopy. You can use
System.Buffer.ByteLength to find outhow many bytes there are. String has a ToCharArray to
convert the String toan array of Char.
Note BlockCopy will move 2 bytes for each Char, while
Encoding may convert 1Char to 1 Byte.
Buffer.BlockCopy is the .NET equivalent of RtlMoveMemory!
Hope this helps Jay
"John Koisch" <jk*****@hotmail.com> wrote in message news:45****************************@phx.gbl... All,
In vb6.0, some of our co-developers used the
following ... Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Any, ByVal src As Any, ByVal cb As Long)
This gave us some errors when we tried to use in
VS.Net. We did change it to typed:
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Byte, ByVal src As String, ByVal cb As Long)
However, now we're getting
An unhandled exception of type 'System.NullReferenceException' occurred in ConsoleApplication2.exe
Additional information: Object reference not set to an instance of an object.
Pardon the length, but code follows. Any help - this is urgent ...
Thx John
Module Module1Attribute
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Byte, ByVal src As String, ByVal cb As Long)
Private Declare Sub ReMoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal src As String, ByVal dst
As Byte, ByVal cb As Long)
Sub Main() Dim message As String
message = "Junk Junk Junk Junk"
Console.WriteLine(EncodeString(message)) End Sub
Public Function EncodeString(ByVal InString As String, Optional ByVal StringToBinaryConv As Boolean = False) As String Dim OutString As String Dim I As Long Dim UnCodedArray() As Byte Dim CodedArray() As Byte
' Begin:SCR #35900; Developer: Mag 05/08/2003 12:32 PM If Trim$(InString) = "" Then EncodeString = "" Exit Function End If ' End: SCR #35900;
'To handle compressed encounter data 'If StringToBinaryConv Then 'InString = StrConv(InString, vbUnicode) 'End If
'Pad will null characters if necessary If Len(InString) Mod 3 <> 0 Then Dim x As Int32 For x = 1 To (3 - Len(InString) Mod 3) InString = InString & vbNullChar Next 'nString = InString & String(3 - Len (InString) Mod 3, Chr(0)) End If
'Convert string to a byte array. This is MUCH faster than the Asc/Chr combo. StringToByteArray(InString, UnCodedArray)
'Make sure our output array is the correct size ReDim CodedArray(((Len(InString) / 3) * 4) - 1)
For I = 0 To (Len(InString) / 3) - 1 'Encode 4 bytes at a time CodedArray(I * 4 + 0) = UnCodedArray(I * 3
+ 0) \ 4 + 32 CodedArray(I * 4 + 1) = ((UnCodedArray(I *
3 + 0) Mod 4) * 16) + (UnCodedArray(I * 3 + 1) \ 16 + 32) CodedArray(I * 4 + 2) = ((UnCodedArray(I *
3 + 1) Mod 16) * 4) + (UnCodedArray(I * 3 + 2) \ 64 + 32) CodedArray(I * 4 + 3) = (UnCodedArray(I *
3 + 2) Mod 64) + 32
'Check for spaces and eliminate them If CodedArray(I * 4 + 0) = 32 Then
CodedArray (I * 4 + 0) = 96 If CodedArray(I * 4 + 1) = 32 Then
CodedArray (I * 4 + 1) = 96 If CodedArray(I * 4 + 2) = 32 Then
CodedArray (I * 4 + 2) = 96 If CodedArray(I * 4 + 3) = 32 Then
CodedArray (I * 4 + 3) = 96 Next I ByteArrayToString(CodedArray, OutString)
'Replace characters that cannot be sent in XML 'OutString = FilterRtfToXml(OutString)
EncodeString = OutString End Function
Private Sub StringToByteArray(ByVal StringIn As String, ByVal ByteArray() As Byte) Dim lBytes As Long
If Len(StringIn) = 0 Then Exit Sub
lBytes = Len(StringIn) ReDim ByteArray(lBytes - 1)
MoveMemory(ByteArray(0), StringIn, lBytes) End Sub Private Sub ByteArrayToString(ByVal ByteArray() As Byte, ByVal StringOut As String) Dim lBytes As Long
If LBound(ByteArray) > 0 Then Exit Sub 'lBound MUST be 0 lBytes = UBound(ByteArray) + 1 StringOut = Convert.ToString(lBytes, 0) ReMoveMemory(StringOut, ByteArray(0), lBytes *
2) End Sub
End Module
.
John, no support, etc. SO, to make this process work, we are 1) stuck with a bad process, and 2) stuck with their code.
Huh???
As far as I can tell: To make this process work you need do one of the
following instead of calling RtlMoveMemory:
1. use the Buffer class http://msdn.microsoft.com/library/de...ClassTopic.asp
2. use the Encoding class http://msdn.microsoft.com/library/de...ClassTopic.asp
Luckily your code encapsulates the call to RtlMoveMemory into to sub
routines.
Both are very easy to use. 'Convert string to a byte array. This is MUCH faster than the Asc/Chr combo. StringToByteArray(InString, UnCodedArray)
The problem as I see it is that the 'faster than Asc/Chr combo' suggests you
want to use the Encoding class, while RtlMoveMemory suggests you want to use
Buffer.BlockCopy.
Buffer.BlockCopy will more closely match how you are currently using
RtlMoveMemory. Whether that is correct or not I'm not sure.
Oh! and by the way, String objects are immutable in .NET, your
ByteArrayToString routine should use a System.Text.StringBuilder instead.
Hope this helps
Jay
"John Koisch" <jk*****@hotmail.com> wrote in message
news:02****************************@phx.gbl... Thanks for your comments. We are, however, in the not unheard of situation of having to deal with OPC (other people's code). This actually comes to us from a different shop in the enterprise, and they are offering no support, etc. SO, to make this process work, we are 1) stuck with a bad process, and 2) stuck with their code.
Otherwise, I would be happy to use other, better, faster solutions.
So, any more thoughts on the nature of our error?
John-----Original Message----- John, In addition to what Mattias stated about using System.Text.Encoding toconvert Strings to Byte.
If you want to move elements of one array to another array, useSystem.Buffer.BlockCopy. You can use System.Buffer.ByteLength to find outhow many bytes there are. String has a ToCharArray to convert the String toan array of Char.
Note BlockCopy will move 2 bytes for each Char, while Encoding may convert 1Char to 1 Byte.
Buffer.BlockCopy is the .NET equivalent of RtlMoveMemory!
Hope this helps Jay
"John Koisch" <jk*****@hotmail.com> wrote in message news:45****************************@phx.gbl... All,
In vb6.0, some of our co-developers used the following ... Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Any, ByVal src As Any, ByVal cb As Long)
This gave us some errors when we tried to use in VS.Net. We did change it to typed:
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Byte, ByVal src As String, ByVal cb As Long)
However, now we're getting
An unhandled exception of type 'System.NullReferenceException' occurred in ConsoleApplication2.exe
Additional information: Object reference not set to an instance of an object.
Pardon the length, but code follows. Any help - this is urgent ...
Thx John
Module Module1Attribute
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Byte, ByVal src As String, ByVal cb As Long)
Private Declare Sub ReMoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal src As String, ByVal dst As Byte, ByVal cb As Long)
Sub Main() Dim message As String
message = "Junk Junk Junk Junk"
Console.WriteLine(EncodeString(message)) End Sub
Public Function EncodeString(ByVal InString As String, Optional ByVal StringToBinaryConv As Boolean = False) As String Dim OutString As String Dim I As Long Dim UnCodedArray() As Byte Dim CodedArray() As Byte
' Begin:SCR #35900; Developer: Mag 05/08/2003 12:32 PM If Trim$(InString) = "" Then EncodeString = "" Exit Function End If ' End: SCR #35900;
'To handle compressed encounter data 'If StringToBinaryConv Then 'InString = StrConv(InString, vbUnicode) 'End If
'Pad will null characters if necessary If Len(InString) Mod 3 <> 0 Then Dim x As Int32 For x = 1 To (3 - Len(InString) Mod 3) InString = InString & vbNullChar Next 'nString = InString & String(3 - Len (InString) Mod 3, Chr(0)) End If
'Convert string to a byte array. This is MUCH faster than the Asc/Chr combo. StringToByteArray(InString, UnCodedArray)
'Make sure our output array is the correct size ReDim CodedArray(((Len(InString) / 3) * 4) - 1)
For I = 0 To (Len(InString) / 3) - 1 'Encode 4 bytes at a time CodedArray(I * 4 + 0) = UnCodedArray(I * 3 + 0) \ 4 + 32 CodedArray(I * 4 + 1) = ((UnCodedArray(I * 3 + 0) Mod 4) * 16) + (UnCodedArray(I * 3 + 1) \ 16 + 32) CodedArray(I * 4 + 2) = ((UnCodedArray(I * 3 + 1) Mod 16) * 4) + (UnCodedArray(I * 3 + 2) \ 64 + 32) CodedArray(I * 4 + 3) = (UnCodedArray(I * 3 + 2) Mod 64) + 32
'Check for spaces and eliminate them If CodedArray(I * 4 + 0) = 32 Then CodedArray (I * 4 + 0) = 96 If CodedArray(I * 4 + 1) = 32 Then CodedArray (I * 4 + 1) = 96 If CodedArray(I * 4 + 2) = 32 Then CodedArray (I * 4 + 2) = 96 If CodedArray(I * 4 + 3) = 32 Then CodedArray (I * 4 + 3) = 96 Next I ByteArrayToString(CodedArray, OutString)
'Replace characters that cannot be sent in XML 'OutString = FilterRtfToXml(OutString)
EncodeString = OutString End Function
Private Sub StringToByteArray(ByVal StringIn As String, ByVal ByteArray() As Byte) Dim lBytes As Long
If Len(StringIn) = 0 Then Exit Sub
lBytes = Len(StringIn) ReDim ByteArray(lBytes - 1)
MoveMemory(ByteArray(0), StringIn, lBytes) End Sub Private Sub ByteArrayToString(ByVal ByteArray() As Byte, ByVal StringOut As String) Dim lBytes As Long
If LBound(ByteArray) > 0 Then Exit Sub 'lBound MUST be 0 lBytes = UBound(ByteArray) + 1 StringOut = Convert.ToString(lBytes, 0) ReMoveMemory(StringOut, ByteArray(0), lBytes * 2) End Sub
End Module
.
John,
I should add to my other post that the Encoding class has shared properties
for different encodings, for example there is Encoding.Unicode which will
convert strings into an array of bytes of Unicode characters (remember each
Unicode character will take up two bytes). There is a Encoding.Default which
will convert strings into the char set currently set for Windows.
Also the Encoding class has a GetBytes method that will convert a string
into an array of bytes. Plus an GetString that will convert an array of
bytes to a string.
Hope this helps
Jay
"John Koisch" <jk*****@hotmail.com> wrote in message
news:02****************************@phx.gbl... Thanks for your comments. We are, however, in the not unheard of situation of having to deal with OPC (other people's code). This actually comes to us from a different shop in the enterprise, and they are offering no support, etc. SO, to make this process work, we are 1) stuck with a bad process, and 2) stuck with their code.
Otherwise, I would be happy to use other, better, faster solutions.
So, any more thoughts on the nature of our error?
John-----Original Message----- John, In addition to what Mattias stated about using System.Text.Encoding toconvert Strings to Byte.
If you want to move elements of one array to another array, useSystem.Buffer.BlockCopy. You can use System.Buffer.ByteLength to find outhow many bytes there are. String has a ToCharArray to convert the String toan array of Char.
Note BlockCopy will move 2 bytes for each Char, while Encoding may convert 1Char to 1 Byte.
Buffer.BlockCopy is the .NET equivalent of RtlMoveMemory!
Hope this helps Jay
"John Koisch" <jk*****@hotmail.com> wrote in message news:45****************************@phx.gbl... All,
In vb6.0, some of our co-developers used the following ... Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Any, ByVal src As Any, ByVal cb As Long)
This gave us some errors when we tried to use in VS.Net. We did change it to typed:
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Byte, ByVal src As String, ByVal cb As Long)
However, now we're getting
An unhandled exception of type 'System.NullReferenceException' occurred in ConsoleApplication2.exe
Additional information: Object reference not set to an instance of an object.
Pardon the length, but code follows. Any help - this is urgent ...
Thx John
Module Module1Attribute
Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal dst As Byte, ByVal src As String, ByVal cb As Long)
Private Declare Sub ReMoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal src As String, ByVal dst As Byte, ByVal cb As Long)
Sub Main() Dim message As String
message = "Junk Junk Junk Junk"
Console.WriteLine(EncodeString(message)) End Sub
Public Function EncodeString(ByVal InString As String, Optional ByVal StringToBinaryConv As Boolean = False) As String Dim OutString As String Dim I As Long Dim UnCodedArray() As Byte Dim CodedArray() As Byte
' Begin:SCR #35900; Developer: Mag 05/08/2003 12:32 PM If Trim$(InString) = "" Then EncodeString = "" Exit Function End If ' End: SCR #35900;
'To handle compressed encounter data 'If StringToBinaryConv Then 'InString = StrConv(InString, vbUnicode) 'End If
'Pad will null characters if necessary If Len(InString) Mod 3 <> 0 Then Dim x As Int32 For x = 1 To (3 - Len(InString) Mod 3) InString = InString & vbNullChar Next 'nString = InString & String(3 - Len (InString) Mod 3, Chr(0)) End If
'Convert string to a byte array. This is MUCH faster than the Asc/Chr combo. StringToByteArray(InString, UnCodedArray)
'Make sure our output array is the correct size ReDim CodedArray(((Len(InString) / 3) * 4) - 1)
For I = 0 To (Len(InString) / 3) - 1 'Encode 4 bytes at a time CodedArray(I * 4 + 0) = UnCodedArray(I * 3 + 0) \ 4 + 32 CodedArray(I * 4 + 1) = ((UnCodedArray(I * 3 + 0) Mod 4) * 16) + (UnCodedArray(I * 3 + 1) \ 16 + 32) CodedArray(I * 4 + 2) = ((UnCodedArray(I * 3 + 1) Mod 16) * 4) + (UnCodedArray(I * 3 + 2) \ 64 + 32) CodedArray(I * 4 + 3) = (UnCodedArray(I * 3 + 2) Mod 64) + 32
'Check for spaces and eliminate them If CodedArray(I * 4 + 0) = 32 Then CodedArray (I * 4 + 0) = 96 If CodedArray(I * 4 + 1) = 32 Then CodedArray (I * 4 + 1) = 96 If CodedArray(I * 4 + 2) = 32 Then CodedArray (I * 4 + 2) = 96 If CodedArray(I * 4 + 3) = 32 Then CodedArray (I * 4 + 3) = 96 Next I ByteArrayToString(CodedArray, OutString)
'Replace characters that cannot be sent in XML 'OutString = FilterRtfToXml(OutString)
EncodeString = OutString End Function
Private Sub StringToByteArray(ByVal StringIn As String, ByVal ByteArray() As Byte) Dim lBytes As Long
If Len(StringIn) = 0 Then Exit Sub
lBytes = Len(StringIn) ReDim ByteArray(lBytes - 1)
MoveMemory(ByteArray(0), StringIn, lBytes) End Sub Private Sub ByteArrayToString(ByVal ByteArray() As Byte, ByVal StringOut As String) Dim lBytes As Long
If LBound(ByteArray) > 0 Then Exit Sub 'lBound MUST be 0 lBytes = UBound(ByteArray) + 1 StringOut = Convert.ToString(lBytes, 0) ReMoveMemory(StringOut, ByteArray(0), lBytes * 2) End Sub
End Module
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gavin |
last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other
groups in a hope to get a response from anyone.
Can any one tell me how to make my VB program read the Bios serial number...
|
by: Rubycon |
last post by:
Hi all,
can anybody tell me what he invalid parameter is in this code. When I
try to execute the mmioDescendParent I get a returncode 11, meaning
that an invalid parameter has been passed. I...
|
by: javaid iqbal |
last post by:
i want to use video.ocx for reading camera in my program. i was using it very
succesfully in VB 6.0. Can some body guide me how to use it in CSharp.
Thanks in Advance.
|
by: Shayne H |
last post by:
I cannot get the following function to work. A System.NullReferenceError
exception occurs when CopyMemory is executed. However, during debug I found
that none of the parameters passed are Null.
Is...
|
by: Mike Loux |
last post by:
Howdy, all.
I am currently looking for a way to, using VB.NET, get around those
annoying little "Allow Access for X Minutes" dialogs that pop up in
Outlook 2003, without resorting to 3rd party...
|
by: Dennis |
last post by:
I am trying to use CopyMemory to copy arrays as follows:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal
pDst As Long, ByVal pSrc As Long, ByVal ByteLen As Integer)
...
|
by: Henrik |
last post by:
I'm sorry to trouble you once again but somebody must know how to get
a list of the desktop icons and their respective positions.
I know that I have to look into shell but I have no idea how to...
|
by: Jason Who |
last post by:
I need to make a quick raw copy of a large block of data from one pointer to
another.
Marshal.Copy let me copy from pointer to array and another call can take it
from aray to pointer. That is...
|
by: betygs |
last post by:
Hi all, I´m not speak english so well, but i'll try to do it better. I have a problem with the filecopy function when i use the IP instead of a computer name. For example
This sentence works ok...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |