Showing posts with label visual basic. Show all posts
Showing posts with label visual basic. Show all posts

20201115

Love hate Python

There was Visual Basic 6 (VB6)... and then there was Python.  Both are interpreted languages (i.e. they run from a high-level script rather than being compiled into machine code). Both claim to be easy to program with and both have a huge following. Python is current whereas VB6 is no longer supported.  Python is free whereas Microsoft have made VB6 neither free nor available but say that it is superseded by VB.NET.  But these are very different languages. Having sharpened my teeth on plain BASIC (e.g. BASIC PLUS in college days, QuickBASIC running under MSDOS) I progressed to VB6 which I used extensively for creating test software to exercise electronics I have designed in the course of my work.

In case I ever have the privilege of helping homeschoolers here with teaching computer science, I figured I ought to learn a current language. I did a bit in C# a few years back for a work project and, whilst C# is a very powerful language (meaning you can do certain complex things with minimal coding), I found its syntactical gamut too much for my poor brain. So, what more suitable to up-and-coming programmers than Python, or so I have been told?

Many years ago I authored some QuickBASIC code that would display prime numbers in a square spiral.  The essential part took a mere 20 lines of script, and here's the output, limited to the VGA 640x480 screen resolution of the day with each integer represented by a single pixel. You can click on each image to zoom in.



The point of the program, apart from being an exercise in graphical output and being cool, is to highlight the mainly diagonal line patterns that prime numbers arranged in this way make. Anyway, this became my first Python challenge.

Here's the output of my Python code - a bit prettier because now each integer is represented by a 4 x 4 pixel square. Value 1 is plotted as a blue square, otherwise primes are red and non-primes grey. The essential part was almost 100 lines of code and took a long time to code. OK, so I am a novice but even so...  I tested it with three different algorithms for finding the primes - the fastest involved saving the primes in a Python list.


And here's the same in VB6.  It was so much easier to do the graphics part in VB6.  Python graphics is anything but intuitive and seems to employ the longest path to achieve the least credible results, whereas in VB6 you simply drag and drop graphic widgets and then click on them to open their respective code space. That they are event driven is taken for granted unlike Python.



Oh, and although no-one on ever claimed VB6 was fast, without pausing to do animated screen redraws I found my VB6 code ran about twice as fast as with Python.  I tried different prime algorithms but found the VB6 code ran fastest by dividing each integer numerator by all the denominators from 2 up to the square root of the numerator, which for large integers involves many more test divisions than did my Python code. That VB6 was still significantly faster says something in its favour.

And then, although Python is an interpreted language like VB6 or QuickBASIC, it has no native integrated development environment (IDE) so testing and debugging entails constant swapping between your chosen text editor (I used Notepad++) and the command line.  Although there are 3rd party IDE's and I am currently investigating Microsoft "Visual Studio Code" which, surprisingly, is free.

So do I love Python? Well, not yet, certainly! 


20150117

Basic

The beauty of Microsoft's QuickBasic was that you could use it almost as easily as a desk calculator for evaluating simple expressions, whilst at the same time it was a fully fledged programming language capable of running business applications. That I know because I wrote one that got used in a number of hotels without fault for many years.

The closest I have found that will run on a Windows computer is Just Basic which can both emulate the DOS based QuickBasic and can create a Windows GUI. With it you can write a one line program like

PRINT "My fish pie was as big as "; asn(1)*2

Just Basic is a subset of Liberty Basic which you will need to upgrade to only if doing serious stuff. I like their business model: Just Basic is offered totally free even for commercial applications and has no silly restrictions. Or you can get the paid for Liberty Basic which adds a few important extras for a very moderate sum.

The beauty of Visual Basic (VB6) is that creating a Windows GUI program is a doddle. Not quite as easy as QuickBasic but almost. For example, if you want to write a FOR loop to evaluate the Gregory–Leibniz series to an arbitrary number of iterations...



which converges rather slowly to Pi...

in QuickBasic this might be

for n=0 to 100
    pi = pi + ((-1)^n) * 4/(2*n + 1)
next

whereas in VB6 you will have to add to this code a Form (aka Window) onto which you drag a Text-Box or Label to display your result. And name and save the Form and Project source files.

Things only get more difficult with VB.NET. The simplest program, one that prints "Hello World", requires all of:

Imports System
Module Module1
   Sub Main()
      Console.WriteLine("Hello World")
      Console.ReadKey()
   End Sub
End Module

You cannot even easily port your VB6 code to VB.NET. And you are forced to install the bloated .NET framework. Serious programmers claim that VB.NET is much more powerful but I reckon that most of us want ease of use more than power, especially when the "power" being talked about is all about multi-threads and objects and inheritance and stuff that, frankly, we never needed back in those days when they used computers to send men to the moon.

David Platt says it all in his article "The Silent Majority: Why Visual Basic 6 Still Thrives" in MSDN Magazine. If we can believe him then it looks like VB6 is here to stay a while longer. I can testify that it runs under Windows 8.1 although there are a few problems in the editor. But this, I have learnt, is to be expected.

I hope, I hope that Microsoft continue to keep new operating systems backwards compatible with software that people actually use, rather than software that Microsoft want people to use. Like VB6. And another example is Word 97 which does almost everything I want of a word processor and which I therefore still use.

Sorry if I come across like I have a 'B' in my bonnet. I guess I have! But there is an old adage that goes "if it ain't broke then don't fix it".

P.S. Have just found VB6 Zone blog which records that Microsoft have agreed that "VB6 is awesome" and will at least continue to support VB6 runtime until 2024. This is good news indeed.

20140708

Do you see three

I am using an Active-X control within Visual Basic. The control takes a string input and outputs a barcode image. The barcode is capable of encoding binary data. The literature that comes with the control says "The data to be encoded must be represented in the form of a string and it is impossible to represent binary data in a string."  Clearly they are using the 'C' language or a derivative, how else could they state such utter nonsense? Why else would they come up with such a contrived and convoluted arrangement of escape characters to send the dreaded-in-'C' null character? Why make the world more complicated than it already is?  Why refute occam's razor?

Thankfully Visual Basic is relatively sane when it comes to data storage. It offers a choice of fixed length strings (in which n bytes of arbitrary binary data include null aka 'chr(0)' occupy exactly n bytes of memory - how can you do better than that?) or variable length strings, and a wealth of string functions which accept either variant.