当前位置:编程学习 > VB >>

跪求VB代码解释

帮小弟解决下代码问题...
Private Sub Command1_Click()
Dim lngReturn As Long
If Name_Do(Val(Len(Text1) + Len(Text2))) > 0 Then
MsgBox "请输入汉字!", , "提示"
Exit Sub
Else
If Text1 = "" And Text2 = "" Then
MsgBox "请输入名字!", , "提示"
Exit Sub
End If
c = "[" & Text1 & "]" & "向" & "[" & Text2 & "]"
d = "[" & Text2 & "]" & "向" & "[" & Text1 & "]"
For i = 1 To Len(Trim(Text1))
lngReturn = CLng("&h" & Hex((AscW(Mid(Text1, i, 1)))))
If i = 1 Then
Text4(0).Text = Mid(lngReturn, 1, 3)
Text4(1).Text = Val(Mid(lngReturn, 3, 2) + 30)
Text4(4).Text = Val(Mid(lngReturn, 2, 2) + 50)
End If
If i = 2 Then
Text4(2).Text = Val(Mid(lngReturn, 1, 2) + 30)
Text4(3).Text = Val(Mid(lngReturn, 2, 2) + 40)
End If
Next i
For i = 1 To Len(Trim(Text2))
lngReturn = CLng("&h" & Hex((AscW(Mid(Text2, i, 1)))))
If i = 1 Then
Text5(0).Text = Mid(lngReturn, 1, 3)
Text5(1).Text = Val(Mid(lngReturn, 3, 2) + 30)
Text5(4).Text = Val(Mid(lngReturn, 2, 2) + 50)
End If
If i = 2 Then
Text5(2).Text = Val(Mid(lngReturn, 1, 2) + 30)
Text5(3).Text = Val(Mid(lngReturn, 2, 2) + 40)
End If
Next i
Text4(5).Text = Int(Rnd * 100)
Text5(5).Text = Int(Rnd * 100)
Call sx(0, 0, 0)
Text3.Text = "名字PK," & Label11 & vbCrLf & vbCrLf
Text3.Text = Text3.Text + Text1 & " " & "HP:" & Text4(0) & " " & "攻:" & Text4(1) & " " & "防:" & Text4(2) & " " & "速:" & Text4(3) & " " & "技:" & Text4(4) & " " & "运:" & Text4(5) & vbCrLf
Text3.Text = Text3.Text + Text2 & " " & "HP:" & Text5(0) & " " & "攻:" & Text5(1) & " " & "防:" & Text5(2) & " " & "速:" & Text5(3) & " " & "技:" & Text5(4) & " " & "运:" & Text5(5) & vbCrLf & vbCrLf
If Text4(5).Text > Text5(5).Text Then '战斗先机
Tur = 2
ElseIf Text4(5).Text < Text5(5).Text Then
Tur = 1
Else
MsgBox "运气都一样,在来一次!", , "提示"
Text4(5).Text = Int(Rnd * 100)
Text5(5).Text = Int(Rnd * 100)
End If
Timer1.Enabled = True
End If
End Sub
Private Sub Timer1_Timer()
a = Int(Rnd * 20)
b = Int(Rnd * 20)
If Text4(0) < 0 Then
Text4(0) = 0
Text3.Text = Text3.Text + "[" & Text1 & "]" & "被打败!"
Timer1.Enabled = False
Exit Sub
ElseIf Text5(0) < 0 Then
Text5(0) = 0
Text3.Text = Text3.Text + "[" & Text2 & "]" & "被打败!"
Timer1.Enabled = False
Exit Sub
ElseIf 10 > Text4(0) > 0 Then
f = Val(Int(Rnd * 10))
Text3.Text = Text3.Text + "[" & Text1 & "]" & "垂死挣扎,提升属性值" & f & "点"
Call sx(f, 0, 0)
ElseIf 10 > Text5(0) > 0 Then
f = Val(Int(Rnd * 10))
Text3.Text = Text3.Text + "[" & Text2 & "]" & "垂死挣扎,提升属性值" & f & "点"
Call sx(f, 0, 1)
Else
If Tur = 1 Then '战斗循环
Call Skill(0, 0, Tur)
Text3.Text = Text3.Text + d & e & vbCrLf
Tur = 2
Exit Sub
ElseIf Tur = 2 Then
Call Skill(0, 0, Tur)
Text3.Text = Text3.Text + c & e & vbCrLf
Tur = 1
Exit Sub
End If
End If
End Sub
答案:如果你全部都不懂话花就没有这个必要了




Private Sub Command1_Click()
Dim lngReturn As Long

'定义
If Name_Do(Val(Len(Text1) + Len(Text2))) > 0 Then '如果长度不符合
MsgBox "请输入汉字!", , "提示"
Exit Sub
'退出过程
Else
If Text1 = "" And Text2 = "" Then
'如果名字为空
MsgBox "请输入名字!", , "提示"




Exit Sub

'退出过程
End If
c = "[" & Text1 & "]" & "向" & "[" & Text2 & "]"

'赋值text1.text向text2.text,代表动作
d = "[" & Text2 & "]" & "向" & "[" & Text1 & "]"

'赋值
For i = 1 To Len(Trim(Text1))


'去掉名字里德空格
lngReturn = CLng("&h" & Hex((AscW(Mid(Text1, i, 1)))))
'返回text里16进制值,相当于通过名字给予属性
If i = 1 Then

Text4(0).Text = Mid(lngReturn, 1, 3)

Text4(1).Text = Val(Mid(lngReturn, 3, 2) + 30)
Text4(4).Text = Val(Mid(lngReturn, 2, 2) + 50)
End If
If i = 2 Then
Text4(2).Text = Val(Mid(lngReturn, 1, 2) + 30)
Text4(3).Text = Val(Mid(lngReturn, 2, 2) + 40)
End If
Next i
For i = 1 To Len(Trim(Text2))
lngReturn = CLng("&h" & Hex((AscW(Mid(Text2, i, 1)))))
If i = 1 Then
Text5(0).Text = Mid(lngReturn, 1, 3)
Text5(1).Text = Val(Mid(lngReturn, 3, 2) + 30)
Text5(4).Text = Val(Mid(lngReturn, 2, 2) + 50)
End If
If i = 2 Then
Text5(2).Text = Val(Mid(lngReturn, 1, 2) + 30)
Text5(3).Text = Val(Mid(lngReturn, 2, 2) + 40)
End If
Next i
Text4(5).Text = Int(Rnd * 100)
Text5(5).Text = Int(Rnd * 100)
Call sx(0, 0, 0)


'调用过程
Text3.Text = "名字PK," & Label11 & vbCrLf & vbCrLf
'显示值
Text3.Text = Text3.Text + Text1 & " " & "HP:" & Text4(0) & " " & "攻:" & Text4(1) & " " & "防:" & Text4(2) & " " & "速:" & Text4(3) & " " & "技:" & Text4(4) & " " & "运:" & Text4(5) & vbCrLf
Text3.Text = Text3.Text + Text2 & " " & "HP:" & Text5(0) & " " & "攻:" & Text5(1) & " " & "防:" & Text5(2) & " " & "速:" & Text5(3) & " " & "技:" & Text5(4) & " " & "运:" & Text5(5) & vbCrLf & vbCrLf
If Text4(5).Text > Text5(5).Text Then '战斗先机
Tur = 2
ElseIf Text4(5).Text < Text5(5).Text Then
Tur = 1
Else
MsgBox "运气都一样,在来一次!", , "提示"
Text4(5).Text = Int(Rnd * 100)
Text5(5).Text = Int(Rnd * 100)
End If
Timer1.Enabled = True
End If
End Sub
Private Sub Timer1_Timer()
a = Int(Rnd * 20)
b = Int(Rnd * 20)
If Text4(0) < 0 Then
Text4(0) = 0
Text3.Text = Text3.Text + "[" & Text1 & "]" & "被打败!"
Timer1.Enabled = False
Exit Sub
ElseIf Text5(0) < 0 Then
Text5(0) = 0
Text3.Text = Text3.Text + "[" & Text2 & "]" & "被打败!"
Timer1.Enabled = False
Exit Sub
ElseIf 10 > Text4(0) > 0 Then
f = Val(Int(Rnd * 10))

'随机出现垂死挣扎
Text3.Text = Text3.Text + "[" & Text1 & "]" & "垂死挣扎,提升属性值" & f & "点"
Call sx(f, 0, 0)


'调用sx
ElseIf 10 > Text5(0) > 0 Then
f = Val(Int(Rnd * 10))
Text3.Text = Text3.Text + "[" & Text2 & "]" & "垂死挣扎,提升属性值" & f & "点"
Call sx(f, 0, 1)
Else
If Tur = 1 Then '战斗循环
Call Skill(0, 0, Tur)
Text3.Text = Text3.Text + d & e & vbCrLf
Tur = 2
Exit Sub
ElseIf Tur = 2 Then
'战斗结束
Call Skill(0, 0, Tur)
Text3.Text = Text3.Text + c & e & vbCrLf
Tur = 1
Exit Sub
End If
End If
End Sub

上一个:vb文件同步比较程序
下一个:vb咋读写文本文件?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,