Showing posts with label VB6. Show all posts
Showing posts with label VB6. 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! 


20200930

Mandelbrot set

I've known about the Mandelbrot set and have been familiar with its general shape for years, but have hitherto thought the maths behind it would too hard for the likes of me. Until I started following the Youtube channel mathologer and this video in particular:



Armed with Burkard Polster's simple explanation I wrote a program in VB6. It runs painfully slowly but at least it proves that the concept was not beyond a simple mind like mine. Here are a few screen-shots from my program.  Each one took a minute or so to draw.






If you were presented with images like these without any notion of how they were formed you might conclude that, like the existence of a watch begs a watch-maker, there must have been a designer, and a pretty good one at that because you can zoom into the patterns indefinitely - in short it is a fractal. And yet the Mandelbrot set (which incidentally properly is the black region: the frilly halo is an indication of how close you are to being in the set, and the colours are somewhat arbitrary) comes about because of the simple iterative formula below in which z is a complex number.  If after repeated iterations the modulus of z exceeds 2, then c is not in the set.  And then you plot the set in the complex plane (aka Argand diagram) and that's it. Easy.


I'm reading a book "Homo Lapsus". Whilst I have not yet finished it, the author, who largely accepts the theory of evolution, mentions the evolution of language. Hitherto I had never considered that evolutionists would get their dirty hands on language. Next they'll be onto music which puzzles them because it does not appear to have any evolutionary advantage. She points out that there are many theories as to how language (the skills of which, along with music, sets humans radically apart from all other animals) evolved. Basically no-one knows. But one guy Nome Chomsky believes that language arose instantaneously in humans through a single mutation. That the area in the brain that has been identified as being responsible for language suddenly came about by that mutation. How whacky is that? Niamh's reticence about the evolution of language does not appear to extend to other marvels such as the oft quoted evolution of the human eye. On this subject one site says according to one scientist’s calculations, if the eye improved just 0.005 percent each generation, it would take 364,000 years from eyes to evolve from a patch of light sensitive cells to the complex eyes we have today. But what a facile and nonsensical statement! The only meaning I can thing he attributes to 0.005% is that he wants us to think it is a very small amount.  So now we have: if the eye improved a small amount every 30 years or so it would take...  which is totally meaningless. And having got this far in the book, my author shows herself to be well versed in evolutionary theory but her arguments have so far had the opposite effect to endearing me to that theory. Not that I go along necessarily with the fundamentalist Christian views of a literal six day creation, either. 

I hate the fighting that goes on between evolutionists and the rest of us: apparently the retina is "wired backwards" so that the photo-sensitive rods and cones are behind all the wiring of nerves and I suppose blood vessels. Evolutionists like Dawkins have made fun of intelligent design advocates pointing out that no designer in their right mind would make a retina like that. But more recently scientists are finding out that there is a reason. There are many websites dealing with this for example here.

I hear you asking - so what do I think happened? Well, to be honest, the older I grow the more I realise that I don't know much about anything.  I wasn't there, I don't know anybody that was, and even if I did I couldn't trust their word or my memory.  You may recall that, as a child, I saw an angel standing tall, wings and all, on a chimney opposite my bedroom window. Was it real, a vision, a dream?  I suspect a dream but I don't know. My memory of the angel is vivid enough but of the circumstances I now have no idea. And, other than the experience sticking in my memory, I am not aware of any other benefit it has conferred. 

So much I do not know, but I do know when I smell something wacky. Mind, I don't dismiss an idea just because it is whacky - just that I treat it with the caution it deserves. I don't know about evolution with its millions of years, or about young-earth creation, except that I have noted numerous whackies in both camps, like the Nome Chomsky one above. And should Christians celebrate pagan Christmas? I'm not convinced either way, I don't know.  There is so much fake news on the internet, so many theories about this and that. I don't know what to make of so many, except when I smell a rat. I was brought up in a Christian family and gladly accepted what I was taught about salvation but now, frankly, I am even wobbly about the existence of God himself. I cry constantly for revelation on that one. Sure, I see the arguments (on both sides) but I think a little more is required than consent.

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.