vb2Py

  VB Classes
Python equivalents of VB's class modules

QuickLinks

VB keywords

VB control structures

Subroutines and Functions

Error Handling


 
  Home
  News
  Downloads
  Documentation
  Screenshots
  Online Version
  Links
  Contribute
  Wiki
  Forum

Simple Example - Public all round

VB Code in class module "A"

Public attr1, attr2, attr3

Public Subroutine method1
End Sub

Python Code
class A :
    def __init__(self):
        self.attr1 = None
        self.attr2 = None
        self.attr3 = None

    def method1(self):
        pass

Harder Example - Some Private

VB Code in class module "A"

Public attr1, attr2, attr3
Dim attr4, attr5

Public Subroutine method1
    If Cond Then method2
End Sub

Private Subroutine method2
    method1 attr1, attr4, 10
End Sub

Python Code
class A :
    def __init__(self):
        self.attr1 = None
        self.attr2 = None
        self.attr3 = None
        self.__attr4 = None
        self.__attr5 = None

    def method1(self):
        if Cond: self.__method2()

    def __method2(self):
        self.method1(self.attr2,
                     self.__attr4,
                     10)

 

Tough Example - Properties

VB Code in class module "A"

Private m_attr1

Public Property Let attr1(newval)
    m_attr1 = newval
End Sub

Public Property Get attr1()
    attr1 = m_attr1
End Sub

Python Code


class A :
    def __init__(self):
        self.__m_attr1 = None

    def let_attr1(self, newval):
        self.__m_attr1 = newval

    def get_attr1(self):
        return self.__m_attr1

    attr1 = property(let_attr1, get_attr1)


 

Another Example - Iterable Classes

VB Code in class module "A"

Private mCol as New Collection

Public Property Get NewEnum() As IUnknown
    Set NewEnum = mCol.[_NewEnum]
End Property

Python Code


class A :
    def __init__(self):
        self.__mCol = {}

    def __iter__(self):
        return iter(self.__mCol.values())

    SourceForge.net Logo