【问题标题】:Passing String Values in Visual Basic在 Visual Basic 中传递字符串值
【发布时间】:2014-02-25 06:17:37
【问题描述】:

我在尝试传递字符串数据类型的值时遇到问题。

我能做些什么来解决这个问题?

发件人:

Private Sub verButton_Click(sender As Object, e As EventArgs) Handles verButton.Click
        If chkauth.auth(csBox.Text, pwBox.Text) Then
            mainForm.Enabled = True
            infoLbl.Visible = False
        Else
            infoLbl.Visible = True
        End If
    End Sub

收件人:

Public Function auth(ByVal cs As String, ByVal pw As String)
        Select Case cs
            Case "Chauix"
                If pw = "ihartcha" Then
                    MsgBox("Authentication successful!", MsgBoxStyle.Information, "Success")
                    Return True
                Else
                    Return False

                End If

            Case "Brink"
                If pw = "Jesusismylife" Then
                    MsgBox("Authentication successful!", MsgBoxStyle.Information, "Success")
                    Return True
                Else
                    Return False

                End If

            Case Else
                Return False

        End Select

    End Function

当我尝试执行导致它的事件时,它总是会导致错误。

【问题讨论】:

  • 这是 VB6 还是 VB.NET?
  • 只是想知道,如果您使用的是您的实际用户名和密码?如果你是,你可能想改变你的例子中的那些:)
  • 不。他们不是。它们只是给我同学看的样本:D

标签: string function basic


【解决方案1】:

不确定您遇到了什么错误,请告知。您的函数 'auth' 没有返回类型 - 从这样做开始,并启用 option strict 和 option explicit,这将帮助您找到代码中可能缺少类型或声明的任何其他位置。

改变函数如下:

auth(ByVal cs As String, ByVal pw As String) as Boolean

这里是关于这些选项的页面:http://msdn.microsoft.com/en-us/library/zcd4xwzs.aspx

【讨论】:

    【解决方案2】:

    我对您的代码进行了一些更改,并将其作为 VB 应用程序运行,它完全可以运行。看看下面的代码:

    Public Class Form1
    
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If auth(TextBox1.Text, TextBox2.Text) Then
            MsgBox("Authentication successful!", MsgBoxStyle.Information, "Success")
        Else
            MsgBox("Authentication failed!", MsgBoxStyle.Critical, "Failed")
        End If
    End Sub
    
    Public Function auth(ByVal cs As String, ByVal pw As String)
        Select Case cs
            Case "demo1"
                If pw = "100" Then
                    Return True
                Else
                    Return False
    
                End If
    
            Case "demo2"
                If pw = "100" Then
                    Return True
                Else
                    Return False
    
                End If
    
            Case Else
                Return False
    
        End Select
    
    End Function
    

    结束类

    我希望这能解决你的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多