Changing the base of a string in VB.NET 
Author Message
 Changing the base of a string in VB.NET

They have something like this in VB6:

Dim s As String
Dim buffer(5) As Byte
buffer(0) = 116 'char for t
buffer(1) = 101 'char for e
buffer(2) = 115 'char for s
buffer(3) = 116 'char for t
buffer(4) = 50  'char for 2
s = buffer      'gives a result of "??2"

I want to get exactly the same result for string s in
VB.Net but I don't know what conversion (encoding) to use
to satisfy that last line. The VB.Net upgrade wizard gives
me a line like this:

Dim s As String
Dim buffer(5) As Byte
buffer(0) = 116 'char for t
buffer(1) = 101 'char for e
buffer(2) = 115 'char for s
buffer(3) = 116 'char for t
buffer(4) = 50  'char for 2
s= System.Text.UnicodeEncoding.Unicode.GetString(buffer)

which doesn't work. Please help.

Sincerely,
Samuel



Wed, 25 Feb 2004 03:26:36 GMT  
 Changing the base of a string in VB.NET
Unicode is two bytes per character, but you are only providing on.  
Try:

s= System.Text.ASCIIEncoding.ASCII.GetString(buffer)

As your last line.



Quote:
> I want to get exactly the same result for string s in
> VB.Net but I don't know what conversion (encoding) to use
> to satisfy that last line. The VB.Net upgrade wizard gives
> me a line like this:

> Dim s As String
> Dim buffer(5) As Byte
> buffer(0) = 116 'char for t
> buffer(1) = 101 'char for e
> buffer(2) = 115 'char for s
> buffer(3) = 116 'char for t
> buffer(4) = 50  'char for 2
> s= System.Text.UnicodeEncoding.Unicode.GetString(buffer)

> which doesn't work. Please help.

> Sincerely,
> Samuel

Tim


Wed, 25 Feb 2004 13:51:16 GMT  
 Changing the base of a string in VB.NET
Yes, I understand what you mean. And I already tried the
line that you gave. But what I want the code to do is the
line in VB6 gives that gives result as "??2". I want the
result to be "??2" or something similar to that. If I use
the line that you gave, it gives a result of "test2"
(which is not what I want). I have already tried
movememory too. It did not work. Please advise and help.

Thanks so much
Samuel

Quote:
>-----Original Message-----
>Unicode is two bytes per character, but you are only
providing on.  
>Try:

>s= System.Text.ASCIIEncoding.ASCII.GetString(buffer)

>As your last line.

>In article <174b401c137d3$02bea440


Quote:

>> I want to get exactly the same result for string s in
>> VB.Net but I don't know what conversion (encoding) to
use
>> to satisfy that last line. The VB.Net upgrade wizard
gives
>> me a line like this:

>> Dim s As String
>> Dim buffer(5) As Byte
>> buffer(0) = 116 'char for t
>> buffer(1) = 101 'char for e
>> buffer(2) = 115 'char for s
>> buffer(3) = 116 'char for t
>> buffer(4) = 50  'char for 2
>> s= System.Text.UnicodeEncoding.Unicode.GetString(buffer)

>> which doesn't work. Please help.

>> Sincerely,
>> Samuel

>Tim
>.



Wed, 25 Feb 2004 17:43:16 GMT  
 Changing the base of a string in VB.NET
Actually, the thing here is that you are trying to create a non-Unicode
string. The fact that it displays as "??2" is a side effect of limitations
in the VB IDE itself, it does not mean you need to expect the same
limitation in future versions?

In other words, keep your eye on the ball and look for the proper technical
result, not for the side effect of a particular version's implementation?

--
MichKa

the only book on internationalization in VB at
http://www.i18nWithVB.com/


Quote:
> Yes, I understand what you mean. And I already tried the
> line that you gave. But what I want the code to do is the
> line in VB6 gives that gives result as "??2". I want the
> result to be "??2" or something similar to that. If I use
> the line that you gave, it gives a result of "test2"
> (which is not what I want). I have already tried
> movememory too. It did not work. Please advise and help.

> Thanks so much
> Samuel

> >-----Original Message-----
> >Unicode is two bytes per character, but you are only
> providing on.
> >Try:

> >s= System.Text.ASCIIEncoding.ASCII.GetString(buffer)

> >As your last line.

> >In article <174b401c137d3$02bea440


> >> I want to get exactly the same result for string s in
> >> VB.Net but I don't know what conversion (encoding) to
> use
> >> to satisfy that last line. The VB.Net upgrade wizard
> gives
> >> me a line like this:

> >> Dim s As String
> >> Dim buffer(5) As Byte
> >> buffer(0) = 116 'char for t
> >> buffer(1) = 101 'char for e
> >> buffer(2) = 115 'char for s
> >> buffer(3) = 116 'char for t
> >> buffer(4) = 50  'char for 2
> >> s= System.Text.UnicodeEncoding.Unicode.GetString(buffer)

> >> which doesn't work. Please help.

> >> Sincerely,
> >> Samuel

> >Tim
> >.



Wed, 25 Feb 2004 18:22:55 GMT  
 Changing the base of a string in VB.NET
Yes, I do understand that I'm not trying to create "??2"
string in my program. But what I am trying to do is to get
a string value that is exactly the same value as that "??
2" (it might display some funny character but the most
important one is the exact same of value). I tried the
Unicode System Encoding (System.Text.UnicodeEncoding), but
when I try to send that string to capicom.dll function
(which is used in signing/verifying signature), it does
not verify the string like it should with the old VB6 (the
one with "??2"). Thanks so much for the reply. Please help.

Samuel

Quote:
>-----Original Message-----
>Actually, the thing here is that you are trying to create
a non-Unicode
>string. The fact that it displays as "??2" is a side

effect of limitations
Quote:
>in the VB IDE itself, it does not mean you need to expect
the same
>limitation in future versions?

>In other words, keep your eye on the ball and look for

the proper technical
Quote:
>result, not for the side effect of a particular version's
implementation?

>--
>MichKa

>the only book on internationalization in VB at
>http://www.i18nWithVB.com/



>> Yes, I understand what you mean. And I already tried the
>> line that you gave. But what I want the code to do is
the
>> line in VB6 gives that gives result as "??2". I want the
>> result to be "??2" or something similar to that. If I
use
>> the line that you gave, it gives a result of "test2"
>> (which is not what I want). I have already tried
>> movememory too. It did not work. Please advise and help.

>> Thanks so much
>> Samuel

>> >-----Original Message-----
>> >Unicode is two bytes per character, but you are only
>> providing on.
>> >Try:

>> >s= System.Text.ASCIIEncoding.ASCII.GetString(buffer)

>> >As your last line.

>> >In article <174b401c137d3$02bea440


>> >> I want to get exactly the same result for string s in
>> >> VB.Net but I don't know what conversion (encoding) to
>> use
>> >> to satisfy that last line. The VB.Net upgrade wizard
>> gives
>> >> me a line like this:

>> >> Dim s As String
>> >> Dim buffer(5) As Byte
>> >> buffer(0) = 116 'char for t
>> >> buffer(1) = 101 'char for e
>> >> buffer(2) = 115 'char for s
>> >> buffer(3) = 116 'char for t
>> >> buffer(4) = 50  'char for 2
>> >> s= System.Text.UnicodeEncoding.Unicode.GetString
(buffer)

>> >> which doesn't work. Please help.

>> >> Sincerely,
>> >> Samuel

>> >Tim
>> >.

>.



Fri, 27 Feb 2004 11:29:01 GMT  
 Changing the base of a string in VB.NET
If you make sure that the API uses an ANSI declare, then the conversion will
happen, no need to any extra conversion.

--
MichKa

the only book on internationalization in VB at
http://www.i18nWithVB.com/


Quote:
> Yes, I do understand that I'm not trying to create "??2"
> string in my program. But what I am trying to do is to get
> a string value that is exactly the same value as that "??
> 2" (it might display some funny character but the most
> important one is the exact same of value). I tried the
> Unicode System Encoding (System.Text.UnicodeEncoding), but
> when I try to send that string to capicom.dll function
> (which is used in signing/verifying signature), it does
> not verify the string like it should with the old VB6 (the
> one with "??2"). Thanks so much for the reply. Please help.

> Samuel
> >-----Original Message-----
> >Actually, the thing here is that you are trying to create
> a non-Unicode
> >string. The fact that it displays as "??2" is a side
> effect of limitations
> >in the VB IDE itself, it does not mean you need to expect
> the same
> >limitation in future versions?

> >In other words, keep your eye on the ball and look for
> the proper technical
> >result, not for the side effect of a particular version's
> implementation?

> >--
> >MichKa

> >the only book on internationalization in VB at
> >http://www.i18nWithVB.com/



> >> Yes, I understand what you mean. And I already tried the
> >> line that you gave. But what I want the code to do is
> the
> >> line in VB6 gives that gives result as "??2". I want the
> >> result to be "??2" or something similar to that. If I
> use
> >> the line that you gave, it gives a result of "test2"
> >> (which is not what I want). I have already tried
> >> movememory too. It did not work. Please advise and help.

> >> Thanks so much
> >> Samuel

> >> >-----Original Message-----
> >> >Unicode is two bytes per character, but you are only
> >> providing on.
> >> >Try:

> >> >s= System.Text.ASCIIEncoding.ASCII.GetString(buffer)

> >> >As your last line.

> >> >In article <174b401c137d3$02bea440


> >> >> I want to get exactly the same result for string s in
> >> >> VB.Net but I don't know what conversion (encoding) to
> >> use
> >> >> to satisfy that last line. The VB.Net upgrade wizard
> >> gives
> >> >> me a line like this:

> >> >> Dim s As String
> >> >> Dim buffer(5) As Byte
> >> >> buffer(0) = 116 'char for t
> >> >> buffer(1) = 101 'char for e
> >> >> buffer(2) = 115 'char for s
> >> >> buffer(3) = 116 'char for t
> >> >> buffer(4) = 50  'char for 2
> >> >> s= System.Text.UnicodeEncoding.Unicode.GetString
> (buffer)

> >> >> which doesn't work. Please help.

> >> >> Sincerely,
> >> >> Samuel

> >> >Tim
> >> >.

> >.



Fri, 27 Feb 2004 11:58:10 GMT  
 Changing the base of a string in VB.NET
Have you got any code for example?

Thanks so much.

Samuel



Sat, 28 Feb 2004 07:16:15 GMT  
 Changing the base of a string in VB.NET
What API are you calling? If you name the API, I can give you the declare
that will give you the behavior you want.

--
MichKa

Michael Kaplan
(principal developer of the MSLU)
Trigeminal Software, Inc.  -- http://www.trigeminal.com/
the book -- http://www.i18nWithVB.com/


Quote:
> Have you got any code for example?

> Thanks so much.

> Samuel



Sat, 28 Feb 2004 07:50:10 GMT  
 Changing the base of a string in VB.NET
I don't think I use any Windows API. If the one used for
signing and verifying signatures is the one that you
asked, it is capicom.dll which is described on this
following page :
http://discuss.microsoft.com/archives/capicom.html
This file is used for encryption, signatures. I think it
is distributed as .dll or .zip. For download of the dll it
is here : http://www.microsoft.com/downloads/release.asp?
releaseid=30316 .

Thanks so much.

Samuel



Sat, 28 Feb 2004 13:27:45 GMT  
 Changing the base of a string in VB.NET
So you will not post the lines of VB6 code that use this string you convert?
That is what I am asking for.

Believe it or not, I was not looking for a homweork assignment where I would
track down that info myself. :-)

--
MichKa

Michael Kaplan
(principal developer of the MSLU)
Trigeminal Software, Inc.  -- http://www.trigeminal.com/
the book -- http://www.i18nWithVB.com/


Quote:
> I don't think I use any Windows API. If the one used for
> signing and verifying signatures is the one that you
> asked, it is capicom.dll which is described on this
> following page :
> http://discuss.microsoft.com/archives/capicom.html
> This file is used for encryption, signatures. I think it
> is distributed as .dll or .zip. For download of the dll it
> is here : http://www.microsoft.com/downloads/release.asp?
> releaseid=30316 .

> Thanks so much.

> Samuel



Sat, 28 Feb 2004 13:38:27 GMT  
 Changing the base of a string in VB.NET
Sorry, that's not what I mean. I'll post it. The part
about the string conversion is under the
function "LoadFile". It is being called by another sub
called "RecurseSig1". That sub is called when we try to
verify a signature.

Here it is in VB.Net: (provided capicom.dll is already
included as a reference)

'this function is later called when loading a file is done
(loading the file is the one that has the string
conversion).
Private Function RecurseSig1(ByVal inode As
System.Windows.Forms.TreeNode, ByVal p7 As String) As
Boolean
        On Error Goto Err_Fn
        Dim i As Integer
        Dim tvNode As System.Windows.Forms.TreeNode
        Dim ch As New CAPICOM.Chain()
        Dim cer As CAPICOM.Certificate
        Dim signer As CAPICOM.Signer
        Dim sd As New CAPICOM.SignedData()
        Dim retval As Boolean

'Following is the line that verifies the string        
sd.Verify(p7, False,
CAPICOM.CAPICOM_SIGNED_DATA_VERIFY_FLAG.CAPICOM_VERIFY_SIGN
ATURE_AND_CERTIFICATE)
   Exit Function
End Function

Private Function LoadFile(ByVal filename As String) As
String
        FileOpen(1, filename, OpenMode.Binary)
        Dim buffer(LOF(1) - 1) As Byte
        FileGet(1, buffer)
        LoadFile =
System.Text.UnicodeEncoding.Unicode.GetString(buffer)
        FileClose(1)
End Function

So after the function calls LoadFile, it calls RecurseSig1
by passing the string p7 (which is the converted string
from binary). Structure in VB6 is exactly the same. It's
just the string conversion line from byte array is
just "LoadFile = buffer".

Sincerely,
Samuel =)



Sun, 29 Feb 2004 08:07:40 GMT  
 Changing the base of a string in VB.NET
Sorry, that's not what I mean. I'll post it. The part
about the string conversion is under the
function "LoadFile". It is being called by another sub
called "RecurseSig1". That sub is called when we try to
verify a signature.

Here it is in VB.Net: (provided capicom.dll is already
included as a reference)

'this function is later called when loading a file is done
(loading the file is the one that has the string
conversion).
Private Function RecurseSig1(ByVal inode As
System.Windows.Forms.TreeNode, ByVal p7 As String) As
Boolean
        On Error Goto Err_Fn
        Dim i As Integer
        Dim tvNode As System.Windows.Forms.TreeNode
        Dim ch As New CAPICOM.Chain()
        Dim cer As CAPICOM.Certificate
        Dim signer As CAPICOM.Signer
        Dim sd As New CAPICOM.SignedData()
        Dim retval As Boolean

'Following is the line that verifies the string        
sd.Verify(p7, False,
CAPICOM.CAPICOM_SIGNED_DATA_VERIFY_FLAG.CAPICOM_VERIFY_SIGN
ATURE_AND_CERTIFICATE)
   Exit Function
End Function

Private Function LoadFile(ByVal filename As String) As
String
        FileOpen(1, filename, OpenMode.Binary)
        Dim buffer(LOF(1) - 1) As Byte
        FileGet(1, buffer)
        LoadFile =
System.Text.UnicodeEncoding.Unicode.GetString(buffer)
        FileClose(1)
End Function

So after the function calls LoadFile, it calls RecurseSig1
by passing the string p7 (which is the converted string
from binary). Structure in VB6 is exactly the same. It's
just the string conversion line from byte array is
just "LoadFile = buffer".

Sincerely,
Samuel =)



Sun, 29 Feb 2004 08:07:26 GMT  
 Changing the base of a string in VB.NET
Ok, the central problem here is that it is time for a change! In VB.Net you
can read and write files in ANY encoding; the need to write files as binary
and convert them later is over.

The most important issue with working round product limitations is that when
they FIX the limitations, you really have to remove the workarounds (since
they often break, as they do here).

--
MichKa

Michael Kaplan
(principal developer of the MSLU)
Trigeminal Software, Inc.  -- http://www.trigeminal.com/
the book -- http://www.i18nWithVB.com/


Quote:
> Sorry, that's not what I mean. I'll post it. The part
> about the string conversion is under the
> function "LoadFile". It is being called by another sub
> called "RecurseSig1". That sub is called when we try to
> verify a signature.

> Here it is in VB.Net: (provided capicom.dll is already
> included as a reference)

> 'this function is later called when loading a file is done
> (loading the file is the one that has the string
> conversion).
> Private Function RecurseSig1(ByVal inode As
> System.Windows.Forms.TreeNode, ByVal p7 As String) As
> Boolean
>         On Error Goto Err_Fn
>         Dim i As Integer
>         Dim tvNode As System.Windows.Forms.TreeNode
>         Dim ch As New CAPICOM.Chain()
>         Dim cer As CAPICOM.Certificate
>         Dim signer As CAPICOM.Signer
>         Dim sd As New CAPICOM.SignedData()
>         Dim retval As Boolean

> 'Following is the line that verifies the string
> sd.Verify(p7, False,
> CAPICOM.CAPICOM_SIGNED_DATA_VERIFY_FLAG.CAPICOM_VERIFY_SIGN
> ATURE_AND_CERTIFICATE)
>    Exit Function
> End Function

> Private Function LoadFile(ByVal filename As String) As
> String
>         FileOpen(1, filename, OpenMode.Binary)
>         Dim buffer(LOF(1) - 1) As Byte
>         FileGet(1, buffer)
>         LoadFile =
> System.Text.UnicodeEncoding.Unicode.GetString(buffer)
>         FileClose(1)
> End Function

> So after the function calls LoadFile, it calls RecurseSig1
> by passing the string p7 (which is the converted string
> from binary). Structure in VB6 is exactly the same. It's
> just the string conversion line from byte array is
> just "LoadFile = buffer".

> Sincerely,
> Samuel =)



Sun, 29 Feb 2004 10:22:34 GMT  
 Changing the base of a string in VB.NET
I'm sorry to be so dumb, but could you show me a code
example of writing/reading using that certain encoding
that you mentioned earlier? That would be a great help.
Thanks.

Samuel



Tue, 02 Mar 2004 11:49:24 GMT  
 Changing the base of a string in VB.NET
Which encoding are you looking for, though?

--
MichKa

Michael Kaplan
(principal developer of the MSLU)
Trigeminal Software, Inc.  -- http://www.trigeminal.com/
the book -- http://www.i18nWithVB.com/


Quote:
> I'm sorry to be so dumb, but could you show me a code
> example of writing/reading using that certain encoding
> that you mentioned earlier? That would be a great help.
> Thanks.

> Samuel



Tue, 02 Mar 2004 13:02:08 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. Crystal Report .Net Web Service ( Invalid length for a Base-64 string )

2. Change to ASP.NET and VB.NET

3. Change to ASP.NET and VB.NET

4. Crystal Reports from ASP.NET without compiling VB.NET on SQL/ADO changes

5. VB.NET application and CR.NET - Change grouping method at runtime

6. calling base class function in VB.NET

7. Implementing events from a base class in VB.NET

8. Report based on VB.NET app data

9. VB.NET SubReport based on datasets

10. Changing SQL statement based on vb form data

11. SQL Base date vs VB Base date

12. Web based form feeding a vb data base

 

 
Powered by phpBB® Forum Software