2011-09-13 60 views
-6
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 
+0

什麼行(不是行號!)是與之相關的錯誤? –

+0

錯誤'txtCustName'未被聲明。由於其保護級別,它可能無法訪問。 Line 45 Colum 29 – TheBetterJORT

+0

再次閱讀我的評論。 –

回答

1

錯誤是不言自明的。 txtCustNameForm1中使用,但沒有定義。你需要定義變量,然後才能使用它,在語法,如:

Dim txtCustName As Textbox 

是否txtCustName(這我假設,就是要一個Textbox)表單上存在?如果沒有,創建它。