VB登录界面代码

VB登录界面代码
方法一:
VB登录界面代码
Option Explicit
Private Sub cmdCancel_Click()
Dim intResult As Integer
'请求用户确认是否真的退出系统登录
intResult = MsgBox("你选择了退出系统登录,退出将不能启动企业人事管理系统!" & vbcrlf_ & "是否真的退出?", vbYesNo, "登录验证")
If intResult = vbYes Then End
'根据用户选择结束应用程序
End Sub
Private Sub CmdOK_Click()
Dim UserName As String
Dim userpassword As String
Dim str As String
Dim nTryCount As Integer
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
UserName = Trim(txtUserName.Text)
userpassword = Trim(txtpassword.Text)
str = "select * from 用户信息表where 用户名='" & UserName & "' and 用户密码= '" & userpassword & " '"
rs.Open str, connectString, adOpenKeyset, 2
If rs.EOF Then '登录失败
MsgBox "对不起,无此用户或者密码不正确!请重新输入!!", vbCritical, "错误"
txtUserName.Text = ""
txtpassword.Text = ""
txtUserName.SetFocus
nTryCount = nTryCount + 1
If nTryCount >= 3 Then
MsgBox "您无权操作本系统!", vbCritical, "无权限"
Unload Me
End If
Else '登陆成功
主界面.Show
Unload Me
End If
End Sub
方法二:
Private Sub Command1_Click()
Dim username As String
Dim userpassword As String
Dim try_times As Integer
try_times = 0
username = Trim$(user.text)
userpassword = Trim$(password.text)
If user.text = "" Then
MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"
user.SetFocus
Exit Sub
End If
If password.text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"
password.SetFocus
Exit Sub
End If
Dim strSQL As String
strSQL = "select * from staff where sno='" & username & "' and password='" & userpassword & "'"
Dim str As New ADODB.Recordset
Set str = New ADODB.Recordset
str.CursorLocation = adUseClient
str.Open strSQL, conn, adOpenStatic, adLockReadOnly
With str
If .State = adStateOpen Then .Close
.Open strSQL
If .EOF Then
try_times = try_times + 1
If try_times = 3 Then
MsgBox "您已经三次尝试进入本系统,均不成功,系统将会自动关闭", vbOKOnly + vbCritical, "警告"
Unload Me
Else
MsgBox "对不起,用户名不存在或密码不正确!", vbOKOnly + vbQuestion, "警告"
user.SetFocus
user.text = ""
password.text = ""
End If
Else
Unload Me
frm_main.Show
End If
End With
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Set conn = New ADODB.Connection
conn.ConnectionString = "dsn=LMS"
conn.Open
Login.Show
End Sub
Private Sub password_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then
Command1.SetFocus
End If
End Sub。

合集下载

VB用户登录管理系统

VB用户登录管理系统

软件开发环境与工具实验报告实验二实验题目:用户登录及管理系统实验地点:软件实验室一指导老师:王琦实验类型:设计型系班:计算机科学与技术系1103班姓名:秦芳芳(2011100316)2013年11月22日一.实验项目名称:用户登录及管理系统二. 实验目的和任务:1、掌握系统登录界面设计基本流程2、了解用户管理所要实现的基本功能3、要求利用三层架构思想机相关技术实现程序三. 实验内容及要求:1、能够进行登录验证2、能够实现对用户的基本管理,管理员能够进行查询添加修改删除3、利用数据库连接访问数据库,提高安全性四.实验步骤:1、class1.vb的代码:Imports System.Data.SqlClientPublic Class Class1Dim strconn As String = Me.getstrconn()Public Function yanzheng(ByVal str1 As String) As Integer Dim conn As New SqlConnectionconn.ConnectionString = strconnconn.Open()Dim cmd As New SqlCommandmandText = "select * from student where sname ='"& str1 & "'" cmd.Connection = conn'mandType = CommandType.TextDim dr As SqlDataReaderdr = cmd.ExecuteReaderIf dr.Read Thendr.Close()conn.Close()Return 1Elsedr.Close()conn.Close()Return 0End IfEnd FunctionPublic Function pwdyanzheng(ByVal str As String) As SqlDataReader Dim conn As New SqlConnectionconn.ConnectionString = strconnconn.Open()Dim cmd As New SqlCommandmandText = "select * from student where sname = '"& str & "'" cmd.Connection = connDim dr As SqlDataReader = cmd.ExecuteReaderReturn drEnd FunctionPublic Function getstrconn() As StringDim str As Stringstr = "server=" &System.Configuration.ConfigurationManager.AppSettings("server") & ";" str &= "uid=" &System.Configuration.ConfigurationManager.AppSettings("uid") & ";"str &= "pwd=" &System.Configuration.ConfigurationManager.AppSettings("pwd") & ";"str &= "database=" &System.Configuration.ConfigurationManager.AppSettings("database") Return strEnd FunctionPublic Function getalldata() As DataSetDim conn As New SqlConnectionconn.ConnectionString = strconnconn.Open()Dim da As New SqlDataAdapter("select * from student", conn)Dim ds As New DataSetda.Fill(ds, "student")conn.Close()Return dsEnd FunctionPublic Function insdata(ByVal str1 As String, ByVal str2 As String) As StringDim conn As New SqlConnectionconn.ConnectionString = strconnDim cmd As New SqlCommandcmd.Connection = connmandText = "insert into student(sname,sno) values('" & str1 & "','" & str2 & "') "Tryconn.Open()cmd.ExecuteNonQuery()Return"1"Catch ex As ExceptionReturn"-1" & ex.MessageEnd Tryconn.Close()End FunctionPublic Function upd(ByVal str1 As String, ByVal str2 As String) As StringDim conn As New SqlConnectionconn.ConnectionString = strconnDim cmd As New SqlCommandcmd.Connection = connmandText = "update student set sno ='" & str2 & "'where sname ='" & str1 & "'"Tryconn.Open()cmd.ExecuteNonQuery()Return"1"Catch ex As ExceptionReturn"-1" & ex.MessageEnd Tryconn.Close()End FunctionPublic Function deldata(ByVal str As String) As StringDim conn As New SqlConnectionconn.ConnectionString = strconnDim cmd As New SqlCommandcmd.Connection = connmandText = "delete from student where sname ='"& str & "'"Tryconn.Open()cmd.ExecuteNonQuery()Return"1"Catch ex As ExceptionReturn"-1" & ex.MessageEnd Tryconn.Close()End FunctionPublic Function search(ByVal str1 As String) As StringDim conn As New SqlConnectionconn.ConnectionString = strconnDim cmd As New SqlCommandcmd.Connection = connmandText = "select * from student"Tryconn.Open()cmd.ExecuteNonQuery()Return"1"Catch ex As ExceptionReturn"-1" & ex.MessageEnd Tryconn.Close()End FunctionEnd Class2、进入界面功能的代码:Imports System.Data.SqlClientPublic Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim o As New Class1Dim f As Integerf = o.yanzheng(Me.TextBox1.Text)If f = 0 ThenMsgBox("不存在该用户,请重新输入!")Me.TextBox1.Text = ""Me.TextBox1.Focus()ElseIf f = 1 ThenDim dr As SqlDataReaderdr = o.pwdyanzheng(Me.TextBox1.Text)dr.Read()If RTrim(dr!sno) <> Me.TextBox2.Text ThenMsgBox("密码错误,请重新输入!")Me.TextBox2.Text = ""Me.TextBox2.Focus()ElseDim strpwd As Stringstrpwd = Me.TextBox2.Textstrpwd =System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfi gFile(strpwd, "md5")Dim frm As New Form2frm.loginname = Me.TextBox1.Textfrm.logintime = TimeOfDayfrm.Show()Me.Hide()End IfEnd IfEnd IfEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickMyBase.Dispose()End SubEnd Class3、用户管理和浏览信息界面的代码:Public Class Form2Public loginname As StringPublic logintime As StringPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickMe.Hide()Form3.Show()End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickMe.Hide()Form4.Show()End SubPrivate Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadMe.loginstatusname.Text = "用户名:" & loginnameMe.loginstatustime.Text = "登录时间:" & logintime End SubPrivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.TickMe.ToolStripStatusLabel1.Text = NowEnd SubEnd Class4、增,删,改,查功能页面的代码:Public Class Form3Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickMe.Hide()del.Show()End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickMe.Hide()ins.Show()End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickMe.Hide()upda.Show()End SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button4.ClickMe.Close()search.Show()End SubEnd Class5、显示信息界面的代码:Public Class Form4Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickMe.Close()Form2.Show()End SubPrivate Sub Form4_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadDim o As New Class1Dim ds As New DataSetds = o.getalldata()Me.DataGridView1.Refresh()Me.DataGridView1.DataSource = ds.Tables("student") End SubEnd Class6、插入信息界面的代码:Public Class insPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim o As New Class1o.insdata(Me.TextBox1.Text, Me.TextBox2.Text)Me.Close()Form2.Show()End SubEnd Class7、查询信息界面的代码:Public Class searchPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim o As New Class1Dim ds As New DataSeto.search(Me.TextBox1.Text)ds = o.getalldata()Me.DataGridView1.Refresh()Me.DataGridView1.DataSource = ds.Tables("student") End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickMe.Close()Form2.Show()End SubPrivate Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClickMe.TextBox1.Text =DataGridView1.CurrentRow.Cells.Item(0).Value.ToStringMe.TextBox2.Text =DataGridView1.CurrentRow.Cells.Item(1).Value.ToStringMe.TextBox3.Text =DataGridView1.CurrentRow.Cells.Item(2).Value.ToStringMe.TextBox4.Text =DataGridView1.CurrentRow.Cells.Item(3).Value.ToStringMe.TextBox5.Text =DataGridView1.CurrentRow.Cells.Item(4).Value.ToStringEnd SubEnd Class8、修改信息界面的代码:Public Class updaPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim o As New Class1o.upd(Me.TextBox1.Text, Me.TextBox2.Text)Me.Close()Form2.Show()End SubEnd Class9、删除信息界面的代码:Public Class delPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim o As New Class1'o.deldata(Me.TextBox1.Text)o.deldata(Me.TextBox1.Text)Me.Close()Form2.Show()End SubEnd Class五、运行结果及截图:(1)建立数据库(2)运行截图六、实验总结:通过本次实验,我大致掌握了一个登录系统界面设计的基本流程,同时了解了用户管理所要实现的基本功能,而且能够利用三层架构思想机相关技术实现程序,能够进行登录验证,实现了对用户的基本管理,在系统中实现了增删查改的功能,利用数据库连接访问数据库,提高了安全性,为以后的学习打下了很好的基础。

vb程序设计登陆界面代码详例

vb程序设计登陆界面代码详例

vb程序设计登陆界面代码详例Imports System.Data.SqlClientPublic Class frmMagementMain'Inherits System.Windows.Forms.FormDim constr As String = "User ID=sa;pwd=a;Initial Catalog=zbb;Data Source=(local)" '定义一个变量,连接字符串Dim sqlstr As String = "select * from manid" '定义一个变量,SQL语句Dim mycon As New SqlConnection(constr) '定义一个变量,为一个连接对象Dim mycom As New SqlCommand(sqlstr, mycon) '定义一个变量,为命令对象Dim myReader As SqlDataReader '定义一个变量,阅读器Dim i As Integer = 0Dim userIDsys() As ArrayPrivate Sub frmMagementMain_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Loadmycon.Open() '打开这个联接myReader = mycom.ExecuteReader '把这个命令的连接送入阅读器myReader.Read()Dim k As Integer = 0While myReader.Read 'while 为遍历集合的每一项,用阅读器的read的方法来读取'定义一个变量的第一项k = k + 1'MsgBox(myReader.Item(1))End WhileMsgBox(k)End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click' Visual Basic 2005' Declare a new TextBox.Dim TextBox2 As New TextBox' Set the location below the first TextBoxTextBox2.Left = 102TextBox2.Top = 242' Add the TextBox to the form's Controls collection.Me.Controls.Add(TextBox2)TextBox2.Text = "这可是我动态加的控件呀"End SubPrivate Sub mnu_magement_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles mnu_magement.ClickDim frmlogin As frmlogin = New frmloginfrmlogin.Show()'GBmagemetPeple.Left = 8'GBmagemetPeple.Top = 28'GBmagemetPeple.Visible = TrueEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button2.ClickEnd SubEnd Class/////////////////////////////////////Imports System.Data.SqlClientPublic Class frmloginDim i As Integer = 0Dim constr1 As String = "" '定义一个变量,连接字符串Dim sqlstr1 As String = ""Dim mycon1 As New SqlConnection(constr1) '定义一个变量,为一个连接对象Dim mycom1 As New SqlCommand(sqlstr1, mycon1) '定义一个变量,为命令对象Dim myReader1 As SqlDataReader '定义一个变量,阅读器Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles OK_Button.ClickIf txtUsename.Text = "" Or txtPassword.Text = "" ThenMsgBox("请输入用户名和密码")Exit SubEnd Ifsqlstr1 = "select * from mgpep where usernameID='" & txtUsename.Text & "' andpasswordID='" & txtPassword.Text & "'" '定义一个变量,SQL语句constr1 = "User ID=sa;pwd=a;Initial Catalog=SaleCD;DataSource=(local)" '定义一个变量,连接字符串mycon1.ConnectionString = constr1mandText = sqlstr1mycon1.Open() '重新打开这个联接myReader1 = mycom1.ExecuteReader '第二次把这个命令的连接送入阅读器If myReader1.VisibleFieldCount = 0 ThenMsgBox("密码不对请重新输入~")Exit SubEnd IfmyReader1.Read() '阅读器重新使用read方法On Error GoTo ssIf myReader1(0) > 0 ThenfrmMagementMain.GBmagemetPeple.Visible = Truesqlstr1 = "select * from mgpep"If mycon1.State = 1 Thenmycon1.Close()End Ifmycon1.Open()myReader1 = mycom1.ExecuteReader '把这个命令的连接送入阅读器Dim userIDsys(myReader1.VisibleFieldCount - 1, 2)'ReDim userIDsys(10, 2)Dim k As Integer = 0While myReader1.ReadfrmMagementMain.CmbUser.Items.Add(myReader1(0)) For i = 0 To 2userIDsys(k, i) = myReader1.Item(i)Nextk = k + 1End WhileMsgBox("已经成功登录~")mycon1.Close()Me.Close()Exit SubElseMsgBox("您没有权限登录~")mycon1.Close()Me.Close()Exit SubEnd Ifss:MsgBox("您没有权限登录~")Me.Close()End SubPrivate Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Cancel_Button.ClickMe.Close()End SubEnd ClassPublic ADOcn As ConnectionPublic Sub main()Dim strSQLServer As StringstrSQLServer = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist SecurityInfo=False;Initial Catalog=图书销售管理系统;DataSource=longmingxue\SQLEXPRESS"Set ADOcn = New ConnectionADOcn.Open = strSQLServerFrmMain.ShowEnd SubPrivate Sub Command1_Click()Dim ADOrs As New RecordsetDim strSQL As StringDim strXB As StringADOrs.ActiveConnection = ADOcnADOrs.Open "select 学号 from 学生表"If Not ADOrs.EOF ThenMsgBox "该学号已经存在,不能继续添加~", vbCritical + vbOKOnly, "信息提示"ElseIf Option1.Value ThenstrXB = "男"ElsestrXB = "女"End IfstrSQL = "Insert Into 学生表( 学号,姓名,性别)"strSQL = strSQL + " Values('" + Text1 + "','"strSQL = strSQL + Text2 + "','" + strXB + "')"ADOcn.Execute strSQLMsgBox "添加成功~", vbOKOnly, "信息提示"End IfEnd Sub。

[最新]vb登录界面代码

[最新]vb登录界面代码

[最新]vb登录界面代码VB登录界面代码方法一:VB登录界面代码Option ExplicitPrivate Sub cmdCancel_Click() Dim intResult As Integer '请求用户确认是否真的退出系统登录intResult = MsgBox("你选择了退出系统登录,退出将不能启动企业人事管理系统~" & vbcrlf_ & "是否真的退出,", vbYesNo, "登录验证") If intResult = vbYes Then End '根据用户选择结束应用程序End SubPrivate Sub CmdOK_Click() Dim UserName As StringDim userpassword As String Dim str As StringDim nTryCount As Integer Dim rs As New ADODB.Recordset Set rs = New ADODB.Recordset UserName = Trim(txtUserName.Text) userpassword =Trim(txtpassword.Text) str = "select * from 用户信息表 where 用户名='" & UserName & "' and 用户密码 = '" & userpassword & " '" rs.Open str, connectString, adOpenKeyset, 2 If rs.EOF Then '登录失败MsgBox "对不起,无此用户或者密码不正确~请重新输入~~", vbCritical, "错误"txtUserName.Text = ""txtpassword.Text = ""txtUserName.SetFocusnTryCount = nTryCount + 1If nTryCount >= 3 ThenMsgBox "您无权操作本系统~", vbCritical, "无权限" Unload Me End IfElse '登陆成功主界面.ShowUnload MeEnd IfEnd Sub方法二:Private Sub Command1_Click()Dim username As StringDim userpassword As StringDim try_times As Integertry_times = 0username = Trim$(user.text)userpassword = Trim$(password.text)If user.text = "" ThenMsgBox "用户名不能为空~", vbOKOnly + vbInformation, "友情提示" user.SetFocusExit SubEnd IfIf password.text = "" ThenMsgBox "密码不能为空~", vbOKOnly + vbInformation, "友情提示"password.SetFocusExit SubEnd IfDim strSQL As StringstrSQL = "select * from staff where sno='" & username & "' and password='"& userpassword & "'"Dim str As New ADODB.RecordsetSet str = New ADODB.Recordsetstr.CursorLocation = adUseClientstr.Open strSQL, conn, adOpenStatic, adLockReadOnlyWith strIf .State = adStateOpen Then .Close.Open strSQLIf .EOF Thentry_times = try_times + 1If try_times = 3 ThenMsgBox "您已经三次尝试进入本系统,均不成功,系统将会自动关闭", vbOKOnly + vbCritical, "警告"Unload MeElseMsgBox "对不起,用户名不存在或密码不正确~", vbOKOnly + vbQuestion, "警告"user.SetFocususer.text = ""password.text = ""End IfElseUnload Mefrm_main.ShowEnd IfEnd WithEnd SubPrivate Sub Command2_Click() Unload MeEnd SubPrivate Sub Form_Load()Set conn = New ADODB.Connectionconn.ConnectionString = "dsn=LMS"conn.OpenLogin.ShowEnd SubPrivate Sub password_KeyPress(KeyAscii As Integer) If KeyAscii = 13 ThenCommand1.SetFocusEnd IfEnd Sub。

用VB编写登录程序

用VB编写登录程序
界面设计:
打开“VB6.0”,出现“新建工程”对话框,选择“标准EXE”单击“打开”即可新建一个工程。新建一个工程后,VB自动生成了一个窗体,其默认的名称是Form1,且显示的标题也是Form1,显然与我们要编写的程序不符。我们可以更改这些设置,方法是:点击Form1窗体,在右边的属性窗口中(如图1)的“名称”后输入“Denglu”(在后面讲的Denglu就是指的这个窗体),在“Caption”后输入“登录窗口”。窗体设置好后,我们便可以将控件放置到这个窗体中去了。
MsgBox ″请输入用户名!″,vbOKOnly+vbCritical,″错误″
Exit Sub ′退出这个过程
Else ′如果输入了用户名
If Text1.Text=″软件世界″ And Text2.Text=″12345″ Then ′如果输入的用户名是″软件世界″且密码为″12345″
但这个程序目前还只能判断在程序中已设置好了的用户名及密码,没有灵活性,你可以发挥你的聪明才智,使其能够判断多个合法的用户及密码。如果你有什么疑问,欢迎写信与我交流,我的E-mail地址是:vber@。
(重庆 杜伟)}
程序测试:
现在我们可以单击“F5”键来运行这个程序,看看其运行效果。直接单击“确定”按钮,将会弹出一个对话框(如图7);在“用户名”后输入“软件世界”,“密码:”后输入“12345”,再单击“确定”按钮,此时便会出现一个“欢迎进行”的信息框(如图8)。怎么样,一个属于自己的“登录窗口”就制作好了。
MsgBox ″你是合法用户,欢迎进入!″,vbOKOnly+vbInformation,12345″
MsgBox ″用户名或密码错误!″,vbOKOnly+vbCritical,″错误″

库存管理之用户登录及用户列表——VB代码

库存管理之用户登录及用户列表——VB代码

1、首页,用户登录界面'连接SQL数据库时必写语句Imports System.Data.SqlClientPublic Class Frm_UserloginPrivate Sub Bt_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_login.ClickIf Txt_UserId.Text = ""ThenMsgBox("用户名不能为空,请输入用户名!", MsgBoxStyle.OkOnly, "温馨提示") Exit SubEnd IfIf Txt_Paw.Text = ""ThenMsgBox("密码不能为空,请输入密码!", MsgBoxStyle.OkOnly, "温馨提示")Exit SubEnd If'连接数据库Dim conn As New SqlConnection'conn.ConnectionString = "user id=sa;password=;database=test;data source=."连接SQL2000数据库的方法'连接SQL Server2005数据库的方法conn.ConnectionString = "server=.;integrated security=sspi;database=NO.4"conn.Open()Dim constr As String'判断输入的数据是否正确Dim UserName, password As StringUserName = Trim(Txt_UserId.Text)password = Trim(Txt_Paw.Text)constr = "select * from t1 where id='" & UserName & " 'and Psd='" & password & "'"Dim da As New SqlDataAdapter(constr, conn)Dim ds As New DataSetda.Fill(ds)If ds.Tables(0).Rows.Count >= 1 ThenMDIParent1.ShowDialog()Me.Hide()ElseMsgBox("用户名或密码错误", MsgBoxStyle.OkOnly, "温馨提示")Txt_UserId.Text = ""Txt_Paw.Text = ""Txt_Paw.Focus()Txt_UserId.Focus()End IfEnd SubPrivate Sub Bt_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_cancel.ClickTxt_UserId.Text = ""Txt_Paw.Text = ""Txt_Paw.Focus()Txt_UserId.Focus()End SubEnd ClassImports System.Data.SqlClientPublic Class Frm_yhlbDim conn As New SqlConnection()Dim flag As IntegerDim ds As New DataSetPrivate Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load‘添加数据库中的数据到DGW控件中GroupBox1.Enabled = Falsebaocun.Enabled = Falsequxiao.Enabled = Falseconn.ConnectionString = "server=(local);integrated security=sspi;database=NO.4"conn.Open()Dim st As Stringst = "select * from t1"Dim da As New SqlDataAdapter(st, conn)Dim ds As New DataSetda.Fill(ds)DGW1.ColumnCount = ds.Tables(0).Columns.CountDGW1.RowCount = ds.Tables(0).Rows.Count'DGW1.ColumnCount = 4 '列'DGW1.RowCount = 4 '行For i = 0 To ds.Tables(0).Rows.Count - 1For j = 0 To ds.Tables(0).Columns.Count - 1DGW1.Rows(i).Cells(j).Value = ds.Tables(0).Rows(i).ItemArray(j)Next jFor j = 0 To ds.Tables(0).Columns.Count - 1DGW1.Columns(j).HeaderText = ds.Tables(0).Columns(j).ColumnNameNextNext iEnd SubFunction f_diaoyong(ByVal st As String) As Long'Dim st As String'st = "select * from t1"Dim da As New SqlDataAdapter(st, conn)Dim ds As New DataSetda.Fill(ds)DGW1.ColumnCount = ds.Tables(0).Columns.CountDGW1.RowCount = ds.Tables(0).Rows.Count'DGW1.ColumnCount = 4 '列'DGW1.RowCount = 4 '行For i = 0 To ds.Tables(0).Rows.Count - 1For j = 0 To ds.Tables(0).Columns.Count - 1DGW1.Rows(i).Cells(j).Value = ds.Tables(0).Rows(i).ItemArray(j)Next jFor j = 0 To ds.Tables(0).Columns.Count - 1DGW1.Columns(j).HeaderText = ds.Tables(0).Columns(j).ColumnNameNextNext iEnd FunctionPrivate Sub tianjia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tianjia.Clickflag = -1GroupBox1.Enabled = Truebaocun.Enabled = Truequxiao.Enabled = TrueTextBox1.Enabled = TrueTextBox2.Text = ""TextBox1.Text = ""TextBox1.Focus()TextBox3.Text = ""End SubPrivate Sub baocun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles baocun.ClickIf flag = -1 ThenDim a, b, c As Stringa = Trim(TextBox1.Text)b = Trim(TextBox2.Text)c = Trim(TextBox3.Text)Dim str As StringDim da As New SqlDataAdapter("select * from t1", conn)da.Fill(ds)For i = 0 To ds.Tables(0).Rows.Count - 1str = Trim(ds.Tables(0).Rows(i).ItemArray(0))If Trim(TextBox1.Text) = str ThenMsgBox("对不起,你的ID重复,请重新输入!", MsgBoxStyle.OkOnly, "用户消息提示框")TextBox1.Text = ""TextBox1.Focus()Exit SubEnd IfNextDim stre = "Insert into t1 values('"& Trim(a) & " ',' "& Trim(b) & " ', ' "& Trim(c) & " ' )"Dim com As New SqlCommand(stre, conn)com.ExecuteNonQuery()ElseIf flag = 1 ThenDim name1, mima1, a1 As Stringname1 = TextBox2.Textmima1 = TextBox3.Texta1 = TextBox1.Texta1 = DGW1.SelectedRows(0).Cells(0).ValueDim stre = "update t1 set name= ' " & name1 & " ', psd= ' " & mima1 & " 'where id='" & a1 & " ' "Dim com As New SqlCommand(stre, conn)com.ExecuteNonQuery()End IfTextBox1.Text = ""TextBox1.Focus()TextBox2.Text = ""TextBox3.Text = ""baocun.Enabled = Falsequxiao.Enabled = FalseGroupBox1.Enabled = FalseCall f_diaoyong("select * from t1")End SubPrivate Sub quxiao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles quxiao.ClickTextBox1.Text = ""TextBox1.Focus()TextBox2.Text = ""TextBox3.Text = ""DGW1.Enabled = Falsebaocun.Enabled = Falsequxiao.Enabled = FalseGroupBox1.Enabled = FalseEnd SubPrivate Sub xiugai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xiugai.Clickflag = 1TextBox1.Enabled = Falsebaocun.Enabled = Truequxiao.Enabled = TrueGroupBox1.Enabled = TrueTextBox1.Text = DGW1.SelectedRows(0).Cells(0).ValueTextBox2.Text = DGW1.SelectedRows(0).Cells(1).ValueTextBox3.Text = DGW1.SelectedRows(0).Cells(2).ValueEnd SubPrivate Sub tuichu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tuichu.ClickEndEnd SubPrivate Sub shanchu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles shanchu.ClickDim yh As Stringyh = TextBox1.Textyh = DGW1.SelectedRows(0).Cells(0).ValueDim stre = "delete from t1 where id='" & yh & " '"Dim com As New SqlCommand(stre, conn)com.ExecuteNonQuery()MsgBox("确定删除!", MsgBoxStyle.OkOnly, "提示信息")baocun.Enabled = Truequxiao.Enabled = TrueDGW1.Enabled = FalseCall f_diaoyong("select * from t1")End SubEnd Class。

后台自动登录网页vb脚本实例代码

后台自动登录网页vb脚本实例代码

set IE=createobject("Internetexplorer.application")IE.Visible = TrueIE.Navigate "https:///login.htm"‘等待网页加载完成While IE.busy Or IE.readystate<>4Wend'从网页元素中找到设置的元素,并赋值'因为form没有name或id,只能从document的collection里取forms集合'再从中定位输入框和提交按钮IE.Document.Forms(0).elements("name").value = "aaaa"IE.Document.Forms(0).elements("passwd").value = "1111"IE.Document.Forms(0).elements("Send").click'登录后界面是框架结构,先等主框架加载完成While IE.busy Or IE.readystate<>4Wend'等框架内网页1加载完成While IE.busy Or IE.Document.Frames(1).document.readystate<>"complete"Wend'点击一个图片按钮/链接,需要先定位到框架内,再从document的collection里取images集合IE.Document.Frames(1).document.images(3).click'等主框架加载完成While IE.busy Or IE.readystate<>4Wend'等框架内网页2加载完成While IE.busy Or IE.Document.Frames(2).document.readystate<>"complete"Wend'定位select控件,并作出选择IE.Document.Frames(2).document.Forms(0).elements("lst_ed_day").selectedIndex=8IE.Document.Frames(2).document.Forms(0).elements("lst_st_time").selectedIndex=1'其他操作。

如何用VB编写一个用户登录窗口

至此,我们完成 了编程,调试一下 以检验程序的正确 性。一种可以右键 “文件”,再点击 “调试”,另一种 是直接点击调试按 钮。
方法/步骤7
在form1窗体里, 双击“重新输入” 按钮,弹出代码窗 口,写上代码,然 后关闭代码窗口。 Private Sub Command2_Clic k() Text1 = "" Text2 = "" End Sub
方法/步骤8
在form2窗体里, 双击“返回”按钮, 弹出代码窗口,写 上代码,然后关闭 代码窗口。 Private Sub Command1_Clic k() Form2.Hide Form1.Show Form1.Text1 = "" Form1.Text2 = "" End Sub
方法/步骤9
在form3窗体里, 双击“重新输入” 按钮,弹出代码窗 口,写上代码,然 后关闭代码窗口。 Private Sub Command1_Clic k() Form3.Hide Form1.Show Form1.Text1 = "" Form1.Text2 = "" End Su
选中(单击即可)窗体Form1,在 右边的属性栏将Caption属性值改 为“用户登录”;选中标签Lable1 将Caption属性值改为“用户名”, 选中标签Lable2将Caption属性值 改为“密码”,属;选中文本框 Text1,将Text属性值置空,选中 文本框Text2,将Text属性值置空 且将PasswordChar属性值改为 “*”;选中按钮Command1,将 Caption属性值改为“登录”,选 中按钮Command2,将Caption属 性值改为“重新输入”。然后调整 各控件位置和大小,使整个窗体更 加美观。

高中信息技术基础VB登录程序代码

高中信息技术基础VB登录程序代码Dim num As Integer, t As Integer Private Sub command1_click()Dim uname As String, psd As String, vcode As Integeruname = Text1.Textpsd = Text2.Textvcode = Val(Text3.Text)If vcode <> Val(Label4.Caption) Thennum = num - 1Label5.Caption = "验证码有误," & "还有" & Str(num) & "次机会"ElseIf uname <> "admin" Or psd <> "p@$$w0rd" Thennum = num - 1Label5.Caption = "用户名与密码错误," & "还有" & Str(num) & "次机会"ElseLabel5.Caption = "验证成功~" timer1.Interval = 200image1.Visible = TrueEnd IfIf num < 1 ThenMsgBox ("3次机会已到,程序结束~")EndEnd IfEnd SubPrivate Sub Form_Load()RandomizeLabel4.Caption = Int(Rnd * 9000) + 1000image1.Visible = Falsenum = 3t = 60timer2.Interval = 1000End SubPrivate Sub timer1_timer()Dim n As Integer, ss As String ss = Label5.Caption n = Len(ss)Label5.Caption = Mid(ss, 2, n - 1) + Mid(ss, 1, 1) End SubPrivate Sub timer2_timer()label6.Caption = "还剩余" & Str(t) & "秒"t = t - 1If t < 0 ThenMsgBox ("时间到,程序结束~")EndEnd IfEnd Sub。

如何用VB编写一个用户登录窗口


在form2窗体各添加一个标 签和按钮。在标签的 Caption属性值改为“登录 成功!”也可以通过Font属 性更改字体;按钮的 Caption属性值改为“返 回”。
在form3窗体各添加一个 标签和按钮。在标签的 Caption属性值改为“用户 名或tion 属性值改为“重新登录”。
.
9
方法/步骤10
至此,我们完成 了编程,调试一下 以检验程序的正确 性。一种可以右键 “文件”,再点击 “调试”,另一种 是直接点击调试按 钮。
.
10
此课件下载可自行编辑修改,此课件供参考! 部分内容来源于网络,如有侵权请与我联系删除!
.
5
方法/步骤6
在form1窗体里,双击“登录”按钮,弹 出代码窗口,写上代码(在编写代码时系 统会自动检查代码错误,但不是万能的哦, 有些错误系统检查不出来),然后关闭代 码窗口,代码会自动保存。我把代码也写 下来,以方便亲手复制粘贴验证一下。
Private Sub Command1_Click() If Text1 = "aaa" And Text2 = "abc123" Then Form1.Hide Form2.Show Else Form1.Hide Form3.Show End If End Sub
Private Sub Command1_Clic k() Form2.Hide Form1.Show Form1.Text1 = "" Form1.Text2 = "" End Sub
.
8
方法/步骤9
在form3窗体里, 双击“重新输入” 按钮,弹出代码窗 口,写上代码,然 后关闭代码窗口。
Private Sub Command1_Clic k() Form3.Hide Form1.Show Form1.Text1 = "" Form1.Text2 = "" End Sub

VB制作系统登录界面,包括用户名,密码和错误校验及效果全代码

VB制作系统登录界面,包括用户名,密码和错误校验及效果全代码第十讲:教你用VB制作系统登录界面,包括用户名,密码和错误校验及效果全代码以下代码均为个人学习心得,经过测试并且无误,可以嵌入大型程序中作为身份认证的功能作用。

其中有一些窗体名和效果代码,不必复制,否则会出现错误,请仔细阅读核心代码理解即可。

红色代码部份为实现用户检测的关键代码,必需要有后台数据库用来存放用户信息,通过 conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\HISDB.mdb"来连接,然后用If rs.EOF = True Then进行判断表中是否存在用户信息即可。

Option ExplicitDim Cnum As IntegerPrivate Sub CmdCancel_Click()'//结束EndEnd SubPrivate Sub CmdLogin_Click()Dim UserName As StringDim PassWord As StringDim conn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim StrSQL As Stringconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &App.Path & "\HISDB.mdb"UserName = Trim(TxtUserName.Text) '//将文本框内的值赋给定义好的全局变量PassWord = Trim(TxtPassword.Text) If UserName = "" Or PassWord = "" ThenMsgBox "对不起,用户或密码不能为空~请重新输入~~", vbCritical, "错误"ElseIf UserName <> Empty And PassWord <> Empty Then '//用户名与密码是否为空Cnum = Cnum + 1StrSQL = "select * from 用户信息表 where 用户名称= '" & UserName & "'and 用户口令 ='" & PassWord & "'"rs.Open StrSQL, conn, adOpenKeyset, adLockPessimistic '//打开记录集If rs.EOF = True ThenMsgBox "对不起,无此用户或者密码不正确~请重新输入~~", vbCritical, "错误"TxtUserName.Text = ""TxtPassword.Text = ""TxtUserName.SetFocusrs.CloseIf Cnum >= 3 ThenMsgBox "对不起,您已经多次失败,无权操作本系统~", vbCritical, "无权限"Unload MeExit SubEnd IfElse '登陆成功,以下为权限验证If rs.Fields("用户权限").Value = "系统管理" Then Frmmdimain.Show Unload MeElseIf rs.Fields("用户权限").Value = "挂号" ThenFrmregistration2.ShowUnload MeElseIf rs.Fields("用户权限").Value = "诊断" Then Frmdiagnose2.Show Unload MeElseIf rs.Fields("用户权限").Value = "收费" Then Frmcharges2.Show Unload MeElseIf rs.Fields("用户权限").Value = "发药" Then Frmmedicine2.Show Unload MeEnd Ifrs.CloseEnd IfEnd IfEnd SubPrivate Sub Form_Load()'//加载主窗时给文本框赋值TxtUserName.Text = "Admin"TxtPassword.Text = "123"Cnum = 0End SubPrivate Sub TmrChangeColor_Timer() '//调用定义好的改变颜色过程, Call changecolor(LblWelcome(0), 0, 1, 2, 3, 4, 5, 6, 7)End SubPrivate Sub TmrMoveText1_Timer() '//移动LblShaSiLblShaSi(0).Move LblShaSi(0).Left + 20 LblShaSi(1).Move LblShaSi(1).Left + 20 End SubPrivate Sub TmrMoveText2_Timer() '//移动LblShaSiIf LblShaSi(0).Left + LblShaSi(0).Width >= Me.Width +LblShaSi(0).WidthThenLblShaSi(0).Move -1500End IfIf LblShaSi(1).Left + LblShaSi(1).Width >= Me.Width +LblShaSi(1).WidthThenLblShaSi(1).Move -1500End IfEnd Sub'//定义一个改变颜色的过程,下面的control就是我们所说的控件 Sub changecolor(LCnt As Control, color1 As Integer, _color2 As Integer, color3 As Integer, _color4 As Integer, color5 As Integer, _color6 As Integer, color7 As Integer, _color8 As Integer)Dim tmep As Integertmep = Val(LCnt.Tag) '//将返回包含于字符串内的数字赋给TEMP Select Case tmepCase color1LCnt.Tag = color2Case color2LCnt.Tag = color3Case color3LCnt.Tag = color4Case color4LCnt.Tag = color5Case color5LCnt.Tag = color6Case color6LCnt.Tag = color7Case color7LCnt.Tag = color8Case color8LCnt.Tag = color1End SelectLCnt.ForeColor = QBColor(LCnt.Tag) '//给控件LCnt中的字体赋予颜色,注意QBColor是将一值'//转换为三色,MSDN详解,我也是在那查的````哈End Sub。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档