views:

35

answers:

2

I copied the exact codes from my textbook and I have the following errors.

Error   3   'txtOutput' is not declared. It may be inaccessible due to its protection level.    C:\Users\Woong-Sup\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb    13  17  WindowsApplication1

Error   4   'txtOutput' is not declared. It may be inaccessible due to its protection level.    C:\Users\Woong-Sup\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb    15  17  WindowsApplication1

Error   1   Handles clause requires a WithEvents variable defined in the containing type or one of its base types.  C:\Users\Woong-Sup\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb    2   44  WindowsApplication1

Could anyone please tell me what the problem is? And I would appreciate if I could add you on my msn and ask some more questions! thanks

Public Class Form1
    Private Sub btnDisplay_Click() Handles btnDisplay.Click
        Dim anyDate As Date
        anyDate = CDate(InputBox("Input a date. (mm/dd/yyyy)"))
        ShowCentury(anyDate)
    End Sub

    Sub ShowCentury(ByVal anyDate As Date)
        Select Case anyDate
            Case Is >= #1/1/2000#
                txtOutput.Text = "twenty-first century"
            Case Is >= #1/1/1900#
                txtOutput.Text = "twentieth century"
            Case Else
                txtOutput.Text = "prior to the twentieth century"
        End Select
    End Sub
End Class
A: 

txtOutput should be a textbox on your form (form1 above)

Mitch Wheat
I still have the same errors... :( sorry, I am a noob and I know the problem is something very simple.
Woong-Sup Jung
Have you added a textbox to form1 in design mode?
Mitch Wheat
Yes I did, and it does nothing to it.. :( Could somebody add me on msn and help me a little please? [email protected]
Woong-Sup Jung
A: 

This is a partial class; it won't stand on its own. The "Form1" form this class is a part of (you do have a form named "Form1", right?) needs a button named "btnDisplay" and a textbox named "txtOutput".

If you have such a form, and the above controls exist on it, ensure that the "GenerateMember" property is set to True for both of them.

cHao
Oh! i will try it. :)
Woong-Sup Jung
You mean AccessibleName, right? I changed it and I set the "GenerateMember" property to True for both of them as you told me, but it still has the same problems.. :(
Woong-Sup Jung
Just so we're not missing anything stupidly obvious...your form is called "Form1", right? (If it's not, VB will probably still generate the form class, but your code won't be a part of it -- it'll just be an extra class.) And no, i don't mean AccessibleName -- that's for accessibility stuff (ie: helping blind people and such), and shouldn't affect whether the controls appear in code.
cHao
I changed btnDisplay to Button1 and txtOutput to Textbox1, and it seems to work!! thank you so much!! :)
Woong-Sup Jung
Each control has a name property, usually called "(Name)" in the designer. That's the name i mean.
cHao
Oh okay! good information, I will give it a try. Thanks again! :)
Woong-Sup Jung