
Used Bytes in a Directory
This function returns the number of bytes used on the directory: Function DirUsedBytes(ByVal dirName As _ String) As LongDim FileName As StringDim FileSize As Currency’ add a backslash if not

This function returns the number of bytes used on the directory: Function DirUsedBytes(ByVal dirName As _ String) As LongDim FileName As StringDim FileSize As Currency’ add a backslash if not

This function returns the hard disk free bytes, total bytes, percentage of free bytes, and used space. Before calling the function, set the first field of the DISKSPACEINFO structure (“RootPath”)

VB4 supports the built-in Win95 Toolbar control, which allows users to add Buttons to the toolbar. The buttonhas a ButtonClick event, but if you want to trap a double-click, there

Dir$ raises a runtime error if you supply it an invalid drive. For example, Dir$ (“d:winhimems.sys”) crashes ifdrive d: doesn’t exist. To check if a file exists, add an error

This code illustrates how to use a Collection to automatically generate a unique set of values from a set of datacontaining duplicates. In this example, scan a string array and

You can use the almost-forgotten ability of Visual Basic to have a function or sub with an undeterminednumber of arguments do something to a set of controls. For example, you

You cannot directly access constituent controls on a UserControl component from another module of the sameproject. Constituent controls behave differently from controls on forms, which you can access from any

These two small, simple, and effective functions easily encrypt/decrypt a text password. The functions taketwo parameters: a number in the range of 1 to 10 used to alternatively shift up

I’ve seen several tips using numeric values instead of the corresponding Visual Basic constants. Always usethe Visual Basic predefined constants. For example, you can set up a message box using

Sometimes I need to control a VB form while focus is on another one. For example, I want form B to beresized when I press the “OK” button on form

If you use OLE Remote Automation, you must start the Automation Manager on the server computer beforeany OLE remote communication occurs. By default, this application is visible, but you can

I enjoyed Joel Paula’s “Scrollable Viewport for a Picture” tip [“101 Tech Tips for VB Developers,” Supplementto the February 1997 issue of VBPJ, page 12], and I’d like to make

If you use popup menus in your applications, you should be aware of a bug present in VB4 16/32 and VB5. Ifyou have two forms and the first one shows

SaveSetting and GetSetting make writing application settings a breeze. These two utility functions retrieve andstore the current forms position: Public Sub FormPosition_Get(F As Form)’ Retrieve Form F’s position from an

If you build an ActiveX control that exposes a Text- or Caption-like property, even under different names, you should modify its attributes in the Procedure Attribute dialog box after expanding

Because GoSubs make for less structured programming, many programmers avoid them. If you compile yourVB5 applications to native code, you have one more reason to stay away from them because,

You can often use Choose to replace an array and build tables of results evaluated at compile-time instead ofrun time. For instance, if you need to evaluate the factorial of

You can often replace an If…Then…Else block with a more compact IIf function: ‘ returns the max of two valuesmaxValue = IIf(first >= second, _ first, second) Switch is a

When building an ActiveX control, you can set a default property or method using the Procedure Attributesdialog box, after clicking on the Advanced button. However, if your default property also

If you, like me, often used the “array” name for variables, you must revise your code when porting yourapplications to Visual Basic 5.0. This name has become a reserved keyword

Users often find it faster to retype the entire contents of a text box rather than position the cursor within the data, and then edit the data. This is especially

You can write a single procedure that accepts any type of array as an argument by using a variantparameter. Within the procedure, address the array using the usual syntax: ‘

When I write text in message boxes, labels, and so on, and I need to include a carriage return/line feed, I use this function, passing it the number of CR/LFs

THE ADDRESS OF A VARIABLEVB5 includes a built-in VarPtr function (see tip “Use the Object Browser to Discover UndocumentedFeatures”), but this function isn’t available in VB4. The VB4 runtime library

Traditionally, VB programmers benchmark their code using the Timer function. However, if your processmight terminate on the following day, you must take into account that the value returned by that

Unlike VB4, VB5””””s App.Path property might return a UNC path, such as “\serverprograms…”), undercertain circumstances, depending on how the program started and if it””””s interpreted in the VB IDE orcompiled

If you right-click on the right-most pane of the Object Browser, you can issue the Show Hidden Members command. From this point on, the Object Browser shows all hidden properties

If you build an ActiveX control that exposes an enumerated property, you should define a Public Enumstructure that gathers all the possible values for that property. Doing this helps the

If you create out-of-process OLE servers, Visual Basic embeds the companion type library into the EXE fileand generates no TLB file. However, if you own the Enterprise Edition of VB4

The implementation of Public variables in forms and classes changed with Visual Basic 5.0. VB4 implementspublic variables in forms and class modules as if they’re regular variables, using pointers to