vb编程 连接用户名现实问题
Private Sub Form_Load()
Dim username As String
username = InputBox("请输入用户名!")
Dim usernames(3) As String
usernames(0) = "xiaof"
usernames(1) = "xiaow"
usernames(2) = "xiaol"
usernames(3) = "xiaoz"
Dim flag As Boolean
flag = False
Dim i As Integer
For i = 0 To 3
If username = usernames(i) Then
flag = True
End If
Next i
If flag = False Then
MsgBox ("用户身份确认失败,请退出系统!")
End
End If
End Sub
Private Sub Picture1_Click()
Picture1.Print "欢迎您!" & username
End Sub
在运行的时候只显示欢迎您。。连接的用户名不能显示。。为什么。。谢谢
答案:因为你定义的username变量是私有的,只能在form_load的事件里面才有效,你要把它放到声明部分才行.
下面是正确的代码:
Dim username As String
Private Sub Form_Load()
username = InputBox("请输入用户名!")
Dim usernames(3) As String
usernames(0) = "xiaof"
usernames(1) = "xiaow"
usernames(2) = "xiaol"
usernames(3) = "xiaoz"
Dim flag As Boolean
flag = False
Dim i As Integer
For i = 0 To 3
If username = usernames(i) Then
flag = True
End If
Next i
If flag = False Then
MsgBox ("用户身份确认失败,请退出系统!")
End
End If
End Sub
Private Sub Picture1_Click()
Picture1.Print "欢迎您!" & username
End Sub
上一个:VB编程三个text的计算器
下一个:VB编程题目,求高手做