明天考试题,请各位大哥帮帮忙,谢谢!!!!
.为VB工程中添加名为Person 的类;
2.该类有两个公有属性MyName、MyAge,其数据类型分别为string类型与intetger类型;
3.该类有ShowMessage函数,返回类型为string类型,返回值形式为:"我叫***,今年**岁. ",其中**分别用该类的MyName与MyAge属性值代替。
4.对象变量的使用
   窗体Form1的标题为"用对象编程";
   在窗体Form1中声明窗体级公有变量P1(Person类型);
   在窗体Form1 的Load 事件中为对象变量P1 创建实例;
   按样文5-1B, 窗体Form1上添加文本框控件txtName、txtAge;三个CommandButton命令按钮,按钮显示的文本信息分别为"赋值"、"显示信息"、"退出";一个Label的标签lblShow;
   为"赋值"命令按钮添加鼠标单击的处理代码,该代码实现把txtName、txtAge的值分别赋值给P1的MyName、MyAge属性;
   为"显示信息"命令按钮添加鼠标单击的处理代码,该代码调用P1的ShowMessage函数,并把返回值显示在lblShow中。

解决方案 »

  1.   

    ''''''''''''''''''''''''''''''''''''''''''''Person类定义
    Option Explicit'local variable(s) to hold property value(s)
    Private mvarMyName As String 'local copy
    Private mvarMyAge As Integer 'local copy
    Public Function ShowMessage(MyName As String, MyAge As Integer) As String
        ShowMessage = "我叫" & MyName & ",今年" & Str(MyAge) & "岁"
        
    End FunctionPublic Property Let MyAge(ByVal vData As Integer)
    'used when assigning a value to the property, on the left side of an assignment.
    'Syntax: X.MyAge = 5
        mvarMyAge = vData
    End Property
    Public Property Get MyAge() As Integer
    'used when retrieving value of a property, on the right side of an assignment.
    'Syntax: Debug.Print X.MyAge
        MyAge = mvarMyAge
    End PropertyPublic Property Let MyName(ByVal vData As String)
    'used when assigning a value to the property, on the left side of an assignment.
    'Syntax: X.MyName = 5
        mvarMyName = vData
    End Property
    Public Property Get MyName() As String
    'used when retrieving value of a property, on the right side of an assignment.
    'Syntax: Debug.Print X.MyName
        MyName = mvarMyName
    End Property
    ''''''''''''''''''''''''''''''''''''''''''''''''Form窗体代码
    Option Explicit
    Dim P1 As New PersonPrivate Sub cmdExit_Click()
    Unload Me
    End SubPrivate Sub cmdSet_Click()
    If Trim(txtName) = "" And Trim(txtAge) = "" Then
        MsgBox "请输入姓名和年龄"
    Else
        P1.MyName = txtName
        P1.MyAge = Val(txtAge)
    End If
    End SubPrivate Sub cmdShow_Click()
        lblShow.Caption = P1.ShowMessage(txtName, txtAge)
    End SubPrivate Sub Form_Load()
        Form1.Caption = "用对象编程"
        Set P1 = New Person
        P1.MyName = "qjwxsd"
        P1.MyAge = 23
        
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        Set P1 = Nothing
    End Sub
      

  2.   

    学VB一年多了还是找不到工作,家里人都叫我不要学VB了,改学CAD,但学VB这么久了,觉得放弃有点可惜不知道该怎么办,我在一家公司编过一个仓库管理系统,但很久了找不到工作,不知道该怎么办,哪位出出点子该怎么办?