lg Function in Visual Basic - vba

this is an very odd question.
I have a client, which needs an updated version of his program. He gave me all the old files, told me it was an Visual Basic Program, from 1995.
As I am born in 2002, I did not realize that Visual Basic did not even exist back then.
Anyway, the syntax seems to be the same
VERSION 2.00
Begin Form REDACTED
BackColor = &H00C0C0C0&
...
Dim ja
Dim lwi1(6) As Double
Dim lwaa(6) As Double
Dim lwa(6) As Double
Dim rr(6) As Double
Then I saw the following line
zwert1 = lg(1# - x) / lg(1# - xcr)
And tried to find the documentation for lg().
After searching for about an hour I gave up. I think its log(), but im not sure, and also I'm confused what kind of language this is written in, there are some PowerPascal (??) files dated in 1989, and the filetype of the cited code is '.frm'.
I feel like I am in a museum, without documentation or a guide.
Can anyone help me figure out what language this is, and what lg() achieves?

It probably is log10 of Visual Basic 4: Logarithm(log, lg, ln)
Here's a substitute for VBA:
Public Function Log10( _
ByVal Value As Double) _
As Double
' Returns Log 10 of Value.
' 2015-08-17. Gustav Brock, Cactus Data ApS, CPH.
Const Base10 As Double = 10
' No error handling as this should be handled
' outside this function.
'
' Example:
'
' If MyValue > 0 then
' LogMyValue = Log10(MyValue)
' Else
' ' Do something else ...
' End If
Log10 = Log(Value) / Log(Base10)
End Function

Related

Reading the PrtDevMode structure

I tried to read the Report.PrtDevMode property using the appropriate structures. If I do a Unicode conversion on the string I get closer, but the values still don't seem correct.
I expect to see intOrientation = 2 and strDeviceName = "C552 Color" and a paper size of 11x17.
I am testing on Windows 10 and Server 2008 with Microsoft Access 2010 (32-bit)
What I have Tried
A simplified copy and paste from the help file:
Private Type str_DEVMODE
RGB As String * 94
End Type
Private Type type_DEVMODE
strDeviceName As String * 32
intSpecVersion As Integer
intDriverVersion As Integer
intSize As Integer
intDriverExtra As Integer
lngFields As Long
intOrientation As Integer
intPaperSize As Integer
intPaperLength As Integer
intPaperWidth As Integer
intScale As Integer
intCopies As Integer
intDefaultSource As Integer
intPrintQuality As Integer
intColor As Integer
intDuplex As Integer
intResolution As Integer
intTTOption As Integer
intCollate As Integer
strFormName As String * 32
lngPad As Long
lngBits As Long
lngPW As Long
lngPH As Long
lngDFI As Long
lngDFr As Long
End Type
Public Sub CheckCustomPage()
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
Dim intResponse As Integer
' Opens report in Design view.
DoCmd.OpenReport "rptNavigationPaneGroups", acDesign
Set rpt = Reports("rptNavigationPaneGroups")
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
' Gets current DEVMODE structure.
' (I added the StrConv function)
DevString.RGB = StrConv(strDevModeExtra, vbUnicode)
LSet DM = DevString
' List the device name.
If DM.strDeviceName <> rpt.Printer.DeviceName Then
Debug.Print "Found: '" & DM.strDeviceName & _
"' instead of '" & rpt.Printer.DeviceName & "'"
End If
End If
Set rpt = Nothing
End Sub
If I use the vbUnicode conversion, I get this output:
Found: 'C552 Color ”-é/ '
instead of 'C552 Color'
Without the conversion, the name is completely unreadable:
Found: '????? ?? A?A?????? ?'
instead of 'C552 Color
I reviewed numerous articles, documentation, and posts describing the usage of the .PrtDevMode property and associated structure.
I compared the structure type with examples in the help file, online documentation, and other sources, but I don't find any examples that involve Unicode conversion, which seems like it might be a piece of the puzzle.
I could use the .Printer object to retrieve many of these properties, but I understand that some settings like the Media Type are only available through the PrtDevMode structure (which is designed to mirror the Win32 SDK).
I could resort to using API calls to query the system printers, but this doesn't solve the problem of needing to write the structure back to the report print settings.
Using this structure would also help me to serialize this data in a readable format so that it can be stored in version control, and written back to the report after the database is rebuilt from source files (which is my ultimate goal).
Any non-null pointers in the right direction?
After further testing, I was able to get it working this morning. As I suspected, I was close on the Unicode conversion, but there were three important modifications that made the difference.
First, I needed to declare the two strings as byte arrays, not simply string buffers. While the string buffer works with the winspool.drv API calls, reading the Report.PrtDevMode property works better with a byte array.
Private Type type_DEVMODE
strDeviceName(1 To 32) As Byte ' <--- Byte array
'strDeviceName As String * 32
intSpecVersion As Integer
intDriverVersion As Integer
intSize As Integer
...
The second part was that the conversion from Unicode needs to be performed only on the string values, not the entire structure.
' Read the string values from DevMode structure
strDevice = NTrim(StrConv(dm.strDeviceName, vbUnicode))
strForm = NTrim(StrConv(dm.strFormName, vbUnicode))
Thirdly, the string is a null-terminated string, so it needs to be trimmed at the null character after the conversion from Unicode.
'---------------------------------------------------------------------------------------
' Procedure : NTrim
' Author : Adam Waller
' Date : 5/15/2020
' Purpose : Trim a null-terminated string.
'---------------------------------------------------------------------------------------
'
Public Function NTrim(strText) As String
Dim lngPos As Long
lngPos = InStr(1, strText, vbNullChar)
If lngPos > 0 Then
NTrim = Left$(strText, lngPos - 1)
Else
NTrim = strText
End If
End Function
With these three changes, I am now able to read the .PrtDevMode property with the expected values. Hopefully this will be helpful for someone else out there as well!
If you find that it works differently on your system, or have additional input, please feel free to leave a comment!

UDF using Evaluate to write to additional cells is unpredictable

I'm reluctant to ask questions about UDF's designed to write to other cells since, by design, this behavior is supposed to be disabled. But... I'm going to power through all the potential criticisms and ask anyway. I don't really expect to have this answered completely, so I'm just fishing for any insight into the odd behavior I'm encountering.
I have a UDF that is designed to calculate a simple bearing allowable. It takes 10 parameters. If any of the parameters are out-of-range the UDF will return "Error" in the calling cell. I wanted to one-up this rather useless feedback by listing all the offending inputs so that the user doesn't have to make a single correction one after the other. This way all the bad inputs would be listed and the user can correct all the inputs at once. FYI, there are more than 10 potential issues with the inputs due to some of the input interactions. Otherwise the user could try massaging the inputs dozens of times without success. This is why I wanted to list all the feedback at once.
The UDF: Shorthand - it sends the data to Class Module to perform all the checks and calculations.
public Function LBA(ByVal layup_string As String, ByVal diaBolt As Double, ByVal boltHead As String, _
ByVal eD As Double, ByVal tMetallicFitting As Double, ByVal tempF As Double, ByVal depth As Double, _
ByVal allowable_type As String, ByVal basis As String, ByVal cond As String) As Variant
'
' declare variables
Dim s As String
Dim val As Variant
Dim clba As New cFunc_LBA
'
' send to class constructor
clba.init layup_string, diaBolt, boltHead, eD, tMetallicFitting, tempF, depth, allowable_type, basis, cond
'
' get errors
If clba.contains_errs Then ' ............................... check for design space violattions: errors
s = clba.get_errs ' .................................... get concat string of all errors
Evaluate ("post_error_messages(""" & s & """)") ' ...... run the subroutine to post err msgs
val = "Error" ' ........................................ return value to calling cell
'
Else
'
' return a valid bearing allowable
val = clba.LBA ' ....................................... expose bearing allowable property
'
End If
'
LBA = val
End Function
The Class Module works as expected. All the calcs and error logs work. In the UDF when I check if there were errors, it returns the errors. I then send the errors (in one long concatenated string) to another subroutine that is supposed to output the errors into other worksheet cells.
The Sub:
Private Sub post_error_messages(ByVal s As String)
' declare variables
Dim arr As Variant
'
' initialize variables
arr = Split(s, ",")
'
' post error messages
For i = 0 To UBound(arr) ' .................. loop thru error messages
m.Cells(17 + i, 2) = CStr(arr(i)) ' ..... write msg in cell, increment by ROW#
Next i
End Sub
A quirk I noticed along the way... I could only get the subroutine (called by Evaluate) to accept a single parameter. Also I could only get it to accept a simple data-type string. I tried arrays, variants, scripting.dictionary none of which worked. Hence all my error messages where concatenated into one long string then split and looped over in the sub.
My problem now is that this setup is only sort of working.
Problem 1: Regardless of how many errors are returned the Sub to post error messages will only return three items. In fact it always returns three items, even if there are only two (the last one shown gets repeated). If there are 10 error messages - 3 get shown. I put debug.print statements in my error message sub so I could see what was happening and it shows that when ONLY 2 error messages are returned it should only be printing to 2 cells, but it prints to the third cell anyway. More than 3 errors just get dropped.
Problem 2: If I delete the cells in the sheet showing the error messages and execute the UDF again the messages will NOT come back. Only if I close the workbook and open it again will the error message subroutine print to the cells again (from the UDF).
Also, and this is not really a problem, Evaluate runs twice. I've looked this up and it seems to be a known issue. I'm just putting this out there, but I'm not sure this causes any issues.
Again, since I'm working outside the intended functionality of Excel's UDFs I do not expect a solution. That said, can anybody offer any insight on this?
Not an answer to your question, but this stripped-down version works OK for me:
Public Function LBA() As Variant
Dim val, s
s = "A,B,C,D,E"
Evaluate "post_error_messages(""" & s & """)"
val = "Error" '
LBA = val
End Function
Private Sub post_error_messages(s As String)
Dim arr As Variant, i
With Sheet1.Cells(17, 2)
.Resize(10, 1).Value = "" '<<< clear any previous errors!
arr = Split(s, ",")
.Resize(UBound(arr) + 1, 1).Value = Application.Transpose(arr)
End With
End Sub

Detecting Unrecognized (codepage-unicode) Characters in a string

How do you detect an unrecognized code page character in a string in vb.Net? These charaters usually show up in a default character such as "?" or a square when the current code page can not recognize the original character from some other output.
I have text fields from an external source that displays the "square" character for some long dash character (not chr(150)) and I want to be able to replace it with character code 45 (dash) to make it compatible but I can't determine how to check for the default special "unrecognized" character in a replace. I searched the net but can't find a solution to this problem! I played with System.Text.Encoding but still can get what I want. Any idea how to do this?
Thanks!
I see this question was asked quite a while ago, I figure you found the answer by now. At any rate, this is what I'm doing at the moment. I look for the specific characters I want to replace and in another array I put what I want them to be changed to. I hope this works for you.
Private Function CleanText(TextToClean As String) As String
Dim CleanedText As String = TextToClean
Dim BadText(5) As Char
Dim GoodText(5) As String
BadText(0) = ChrW(169) ' © (alt 0169, copyright)
BadText(1) = ChrW(174) ' ® (alt 0174, registered trademark)
BadText(2) = ChrW(8482) ' ™ (alt 0153, trademark)
BadText(3) = ChrW(8364) ' € (alt 0128, Euro)
BadText(4) = ChrW(176) ' ° (alt 0176, degrees)
GoodText(0) = "(c)"
GoodText(1) = "(r)"
GoodText(2) = "(tm)"
GoodText(3) = "(euro)"
GoodText(4) = "o"
For i As Integer = 0 To BadText.GetUpperBound(0)
CleanedText = CleanedText.Replace(BadText(i), GoodText(i))
Next
Return CleanedText
End Function

mid()=foo in VBS?

In VBA and VB6 I can assign something to mid for Example mid(str,1,1)="A" in VBS this doesn't work.
I need this because String concatenation is freakin' slow
Here is the actual code i hacked together real quick
Function fastXMLencode(str)
Dim strlen
strlen = Len(str)
Dim buf
Dim varptr
Dim i
Dim j
Dim charlen
varptr = 1
buf = Space(strlen * 7)
Dim char
For i = 1 To strlen
char = CStr(Asc(Mid(str, i, 1)))
charlen = Len(char)
Mid(buf, varptr, 2) = "&#"
varptr = varptr + 2
Mid(buf, varptr, charlen) = char
varptr = varptr + charlen
Mid(buf, varptr, 1) = ";"
varptr = varptr + 1
Next
fastXMLencode = Trim(buf)
End Function
How can i get this to work in VBS?
Authoritative source explicitly stating it's not available in VBScript:
Visual Basic for Applications Features Not In VBScript:
Strings: Fixed-length strings LSet, RSet Mid Statement StrConv
VBA has both a Mid Statement and a Mid Function. VBScript only has the Mid Function.
The one other option you have if you are stuck doing this in VBScript is to make API calls. Since you are already comfortable working directly with the string buffer this might not be too big a jump for you. This page should get you started: String Functions
Sorry, it looks like API calls are out, too: Rube Goldberg Memorial Scripting Page: Direct API Calls Unless you want to write an ActiveX wrapper for your calls, but we're starting to get into an awful lot of work (and additional maintenance requirements) now.
You can't do that. You will have to rebuild the string from scratch.
This is not possible, mid(str,1,1) is a function which just returns a number (str is not passed 'by reference' and is not altered).
It's never too late to suggest an answer, even to a decade-old question...
One great thing about VBScript is that even though it's a subset of VB/VBA it still lets you declare (and use) classes. And having classes implies them having properties, with getters and/or setters... if you can guess where I'm going...
So if you wrap a class around a VBA-compatible implementation of Mid(), it's actually possible to emulate Mid() statements with a Let property. Consider the following code:
Class CVBACompat
' VB6/VBA-Like Mid() Statement
Public Property Let LetMid(ByRef Expression, ByVal StartPos, ByVal Length, ByRef NewValue) ' ( As String, As Long, As Long, As String)
Dim sInsert ' As String
sInsert = Mid(NewValue, 1, Length)
Expression = Mid(Expression, 1, StartPos - 1) & sInsert & Mid(Expression, StartPos + Len(sInsert))
End Property
' VB6/VBA-Like IIf() Function
Public Function IIf(Expression, TruePart, FalsePart)
If CBool(Expression) Then
IIf = TruePart
Else
IIf = FalsePart
End If
End Function
End Class: Public VBACompat: Set VBACompat = New CVBACompat: Public Function IIf(X, Y, Z): IIf = VBACompat.IIf(X, Y, Z): End Function
VBA's language specification says that when Mid( <string-expression>, <start> [, <length> ] ) is used as a statement, what's to be replaced in the source string <string-expression> is the lowest number of characters given the entire RHS expression or as limited by the <lenght> argument, when provided. Now, you can't have optional arguments in VBScript, so if you want to be able to also use statements of the sort Mid( <string-expression>, <start> ) = <expression> you'll have to have two separate implementations.
The implementation proposed above can be checked with the following code (not including checks for error-throwing conditions, which are the same as for the Mid() function anyway) :
Dim f ' As String
Dim g ' As String
f = "1234567890"
g = f
' VB6 / VBA: Mid(f, 5, 2) = "abc"
VBACompat.LetMid(f, 5, 2) = "abc"
' VB6 / VBA: Mid(g, 5, 4) = "abc"
VBACompat.LetMid(g, 5, 4) = "abc"
WScript.Echo "First call " & IIf(f = "1234ab7890", "passes", "fails")
WScript.Echo "Second call " & IIf(g = "1234abc890", "passes", "fails")
In any case, since the proposed solution is just an emulation of otherwise native code implementations (in VB6, VBA), and still implies string concatenation anyway with the overhead of class instantiation + VTable translations, the OP'd be better off creating and making available an ActiveX component (OCX) to do concatenations in series.

Hidden features of VBA

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
Which features of the VBA language are either poorly documented, or simply not often used?
This trick only works in Access VBA, Excel and others won't allow it. But you can make a Standard Module hidden from the object browser by prefixing the Module name with an underscore. The module will then only be visible if you change the object browser to show hidden objects.
This trick works with Enums in all vb6 based version of VBA. You can create a hidden member of an Enum by encasing it's name in brackets, then prefixing it with an underscore. Example:
Public Enum MyEnum
meDefault = 0
meThing1 = 1
meThing2 = 2
meThing3 = 3
[_Min] = meDefault
[_Max] = meThing3
End Enum
Public Function IsValidOption(ByVal myOption As MyEnum) As Boolean
If myOption >= MyEnum.[_Min] Then IsValidOption myOption <= MyEnum.[_Max]
End Function
In Excel-VBA you can reference cells by enclosing them in brackets, the brackets also function as an evaluate command allowing you to evaluate formula syntax:
Public Sub Example()
[A1] = "Foo"
MsgBox [VLOOKUP(A1,A1,1,0)]
End Sub
Also you can pass around raw data without using MemCopy (RtlMoveMemory) by combining LSet with User Defined Types of the same size:
Public Sub Example()
Dim b() As Byte
b = LongToByteArray(8675309)
MsgBox b(1)
End Sub
Private Function LongToByteArray(ByVal value As Long) As Byte()
Dim tl As TypedLong
Dim bl As ByteLong
tl.value = value
LSet bl = tl
LongToByteArray = bl.value
End Function
Octal & Hex Literals are actually unsigned types, these will both output -32768:
Public Sub Example()
Debug.Print &H8000
Debug.Print &O100000
End Sub
As mentioned, passing a variable inside parenthesis causes it to be passed ByVal:
Sub PredictTheOutput()
Dim i&, j&, k&
i = 10: j = i: k = i
MySub (i)
MySub j
MySub k + 20
MsgBox Join(Array(i, j, k), vbNewLine), vbQuestion, "Did You Get It Right?"
End Sub
Public Sub MySub(ByRef foo As Long)
foo = 5
End Sub
You can assign a string directly into a byte array and vice-versa:
Public Sub Example()
Dim myString As String
Dim myBytArr() As Byte
myBytArr = "I am a string."
myString = myBytArr
MsgBox myString
End Sub
"Mid" is also an operator. Using it you overwrite specific portions of strings without VBA's notoriously slow string concatenation:
Public Sub Example1()
''// This takes about 47% of time Example2 does:
Dim myString As String
myString = "I liek pie."
Mid(myString, 5, 2) = "ke"
Mid(myString, 11, 1) = "!"
MsgBox myString
End Sub
Public Sub Example2()
Dim myString As String
myString = "I liek pie."
myString = "I li" & "ke" & " pie" & "!"
MsgBox myString
End Sub
There is an important but almost always missed feature of the Mid() statement. That is where Mid() appears on the left hand side of an assignment as opposed to the Mid() function that appears in the right hand side or in an expression.
The rule is that if the if the target string is not a string literal, and this is the only reference to the target string, and the length of segment being inserted matches the length of the segment being replaced, then the string will be treated as mutable for the operation.
What does that mean? It means that if your building up a large report or a huge list of strings into a single string value, then exploiting this will make your string processing much faster.
Here is a simple class that benefits from this. It gives your VBA the same StringBuilder capability that .Net has.
' Class: StringBuilder
Option Explicit
Private Const initialLength As Long = 32
Private totalLength As Long ' Length of the buffer
Private curLength As Long ' Length of the string value within the buffer
Private buffer As String ' The buffer
Private Sub Class_Initialize()
' We set the buffer up to it's initial size and the string value ""
totalLength = initialLength
buffer = Space(totalLength)
curLength = 0
End Sub
Public Sub Append(Text As String)
Dim incLen As Long ' The length that the value will be increased by
Dim newLen As Long ' The length of the value after being appended
incLen = Len(Text)
newLen = curLength + incLen
' Will the new value fit in the remaining free space within the current buffer
If newLen <= totalLength Then
' Buffer has room so just insert the new value
Mid(buffer, curLength + 1, incLen) = Text
Else
' Buffer does not have enough room so
' first calculate the new buffer size by doubling until its big enough
' then build the new buffer
While totalLength < newLen
totalLength = totalLength + totalLength
Wend
buffer = Left(buffer, curLength) & Text & Space(totalLength - newLen)
End If
curLength = newLen
End Sub
Public Property Get Length() As Integer
Length = curLength
End Property
Public Property Get Text() As String
Text = Left(buffer, curLength)
End Property
Public Sub Clear()
totalLength = initialLength
buffer = Space(totalLength)
curLength = 0
End Sub
And here is an example on how to use it:
Dim i As Long
Dim sb As StringBuilder
Dim result As String
Set sb = New StringBuilder
For i = 1 to 100000
sb.Append CStr( i)
Next i
result = sb.Text
VBA itself seems to be a hidden feature. Folks I know who've used Office products for years have no idea it's even a part of the suite.
I've posted this on multiple questions here, but the Object Browser is my secret weapon. If I need to ninja code something real quick, but am not familiar with the dll's, Object Browser saves my life. It makes it much easier to learn the class structures than MSDN.
The Locals Window is great for debugging as well. Put a pause in your code and it will show you all the variables, their names, and their current values and types within the current namespace.
And who could forget our good friend Immediate Window? Not only is it great for Debug.Print standard output, but you can enter in commands into it as well. Need to know what VariableX is?
?VariableX
Need to know what color that cell is?
?Application.ActiveCell.Interior.Color
In fact all those windows are great tools to be productive with VBA.
It's not a feature, but a thing I have seen wrong so many times in VBA (and VB6): Parenthesis added on method calls where it will change semantics:
Sub Foo()
Dim str As String
str = "Hello"
Bar (str)
Debug.Print str 'prints "Hello" because str is evaluated and a copy is passed
Bar str 'or Call Bar(str)
Debug.Print str 'prints "Hello World"
End Sub
Sub Bar(ByRef param As String)
param = param + " World"
End Sub
Hidden Features
Although it is "Basic", you can use OOP - classes and objects
You can make API calls
Possibly the least documented features in VBA are those you can only expose by selecting "Show Hidden Members" on the VBA Object Browser. Hidden members are those functions that are in VBA, but are unsupported. You can use them, but microsoft might eliminate them at any time. None of them has any documentation provided, but you can find some on the web. Possibly the most talked about of these hidden features provides access to pointers in VBA. For a decent writeup, check out; Not So Lightweight - Shlwapi.dll
Documented, but perhaps more obscure (in excel anyways) is using ExecuteExcel4Macro to access a hidden global namespace that belongs to the entire Excel application instance as opposed to a specific workbook.
You can implement interfaces with the Implements keyword.
Dictionaries. VBA is practically worthless without them!
Reference the Microsoft Scripting Runtime, use Scripting.Dictionary for any sufficiently complicated task, and live happily ever after.
The Scripting Runtime also gives you the FileSystemObject, which also comes highly recommended.
Start here, then dig around a bit...
http://msdn.microsoft.com/en-us/library/aa164509%28office.10%29.aspx
Typing VBA. will bring up an intellisense listing of all the built-in functions and constants.
With a little work, you can iterate over custom collections like this:
' Write some text in Word first.'
Sub test()
Dim c As New clsMyCollection
c.AddItems ActiveDocument.Characters(1), _
ActiveDocument.Characters(2), _
ActiveDocument.Characters(3), _
ActiveDocument.Characters(4)
Dim el As Range
For Each el In c
Debug.Print el.Text
Next
Set c = Nothing
End Sub
Your custom collection code (in a class called clsMyCollection):
Option Explicit
Dim m_myCollection As Collection
Public Property Get NewEnum() As IUnknown
' This property allows you to enumerate
' this collection with the For...Each syntax
' Put the following line in the exported module
' file (.cls)!'
'Attribute NewEnum.VB_UserMemId = -4
Set NewEnum = m_myCollection.[_NewEnum]
End Property
Public Sub AddItems(ParamArray items() As Variant)
Dim i As Variant
On Error Resume Next
For Each i In items
m_myCollection.Add i
Next
On Error GoTo 0
End Sub
Private Sub Class_Initialize()
Set m_myCollection = New Collection
End Sub
Save 4 whole keystrokes by typing debug.? xxx instead of debug.print xxx.
Crash it by adding: enum foo: me=0: end enum to the top of a module containing any other code.
Support for localized versions, which (at least in the previous century) supported expressions using localized values. Like Pravda for True and Fałszywy (not too sure, but at least it did have the funny L) for False in Polish... Actually the English version would be able to read macros in any language, and convert on the fly. Other localized versions would not handle that though.
FAIL.
The VBE (Visual Basic Extensibility) object model is a lesser known and/or under-utilized feature. It lets you write VBA code to manipulate VBA code, modules and projects. I once wrote an Excel project that would assemble other Excel projects from a group of module files.
The object model also works from VBScript and HTAs. I wrote an HTA at one time to help me keep track of a large number of Word, Excel and Access projects. Many of the projects would use common code modules, and it was easy for modules to "grow" in one system and then need to be migrated to other systems. My HTA would allow me to export all modules in a project, compare them to versions in a common folder and merge updated routines (using BeyondCompare), then reimport the updated modules.
The VBE object model works slightly differently between Word, Excel and Access, and unfortunately doesn't work with Outlook at all, but still provides a great capability for managing code.
IsDate("13.50") returns True but IsDate("12.25.2010") returns False
This is because IsDate could be more precisely named IsDateTime. And because the period (.) is treated as a time separator and not a date separator. See here for a full explanation.
VBA supports bitwise operators for comparing the binary digits (bits) of two values. For example, the expression 4 And 7 evaluates the bit values of 4 (0100) and 7 (0111) and returns 4 (the bit that is on in both numbers.) Similarly the expression 4 Or 8 evaluates the bit values in 4 (0100) and 8 (1000) and returns 12 (1100), i.e. the bits where either one is true.
Unfortunately, the bitwise operators have the same names at the logical comparison operators: And, Eqv, Imp, Not, Or, and Xor. This can lead to ambiguities, and even contradictory results.
As an example, open the Immediate Window (Ctrl+G) and enter:
? (2 And 4)
This returns zero, since there are no bits in common between 2 (0010) and 4 (0100).
Deftype Statements
This feature exists presumably for backwards-compatibility. Or to write hopelessly obfuscated spaghetti code. Your pick.