【问题标题】:Variable is not declared. Permission level error变量未声明。权限级别错误
【发布时间】:2011-09-13 02:00:37
【问题描述】:
Option Strict On

Public Class Form1
'Project:  
'Author: 
'Date created: 9/8/2011
'Program Description: Program.

Private Sub btnData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnData.Click

    '0. Declare variables
    Dim customerName As String
    Dim phoneNum As String
    Dim ticketPrice As Double
    Dim firstName, lastName As String
    Dim position As Integer
    Dim amountPaid As Double
    Dim areCode As String

    '1. Collect data: Customer name, phone number, ticket amount, and cash paid (use an input box)
    'get customer name from a textbox
    customerName = CStr(txtCustName.Text)

    'get phone number from a masked textbox
    phoneNum = mskPhone.Text

    'get ticket price from a textbox
    ticketPrice = CDbl(Val(txtTicket.Text))

    'get cash paid from a input box
    amountPaid = CDbl(Val(InputBox("Cash paid", "Lab2", "20")))

    '2. Rearrange name (Last, First)
    position = customerName.IndexOf(" ")
    firstName = customerName.Substring(0, position)
    lastName = customerName.Substring(position + 1)

    '3. Extract area code
    areCode = phoneNum.Substring(1, 3)

    '4. Calculate the change

    '5. Print data. Use the working version as a reference for your output.
    'print customer name

    lstDisplay.Items.Add("Customer Name: " & lastName & ", " & firstName)

End Sub

End Class

【问题讨论】:

  • 错误与哪一行(不是行号!)相关联?
  • 错误 2 'txtCustName' 未声明。由于其保护级别,它可能无法访问。第 45 行第 29 列
  • 非常感谢,我一直在自责,因为我的电脑太慢了,而且我看到了调试。是时候升级我的东西了。
  • Option Strict On 不是 VBA,是吗?
  • @Jean-François Corbett 不,它是 VB.NET,为什么这个问题被标记为“VBA”?

标签: vb.net


【解决方案1】:

这个错误是不言自明的。 txtCustNameForm1 中使用,但未定义。您需要先定义变量,然后才能使用它,语法如下:

Dim txtCustName As Textbox

您的表单上是否存在txtCustName(我假设它是Textbox)?如果没有,请创建它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多