VB编程求修改密码个添加新用户
谁能帮我编下用VB修改用户密码和重新添加一个新用户的代码·修改后的密码和添加后的新用户都显示在一个记事本里面·而且说明下原因·还要用到OPEN语句·
谁能帮我编下用VB修改用户密码和重新添加一个新用户的代码·修改后的密码和添加后的新用户都显示在一个记事本里面·而且说明下原因·还要用到OPEN语句·
答案:根据你的问题我用VB帮你写了一个程序,基本上你描述的问题多可以解决。新建一个窗体后要引用一个FileSystemObject。在“工程-引用”中操作如图然后根据下图画出窗体界面
最后添加下面代码。
Private Sub Command1_Click()
Dim YesNO As Boolean '当YesNO=True时代表用户名在p.txt中以有,代表修改密码。YesNo=False为没有代表添加新记录。
Dim TStr As String
If Combo1.Text = "" Or Text2.Text = "" Then
MsgBox "用户名或密码不能为空!"
Exit Sub
End IfFor i = 1 To Combo1.ListCount
If Combo1.Text = Combo1.List(i - 1) Then
YesNO = True
Exit For
End If
Next iIf YesNO = True Then '用户名存大时
TStr = ""
Open (App.Path & "\p.txt") For Input As #1
Do While Not EOF(1)
Line Input #1, Intext
Intext = Trim(Intext)
If Intext <> "" Then
If Trim(Combo1.Text) = Mid(Intext, InStr(Intext, "U:") + 2, InStr(Intext, "P:") - InStr(Intext, "U:") - 2) Then
Intext = "U:" & Combo1.Text & "P:" & Text2.Text
End If
TStr = TStr + Intext + Chr(13) + Chr(10)
End If
Loop
Close #1
Open (App.Path & "\p.txt") For Output As #1
Print #1, TStr
Close #1Else '用户名不存在时
TStr = ""
Open (App.Path & "\p.txt") For Input As #1
Do While Not EOF(1)
Line Input #1, Intext
Intext = Trim(Intext)
If Intext <> "" Then
TStr = TStr + Intext + Chr(13) + Chr(10)
End If
Loop
Close #1
Intext = "U:" & Combo1.Text & "P:" & Text2.Text
TStr = TStr + Intext + Chr(13) + Chr(10)
Open (App.Path & "\p.txt") For Output As #1
Print #1, TStr
Close #1End If
MsgBox "保存成功!"
End SubPrivate Sub Form_Load()
Dim Intext As String
Label1.Caption = "用户名"
Label2.Caption = "密码:"
Command1.Caption = "保存"
Dim fs As New FileSystemObject
If fs.FileExists(App.Path & "\p.txt") Then '判断有没有p.txt这个文件
'如果有将里面的用户名添加到cobo1控件里
Open (App.Path & "\p.txt") For Input As #1
Do While Not EOF(1)
Line Input #1, Intext
If Len(Intext) <> 0 Then
Intext = Trim(Intext)
Combo1.AddItem Mid(Intext, InStr(Intext, "U:") + 2, InStr(Intext, "P:") - InStr(Intext, "U:") - 2)
End If
Loop
Close #1
Else
'如果没有生成一个p.txtOpen App.Path & "\p.txt" For Random As #1
Close #1
End If
Combo1.Text = Combo1.List(0)
Text2.Text = ""
Text2.PasswordChar = "*"
End Sub
上一个:vb主要做什么用的呀
下一个:VB程序中的错误分为哪几种