Deon

Deon

  • NA
  • 1
  • 0

Code Convert from VB.net to C#

Jul 1 2010 2:46 AM
Hi Guys

I'm having problems converting this code below from vb.net to c# can someone please help ??

 Public Function CryptData(ByVal Text As String) As String

        Dim strTempChar As String
        Dim i As Integer

        For i = 1 To Len(Text)

            If Asc(Mid$(Text, i, 1)) < 128 Then
                strTempChar = CType(Asc(Mid$(Text, i, 1)) + 128, String)
            ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
                strTempChar = CType(Asc(Mid$(Text, i, 1)) - 128, String)
            End If

            Mid$(Text, i, 1) = Chr(CType(strTempChar, Integer))

        Next i

        Return Text

    End Function


This is the code after I convert it to C#

public string CryptData(string Text)
        {
            string strTempChar = null;
            int i = 0;

            for (i = 1; i <= Len(Text); i++)
            {
                if (Asc(Mid(Text, i, 1)) < 128)
                {
                    strTempChar = Convert.ToString(Asc(Mid(Text, i, 1)) + 128);
                }
                else if (Asc(Mid(Text, i, 1)) > 128)
                {
                    strTempChar = Convert.ToString(Asc(Mid(Text, i, 1)) - 128);
                }

                Mid(Text, i, 1) == Chr(Convert.ToInt32(strTempChar));
            }

        }


The application is giving loads of errors like

Error    1    The name 'Len' does not exist in the current context  
Error    2    The name 'Asc' does not exist in the current context
Error    3    The name 'Mid' does not exist in the current context   


Can someone please help me ???

Regards

VX

Answers (2)