Results 1 to 4 of 4

Thread: So simple.....but can't do it ...sheeeeee

  1. #1

    Thread Starter
    Lively Member abhaybakshi's Avatar
    Join Date
    Dec 2001
    Location
    Mumbai (INDIA)
    Posts
    81

    Red face So simple.....but can't do it ...sheeeeee

    hello intelligent people,

    Simple problem.....

    I have a class (compiled it to make dll).

    It has one property (nm) and one method (rtn).

    I am setting this property as "abhay" in my code, which will get converted to "ABHAY". (simple Ucase function).

    Now, i want to display a messagebox saying "Got abhay" if
    value of nm is "ABHAY".

    Problem is, method rtn in class is not getting value of property nm.

    Little jumbling? c the code below.

    CLASS CODE

    Public Property Get nm() As String
    nm = myname
    End Property

    Public Property Let nm(ip As String)
    myname = UCase(ip)
    End Property

    Public Sub rtn()
    If ip = "abhay" Then
    MsgBox "got it"
    End If
    End Sub

    Follows is a code, where i set property of nm.

    CODE

    Private Sub Command1_Click()
    Dim ab As New nmclass
    ab.nm = "abhay"
    ab.rtn
    End Sub
    Money is a great thing, but it can't purchase satisfaction....
    Respect money, but don't allow it to control you...

  2. #2
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    In your rtn sub:

    Public Sub rtn()
    If ip = "abhay" Then
    MsgBox "got it"
    End If
    End Sub

    you are checking ip, but that is just a parameter of the other functions. Shouldn't that be:

    Public Sub rtn()
    If myname = "abhay" Then
    MsgBox "got it"
    End If
    End Sub


    ?
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  3. #3
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    If you had 'Option Explicit' at the very top of your code, you'd have seen this for yourself, as it would have reminded you that in the second sub, ip had not been declared.

    Always use Option Explicit.
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  4. #4
    Addicted Member
    Join Date
    Feb 2002
    Posts
    242
    Private Sub Command1_Click()
    Dim ab As New nmclass
    ab.nm = "abhay"
    ab.rtn
    End Sub


    It looks like you arent properly setting your class. I could be wrong, but try this code:

    [code]
    Private Sub Command1_Click()
    Set ab = New nmclass
    'etc, etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width