输入框有两个值作为输入

时间:2014-12-22 18:53:17

标签: vb.net visual-studio

我有这个代码,要求键打开某个窗口表单。如果无效密钥的数量大于3,则应用程序结束。

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load




        Dim clave As String, attempts As Integer, intentoclave As String

        'This is the key

        clave = "UNI"
        attempts = 0


        For attempts = 1 To 4


            If attempts < 4 Then
                intentoclave = InputBox("Write the key")

                If intentoclave = clave Then
                    Exit For

                    Me.Show()
                End If
            Else
                End
            End If

        Next



    End Sub

它工作正常,但我想在输入框中输入用户名。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

InputBox function具有可选值:

Public Function InputBox( _
   ByVal Prompt As String, _
   Optional ByVal Title As String = "", _
   Optional ByVal DefaultResponse As String = "", _
   Optional ByVal Xpos As Integer = -1, _
   Optional ByVal YPos As Integer = -1 _
) As String

您没有指定如何检索用户名以及您想要显示它的位置,但如果您想将其显示为输入框的默认值,您只需将该用户名传递给第三个参数( InputBox函数的DefaultResponse:

intentoclave = InputBox("Write the key", "Any title", "Your username goes here!")