Home All Groups Group Topic Archive Search About

convert text to decimal

Author
25 Oct 2006 8:16 PM
xla76
Hi all,

I am trying to follow some instructions for setting a password for VNC.
unfortunately I get stuck at the first hurdle:
''DecimalPassword = your password converted to decimal, separated by
spaces. ie "255 255 255"'

How do I do that? I tried double.parse with no luck.

Thanks

Pete

Author
25 Oct 2006 8:48 PM
Theo Verweij
You mean something like this:

     Private Function Pwd2Dec(ByVal Pwd As String) As String
         Dim MyPwd() As Char
         Dim DecPwd As New System.Text.StringBuilder

         MyPwd = Pwd.ToCharArray()
         For i As Integer = 0 To MyPwd.GetUpperBound(0)
             DecPwd.Append(Asc(MyPwd(i)).ToString & " ")
         Next
         Return DecPwd.ToString
     End Function

     Private Function Dec2Pwd(ByVal DecPwd As String) As String
         Dim MyDec() As String = Split(DecPwd, " ")
         Dim Pwd As New System.Text.StringBuilder

         For i As Integer = 0 To MyDec.GetUpperBound(0)
             'used cint(val(..)) instead of cint because it won't give a
type mismatch when the string isn't numeric
             Pwd.Append(Chr(CInt(Val(MyDec(i)))))
         Next
         Return Pwd.ToString
     End Function


xla76 wrote:
Show quoteHide quote
> Hi all,
>
> I am trying to follow some instructions for setting a password for VNC.
> unfortunately I get stuck at the first hurdle:
> ''DecimalPassword = your password converted to decimal, separated by
> spaces. ie "255 255 255"'
>
> How do I do that? I tried double.parse with no luck.
>
> Thanks
>
> Pete
>
Author
25 Oct 2006 8:51 PM
Tim Patrick
I'm not sure what VNC is looking for, but I might guess that they want the
ASCII value of each character in the password. Try this code.

   Dim password As String
   Dim decimalPassword As String = ""
   Dim counter As Integer

   ' ----- Get the password itself, somehow.
   password = PromptUserForPassword()

   ' ----- Convert to decimal form.
   For counter = 0 to password.Length - 1
      If (counter > 0) Then decimalPassword &= " "
      decimalPassword &= CStr(Asc(password.Substring(counter, 1)))
   Next counter

-----
Tim Patrick
Start-to-Finish Visual Basic 2005

Show quoteHide quote
> Hi all,
>
> I am trying to follow some instructions for setting a password for
> VNC.
> unfortunately I get stuck at the first hurdle:
> ''DecimalPassword = your password converted to decimal, separated by
> spaces. ie "255 255 255"'
> How do I do that? I tried double.parse with no luck.
>
> Thanks
>
> Pete
>
Author
27 Oct 2006 5:31 AM
xla76
Thanks guys, - spot on.