convert c++ to vba

Felga

New Member
Joined
Dec 11, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
can anyone help me convert this code to vba ? zenit polar

char[] zenit = { 'z', 'e', 'n','i','t' };
char[] polar = { 'p', 'o', 'l', 'a', 'r' };

Console.WriteLine("Digite uma frase para ser Criptografada (zenit polar):");
string txt = Console.ReadLine();
txt = txt.ToLower();
char[] letra = txt.ToCharArray();


Console.WriteLine("Sua frase criptografada fica: ");


for (int i = 0; i < txt.Length; i++)
{
for (int x = 0; x < zenit.Length; x++)
{
if (letra == zenit[x])
letra = polar[x];
else if (letra == polar[x])
letra = zenit[x];
}
Console.Write(letra);
}


Console.WriteLine("\n" + "Sua frase Descriptografada: ");
for (int i = 0; i < txt.Length; i++)
{
for (int x = 0; x < zenit.Length; x++)
{
if (letra == zenit[x])
letra = polar[x];
else if (letra == polar[x])
letra = zenit[x];
}
Console.Write(letra);
}
Console.ReadKey();
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows
Hi @Felga, welcome to MrExcel.

How about ...
VBA Code:
Sub ZenitPolar()

    Dim arrZenit    As Variant
    Dim arrPolar    As Variant
    Dim arrLetra()  As String
    Dim sInput      As String
    Dim sOutput     As String
    Dim i           As Long
    Dim x           As Long
    Dim a           As Long

    arrZenit = Array("z", "e", "n", "i", "t")
    arrPolar = Array("p", "o", "l", "a", "r")

    sInput = Application.InputBox("Digite uma frase para ser Criptografada (zenit polar):", Type:=2)

    arrLetra = Split(StrConv(sInput, vbUnicode), Chr$(0))
    ReDim Preserve arrLetra(UBound(arrLetra) - 1)

    If Len(sInput) >= 1 Then
        For a = 1 To 2
            For i = 0 To Len(sInput) - 1
                For x = 0 To UBound(arrZenit)
                    If arrLetra(i) = arrZenit(x) Then
                        arrLetra(i) = arrPolar(x)
                    ElseIf arrLetra(i) = arrPolar(x) Then
                        arrLetra(i) = arrZenit(x)
                    End If
                Next x
            Next i
            If a = 1 Then
                MsgBox "Sua frase criptografada fica:" & vbNewLine & Join(arrLetra, "")
            Else
                MsgBox "Sua frase Descriptografada:" & vbNewLine & Join(arrLetra, "")
            End If
        Next a
    End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,130,186
Messages
5,640,688
Members
417,161
Latest member
Devon150

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top