Visual Basic,打开表格

问题描述:

我想制作一个程序,要求用户登录,如果输入正确的用户名和密码,然后打开该用户的窗体。我也只是现在做的方式是用户名被存储在一个变量,我想知道我怎么可以在表单名称使用的文字从变量,例如:Visual Basic,打开表格

用户名=用户1然后

FrmUser1。显示

用户名= JohnSmith对然后

FrmJohnSmith.show

这里是从代码的摘录我迄今为止:

Dim Path As String = "Account_File.text " 
    Dim Read_File() As String = File.ReadAllLines(Path) 
    Dim NoOfLines As Integer = Read_File.Length 
    Dim UserName(NoOfLines) As String 
    Dim Password(NoOfLines) As String 
    Dim LastNonEmpty As Integer = -1 
    Dim InputUserName As String = "" 
    Dim InputPassword As String = "" 

    If TxtUserName.Text = "" Then 
     MsgBox("Please enter a username.") 
     GoTo InvalidDetails 
    Else 
     InputUserName = TxtUserName.Text 
    End If 

    If TxtPassword.Text = "" Then 
     MsgBox("Please enter a Password.") 
     GoTo InvalidDetails 
    Else 
     InputPassword = TxtPassword.Text 
    End If 

    For i = 0 To NoOfLines 
     Dim SplitString() As String = Split(Read_File(i)) 
     For j As Integer = 0 To SplitString.Length - 1 
       If SplitString(j) <> "" Then 
       LastNonEmpty += 1 
       SplitString(LastNonEmpty) = SplitString(j) 
      End If 
     Next 
     ReDim Preserve SplitString(LastNonEmpty) 
     LastNonEmpty = -1 
     UserName(i) = SplitString(0) 
     Password(i) = SplitString(1) 
    Next 

    For i = 0 To NoOfLines 
     If UserName(i) = InputUserName And Password(i) = InputPassword Then 
      frm.show() 
     Else 
      MsgBox("Either the username or password is incorrect.") 
     End If 
    Next 
+0

我从VB6重新签名到VB.Net(变量初始值设定器语法) – 2015-02-06 18:11:51

+0

谢谢我得到2混合有时 – Lazzer555 2015-02-06 18:32:48

+0

您是否有帐户文件中的每个用户的自定义窗体? – LarsTech 2015-02-06 18:45:24

一些示例代码:

Dim formname = "Form" + TxtUserName.Text 
    Dim typename = Me.GetType().Namespace + "." + formname 
    Dim type = Me.GetType().Assembly.GetType(typename) 
    If type IsNot Nothing Then 
     Dim form = CType(Activator.CreateInstance(type), Form) 
     form.Show() 
    End If 

即假设所有形式住在同一组件,并且具有相同的命名空间。请记住,您的客户不太可能因为每次获得新员工而不得不打电话给您。或者就此而言,您会希望您提供用户名和密码,而不必提供Windows登录已提供的安全保证。不要这样做。

+0

这只是个人使用的练习程序,目前我正在参加大学学习软件开发。 – Lazzer555 2015-02-06 19:12:48