Cool Visual Basic
 
Main
Frequently Asked Questions
VB Helpdesk
Message Boards
Library
Downloads
View Guestbook
Add to Guestbook
Product Reviews
Bookstore
Links
Newsgroups
Vendors
Affiliates
Cooltech.org

Cool VB FAQ


Text Format

The best Visual Basic FAQ(Frequently Asked Quesitions) file on the internet. Do you have a problem that's got you stumped? Do you have the answer to one? We've done our best to make this the best resources for the questions and the answers. Post a question, or a answer to one, by sending email to VBQA@beadsandbaubles.com.

      Root

            Classes(Object-Oriented Programming)

  • How can I pass multiple parameters to a property let procedure?

    Let's say I've two (2) string member variables defined as follows:

          Private m_s1 As String
          Private m_s2 As String
    
    I want to create a procedure to "set" these variables in the "TheClass" class and so I code
          Public Property Let  SetVals(ByVal sStr1 As String, ByVal sStr2 As
      String)
              m_s1 = sStr1
              m_s2  = sStr2
          End Property
    
    In the General Declaration on my form I code
          Dim MyClass as TheClass
    
    During Form Load I code
          Set MyClass = New TheClass
          MyClass.SetVals ("AA","BB") ' And god knows how many variations!!
          .
          .
    
    No matter what variation on MyClass.SetVals I use (= sign, (), etc.) I get either compilation or run-time errors.

    Compatibility:VB3  VB4  VB5

    You *can* do this, but not the way you think. It works like this:

                SetVals("AA") = "BB"
    
    It's kind of odd, because the first param is what is on the left side of the assignment(=), and the rest are contained in the params. Like this:
                SetVals(Param2,Param3,Param4) = Param1
    
    However, I would implement your class like this:
          Private m_s1 As String
          Private m_s2 As String
          Property Let  s1(ByVal sStr1 As String)
              m_s1 = sStr1
          End Property
    
          Property Let  s2(ByVal sStr1 As String)
              m_s2 = sStr1
          End Property
    

     

     

  • How can I create a class member that is public to other files in my project but private to the world?

    Compatibility:VB3  VB4  VB5

    Use the Friend keyword.

     

     

  • How can I create a stack class with the least amount of code?

    Compatibility:VB3  VB4  VB5

    Try this code:

    Dim m_Collect As New Collection
    
    Property Get Count() As Long
      Count = m_Collect.Count
    End Property
    Public Sub Push(i As Variant)
      m_Collect.Add i
    End Sub
    
    Public Function Pop() As Variant
      If m_Collect.Count = 0 Then Beep: GoTo exiter
      Pop = m_Collect(m_Collect.Count)
      m_Collect.Remove m_Collect.Count
    exiter:
    End Function

     

     

    LinkExchange
    LinkExchange Member Free Home Pages at GeoCities


    Copyright 2000, David J Berube<Form1@aol.com>. All Rights Reserved.