Softstuff Consulting
My occasional musings of a technical nature
  • Send us a message
  • About Softstuff Consulting
  • Privacy Policy
  • Main Website
Thoughts , VBScript , Visual Studio , Windows

Lets not forget VB script

by Ian Blair May 6, 2020 No Comments

I fondly remember Visual Basic, not the new shiny .NET version, but the old VB6 that was an excellent way to build applications, but was always a bit of a pain to install them afterwards as sometimes I would find myself disappearing down the ActiveX regsvr32 version rabbit hole.

But fortunately VB6 sort of lives on in VBScript and best of all you can run VB Script files directly by double clicking them in Windows 10.

Normally if I need to automate something I would see if it could be done with a batch file, or PowerShell script and if necessary get Visual Studio out and write the extras I need as one or more console applications, but it struck me that its possible that some of the things could be done in VBScript, and just put together in Notepad rather than full Visual Studio.

As a quick experiment and as it is Wednesday I thought I would knock together a small script that will do a bit of number juggling randomly and pick tonight’s lottery numbers. It took me just a couple of minutes to put together including a moment or two to refresh my memory on VB syntax, but it simply creates an array of numbers, loops around swapping them randomly and then displays the first six number in the array in a message box.

For reference the numbers it picked was 1, 13, 22, 29, 43, 57.

Option Explicit
Randomize
Dim numbers(59)
Dim x,y,z,temp
For x=0 to 59
 numbers(x)=FormatNumber(x,0)
next 

For x=0 to Rnd * 10000000
   y=Rnd * 59
   z=Rnd * 59
   temp=numbers(y)
   numbers(y)=numbers(z)
   numbers(z)=temp  
next



MsgBox "Numbers " + numbers(0) + "," + numbers(1) + ","+numbers(2) + "," +numbers(3) + ","+ numbers(4) + "," + numbers(5),vbOkOnly,"Numbers"

The code is really simple, and it was written in notepad and saved to my desktop as lottery.vbs and runs when I double click it.

VB Script has the advantage that it can access external libraries, and registry entries and also write back to the file system making it useful to automate lots of general housekeeping tasks.

The above code was just a bit of fun, but it might be worth digging out your old Visual Basic 6 knowledge and using VBScript for some small but repetitive system tasks.

Proof of ConceptTasksVBScript

  • Previous Bootstrap dialogs and AJAX calls to delete records in Dot Net Core.3 years ago
  • Next Make using Windows for people with eyesight issues easier3 years ago

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How to make your Powershell scripts more annoying
  • What motherboard is in my PC
  • A Dynamics365 plugin thought experiment
  • Registering a Dynamics365 plugin and I get an error
  • Going back in time with Dynamics365

Categories

  • Bootstrap
  • C#
  • CSS
  • Dot Net Core
  • Dynamics365
  • JavaScript
  • Powershell
  • T-SQL
  • Thoughts
  • VBScript
  • Visual Studio
  • Windows
  • Xamarin

Recent Comments

  • S0ftStuffB055 on Call a Dynamics365 workflow from JavaScript
  • Siva on Call a Dynamics365 workflow from JavaScript
  • TC Sharpe on Throw exceptions in Dynamics365 workflow plugins, or don’t
  • BigOwl on Throw exceptions in Dynamics365 workflow plugins, or don’t
  • CRMGod on Access a Dynamics365 embedded webresource

Archives

  • January 2021
  • May 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • June 2019
  • May 2019
  • February 2019
2023 Softstuff Consulting. Donna Theme powered by WordPress
  • Twitter