Category: Visual Basic
-
Decimal to Binary functions in Visual Basic
Here are functions to perform decimal to/from binary conversion. CBin – converts a decimal integer to binary string. CDeci – converts a binary string to decimal integer. CBinS16 – converts a decimal signed integer to 16 bit binary string. CdecS16 – converts a 16 bit binary string to decimal signed integer.
-
SQL Server Quickest way to Insert Multiple Rows with VB
Having to parse huge amounts of data from xml files to an SQL Server database, I needed to greatly optimise my code. Here are some tests to insert 10000 rows into table TABLETESTER. First, using the standard INSERT INTO without specifying column names. TickCount of 70547. Specifying the column names is actually marginally faster. TickCount…
-
Visual Basic 6 – quickest way to find first/last character in string
When you are parsing large amounts of data, the way you code string matching can make a huge difference. In one case I needed to find if a string was contained within quotes, here are the test results from quickest to slowest. The test situation was to find if the last character in the string…
-
Base64/sexatrigesimal encoding/decoding in VBA/VB6/Visual Basic
Here is an implementation of Base 36 enconding/decoding functions is VB6.
-
eventquery.vbs – ERROR: Unable to execute the query for the…
If you received this error when trying to execute eventquery.vbs the cause is an overflow of events past 32,767 (the maximum capacity of a VB6 Integer). There is a very simple fix for this which is to change the data type from an Integer to a Long (which has a maximum capacity of 2,147,483,647). In…
-
Longest Common Subsequence implemented in VBA (Visual Basic for Applications)
From Wikipedia, The longest common subsequence (LCS) problem is to find the longest subsequence common to all sequences in a set of sequences (often just two). The following is a VBA implementation of this problem. The following functions are included; String functions; longestCommonSubsequence – calculate an LCS array. backTraceUp and backTraceLeft – trace back either…
-
Get the parameters/arguments being called to an executable
Lets say you have some program ‘A’ that has no documentation and no help files but is being executed by some program ‘B’. You want to run program ‘A’ is individually, but you need to know what parameters/arguments are being passed from program ‘B’. The following executable will help. Replace program ‘A’ (temporarily) with the…
-
Optimizing/faster String Concatenation in VBA
There are numerous links about Visual Basic string concatenation, one particular is Microsoft’s How To Improve String Concatenation Performance. But the article is overwritten for the point it is trying to make, so I will share a simplified example. Lets say we want to perform the following concatenation: This takes approximately 6000 ticks. The faster…
-
Word Minimize/Maximize event capture VBA
Here is a quick little post outlining how to create a minimize/maximize event routine. Add the following code to a class named EventClassModule and then add the following code under ThisDocument
-
VBA automatically saves Excel 2003 Workbook in compatibility mode as Excel 2007 Workbook
Lets say you have a neat little Excel 2003 macro, when you run your macro in Excel 2007, Excel runs it in Compatibility Mode, and any benefits (such as the 16384 columns) you were hoping to use are still unavailable. So how can we enable these benefits depending on the Excel version? Simply by including…