car with vb luggage towards python road

Python for VB programmers

In this blog, I’ll show you how you can help VB programmers to transition to (or understand) Python.

Function

To get a VB programmer to “map” concept and keywords in Python, here’s a simple guide that you can use:

  • def is to function
  • varname:vartype is to varname as vartype
  • -> vartype is to as vartype

And here’s a simple example to illustrate that mapping I just gave:

Python implementation
VB.Net implementation

Knowing this mapping makes it simple, right? They’re practically the same, just some minor implementing differences.

Class

Now, let’s go to a more complex comparison — class.

Python and VB(Net) share common concepts like:

  • class (level) variables (data/attributes) [and/or methods]
    • in VB, this is implemented using the “shared” keyword
  • instance (level) variables [and/or methods]
    • the “self” in Python is implemented as “Me” in VB
  • local (level) variables
    • in both languages, they are not associated with either class or instance and exists within the block/function

Class-level data and/or methods are accessible even without an instance of that class. There are specific reasons for doing this so be sure you don’t abuse it — know when and why.

Python implementation

Here’s a demo of a Python class and how it implements the 3 levels of access:

VB.Net implementation

And here’s the similar (conceptually), albeit longer implementation using VB.Net

Congratulations!

If you understand this, then you should be able to transition easily from VB to Python.

Share this to others that might be struggling to bridge the gap between VB and Python.

Source Codes

If you want to try them out, I uploaded the codes to my Git account:

https://github.com/vegitz/codes/tree/master/0047%20Python%20for%20VB%20programmers

Leave a Comment