给解决下:想做一个ASCII转换程序
想做一个ASCII转换程序
在Text1中输入一组任意的字符,在Text2将其转化为十进制ASCII码,但在显示的ASCII值是第一位转换的字符在输出的数据上+0第二位+1…………第N位加N-1
Dim i As Integer
Dim j As Integer
Dim X As Integer
Dim a As Double, t1 As String, t2 As String
Dim t4 As String, t5 As String, t6 As String, t7 As String
Private Sub Command1_Click()
If Text1 <> "" Then
Timer1.Enabled = True
Else
MsgBox "请输入内容!", 48, "提示"
End If
End Sub
Private Sub Command2_Click()
If Text2 <> "" Then
Timer2.Enabled = True
Else
MsgBox "请输入内容!", 48, "提示"
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 10 '设置转化每个数据的时间
Timer2.Enabled = False
Timer2.Interval = 10 '设置还原每个数据的时间
X = 0
End Sub
Private Sub Timer1_Timer()
t1 = Text1.Text
t2 = Text2.Text
t3 = Text3.Text
t4 = Text4.Text
'For j = 0 To 9
Text3.Text = Asc(Mid(Text1.Text, Len(Text1.Text) - i, 1) + 1)
Text2.Text = Text3 + "," + Text2
i = i + 1
If i >= Len(Text1.Text) Then
Timer1.Enabled = False
End If
'Next j
End Sub
Private Sub Timer2_Timer()
X = X + 1
a = Split(Text2.Text, ",")
Text3 = Chr(a(X))
Text4 = Text4 + Text3 '这里如果text4=text4+text3就会倒着输出
If X >= Len(Text1) Then
Timer2.Enabled = False
End If
End Sub
[解决办法]
Option Explicit
Dim i As Integer
Dim X As Integer
Dim a() As String
Dim t1 As String, t2 As String, t3 As String, t4 As String
Private Sub Command1_Click()
If Text1 <> "" Then
i = 0
Text2 = ""
Timer1.Enabled = True
Else
MsgBox "请输入内容!", 48, "提示"
End If
End Sub
Private Sub Command2_Click()
If Text2 <> "" Then
X = 0
Text4 = ""
Timer2.Enabled = True
Else
MsgBox "请输入内容!", 48, "提示"
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 10
Timer2.Enabled = False
Timer2.Interval = 10
End Sub
Private Sub Timer1_Timer()
t1 = Text1.Text
t2 = Text2.Text
t3 = Text3.Text
t4 = Text4.Text
Text3.Text = Asc(Mid(Text1.Text, Len(Text1.Text) - i, 1)) + Len(Text1.Text) - i - 1
Text2.Text = Text3 + "," + Text2
i = i + 1
If i >= Len(Text1.Text) Then
Timer1.Enabled = False
End If
End Sub
Private Sub Timer2_Timer()
a = Split(Text2.Text, ",")
Text3 = Chr(Val(a(X)) - X)
Text4 = Text4 + Text3
X = X + 1
If X >= Len(Text1) Then
Timer2.Enabled = False
End If
End Sub