首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

给解决停:想做一个ASCII转换程序

2014-01-15 
给解决下:想做一个ASCII转换程序想做一个ASCII转换程序在Text1中输入一组任意的字符,在Text2将其转化为十

给解决下:想做一个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

[解决办法]
Text1 输入字母,符号没有问题。

什么叫“当输入9时出现49,应该是58的”?你的需求能不能说清楚一点儿?

照你原来的叙述,应该与它在字符串中的位置有关。"9" 的 ASCII 码是 57,如果处于字符串的第二个字符,编码是 58。
[解决办法]
我试了,Text1 可以输入任何字符,包括汉字。

热点排行