Private Sub Command1_Click()
Dim xalphabets(26) As String
Dim dalphabets(26) As String
Dim i As Integer
Dim text As String
Dim total As Integer
Dim word As String
Dim k As Integer
Dim ascword As Integer
Dim numberword As Integer
Dim examine As Integer
password = ""
text = Text1.text
total = Len(text)
For i = 1 To 26
    xalphabets(i) = Chr(i + 96)
    dalphabets(i) = Chr(i + 64)
Next i
text = Text1
total = Len(text)
For i = 1 To total
    word = Mid(text, i, 1)
    k = i Mod 5
    ascword = Asc(word)
    If k = 0 Then
        k = 5
    End If
    If IsNumeric(word) Then
        numberword = Val(word)
        numberword = (numberword + k)
        If numberword > 9 Then
            numberword = numberword - 10
        End If
        password = password & numberword
    ElseIf ascword >= 97 And ascword <= 127 Then
        For examine = 1 To 26
            If xalphabets(examine) = word Then
                Exit For
            End If
        Next examine
        examine = examine + k
        If examine > 26 Then
            examine = examine - 26
        End If
        password = password & xalphabets(examine)
    ElseIf ascword >= 65 And ascword <= 90 Then
        For examine = 1 To 26
            If dalphabets(examine) = word Then
                Exit For
            End If
        Next examine
        examine = examine + k
        If examine > 26 Then
            examine = examine - 26
        End If
        password = password & dalphabets(examine)
    Else
        password = password & word
    End If
Next i
Text2 = StrReverse(password)
End SubPrivate Sub Command2_Click()                   '清空
Text1 = ""
Text2 = ""
password = ""
End SubPrivate Sub Text1_Change()                     '使流动条处在最下方
    Text1.SelStart = Len(Text1.text)
End SubPrivate Sub Text2_Change()
    Text1.SelStart = Len(Text1.text)
End Sub

解决方案 »

  1.   

    1.这应该是一个窗口中部分控件的事件代码,两个文本输入框text1、text2,一个按钮command1。
    2.command1按钮的单击事件使用了外部变量,如password,并且感觉代码有些问题,如这句text = Text1,VB代码编译或许通不过;
    3.代码很简单,给出Command1_Click()的变量声明部分:
    var
     xalphabets,dalphabets : string[26];
     i, k, ascword, numberword, examine: integer;
     text,word: string;4.注意的地方:
     与VB的循环有区别,如VB语法:For i = 1 To 26 
    改成Delphi为:  For i := 0 To 25 do
    delhi默认的数组下标起点为0,除非声明时指定了下标起始。
      

  2.   

    //Private Sub Command1_Click() 
    procedure TForm1.Button1Click(Sender: TObject);//按钮事件,TButton代替VB的CommandButton
    var //定义变量
      //Dim xalphabets(26) As String 
      xalphabets: array [0..26] of String;
      //Dim dalphabets(26) As String 
      dalphabets: array [0..26] of String;
      //Dim i As Integer 
      i: Integer;//虽然VB当中的Integer对应的不是Delphi的Integer,但是由于是循环计数,所以使用Integer
      //Dim text As String 
      text: WideString;//这里使用Unicode可以省去分字的麻烦(VB当中也是Unicode),但是需要注意后面的转换
      //Dim total As Integer 
      total: Integer;//这个也一样,并没有类型的限制,所以建议使用Integer更为保险
      //Dim word As String 
      _word: String;//word在delphi当中是一个系统类型,所以须有所改变
      //Dim k As Integer 
      k: Integer; //同上
      //Dim ascword As Integer 
      ascword: Word;//这个得注意类型了,虽然使用Integer不会有太多的问题
      
      //Dim numberword As Integer 
      numberword: Integer;
      //Dim examine As Integer 
      examine: Integer;
    begin
      //password = "" 
      password := '';
      //text = Text1.text 
      text := Edit1.Text;//用TEdit代替VB的TextBox,把AnsiString转为WideString
      //total = Len(text) 
      total := Length(Text);//以Unicode字符计数
      //For i = 1 To 26 
      for i := 1 to 26 do begin
        //xalphabets(i) = Chr(i + 96) 
        xalphabets[i] := chr(i + 96); //小写字母
        //dalphabets(i) = Chr(i + 64) 
        dalphabets[i] := chr(i + 64); //大写字母
      //Next i 
      end;  //text = Text1 
      //total = Len(text) 
      //这两行代码上面已经有了,属于重复的  //For i = 1 To total 
      for i := 1 to total do begin
        //word = Mid(text, i, 1) 
        _word := Text[i]; //取第I个字符(Unicode),赋值给_Word变成ANSI Code
        //k = i Mod 5 
        k := i mod 5;
        //ascword = Asc(word) 
        ascword := Ord(_word);//取ASCII码值
        //If k = 0 Then 
        if k = 0 then begin
            //k = 5 
          k := 5;
        //End If 
        end;    //If IsNumeric(word) Then 
        if _word in ['0'..'9'] then begin //是否数字字符
            //numberword = Val(word) 
            numberword := IntToStr(_word);
            //numberword = (numberword + k) 
            Inc(numberword, k);
            //If numberword > 9 Then 
            if numberword > 9 then begin
                //numberword = numberword - 10 
                dec(numberword, 10);
            //End If 
            end;
            //password = password & numberword 
            password := password + IntToStr(numberword); 注意VB当中的 '&' 操作符,会对非字符类型进行隐含转换
        //ElseIf ascword >= 97 And ascword <= 127 Then 
        end else if (ascword >= 97) and (ascword <= 127 (*不知道这个是否应该是122*)) then begin
            //For examine = 1 To 26 
            for examine := 1 to 26 do begin
                //If xalphabets(examine) = word Then 
                if xalphabets[examine] = _word then begin
                    //Exit For 
                    break;
                //End If 
                end;
            //Next examine 
            end;        //examine = examine + k 
            Inc(examine, k); //在Delphi当中对于for循环的计数器使用是有限制的,所以这里面要用于examine,最好前面改为while,后续代码亦如此
            //If examine > 26 Then 
            if examine > 26 then begin
                //examine = examine - 26 
                dec(examine, 26);
            //End If 
            end;
            //password = password & xalphabets(examine) 
            password := password + xalphabets[examine];
        //ElseIf ascword >= 65 And ascword <= 90 Then 
        end else if (ascword >= 65) and (ascword <= 90) then begin
            //For examine = 1 To 26 
            for examine := 1 to 26 do begin
                //If dalphabets(examine) = word Then 
                if dalphabets[examine] = _word then begin
                    //Exit For 
                    break
                //End If 
                end;
            //Next examine 
            end;
            //examine = examine + k 
            inc(examine, k);
            //If examine > 26 Then 
            if examine > 26 then begin
                //examine = examine - 26 
                dec(examine , 26);
            //End If 
            end;
            //password = password & dalphabets(examine) 
            password := password + dalphabets[examine];
        //Else 
        end else begin
            //password = password & word 
            password := password + _word;
        //End If 
        end;
      //Next i 
      end;
      //Text2 = StrReverse(password) 
      //StrReverse是反串,即把字符串password当中的字符逆向排列,如'123',StrReverse之后就是'321'
      Edit2.Text := StrReverse(password);//TEdit代替VB的TextBox
    //End Sub 
    end;//Private Sub Command2_Click()                  '清空 
    procedure TForm1.Button2Click(Sender: TObject);//TButton代替VB的CommandButton
    begin
      //Text1 = "" 
      Edit1.Text := '';
      //Text2 = "" 
      Edit2.Text := '';
      //password = "" 
      password := '';
    //End Sub 
    end;//Private Sub Text1_Change()                    '使流动条处在最下方 
    procedure TForm1.Edit1Change(Sender: TObject);//Edit1的OnChange事件
    begin
        //Text1.SelStart = Len(Text1.text) 
        Edit1.SelStart := Length(Edit1.Text);
    //End Sub 
    end;//Private Sub Text2_Change() 
    procedure TForm1.Edit2Change(Sender: TObject);//Edit2的OnChange事件
    begin
        //Text1.SelStart = Len(Text1.text) 
        Edit1.SelStart := Length(Edit1.Text);//这里估计是代码写错了,是Edit2而不是Edit1
    //End Sub
    end;
      

  3.   

    2.Password是一个全局变量,或者称之为窗体的类变量,VB允许Text = Text1,相当于Text = Text1.Text
    3.xalphabets,dalphabets : string[26]; 这个理解是不对的,除非VB代码为xalphabets: string(26)...
    4.Delphi使用 for i := 1 to 26并无不可.VB当中也是以0为起始下标的.只是为了方便,原代码当中忽略了一个元素的利用.