101 Tech Tips for VB Developers
These tips and tricks were submitted by professional developers using Visual Basic 3.0, Visual Basic 4.0, Visual Basic 5.0, Visual Basic for Applications (VBA), and Visual Basic Script (VBS). The tips were compiled by the editors at Visual Basic Programmer’s Journal. Special thanks to VBPJ Technical Review Board members Francesco Balena, Chris Kinsman, Karl E. Peterson, Phil Weber, and Jonathan Wood. Instead of typing the code published here, download the tips from the free, Registered Level of The Development Exchange at http://www.windx.com.
USE BOOLEAN VARIABLES FOR CHECKBOX VALUES
Visual Basic specifies a Boolean’s default values as zero for False and -1 for True. You may save and set the value of a check box, based on the absolute value of a Boolean variable, as these correspond to the intrinsic constants vbUnchecked and vbChecked:
…
DISPLAY HORIZONTAL SCROLLBAR
Unlike the Windows 95 common controls, the standard list box doesn’t have a horizontal scrollbar when list items are too wide to fit within the list box. Fortunately, it’s not hard to direct a listbox control to display a horizontal scrollbar.
Add this code to a form’s Load event. It fills a list box with 100 long strings and calls SetHScroll to show a horizontal scrollbar in the list box:
…
Add this code, which includes the required API declarations and the SetHScroll routine, to a BAS module. The SetHScroll routine uses the SendMessage API function to send the LB_SETHORIZONTALEXTENT message to a list box. The last argument is an item from the list, preferably one of the longest items. SetHScroll determines the string’s width in pixels and passes this value to the list box along with the LB_SETHORIZONTALEXTENT message. The list box sets its horizontal extent to this value, and if it is wider than the list-box control, the list box displays a horizontal scrollbar:
…
Website: vb.mvps.org | Filesize: 451kb
No of Page(s): 28
Click here to download 101 Tech Tips for VB Developers.
Related Tutorial
Tags: Tips, win32 api, Windows API, Windows Forms
Comments
Leave a Reply