
Since 1998, DevX has helped people start businesses, build websites, and provide enterprise technology to people globally. Interviewing the likes of Microsoft’s co-founder, Steve Ballmer, the publication brings comprehensive, reliable, and accessible insights to the Internet.
There are two ways to save changes before exiting a form. One is toinvoke the Update method on the data control the DataGrid is bound to fromwithin the QueryUnload event
Setting the ClipControls property to False significantly reduces thetime it takes forms to paint. The default is True, so you’ll need to changeit to False. If you’re using graphics methods,
Keep control and form names as short as possible. Such names are keptin the EXE file. Variable names, however, are not kept in the EXE.
Grids provide a nice way to present certain types of spreadsheet information.Unfortunately, the grid in VB does not allow editing. With just a littlebit of code you can simulate editing
Using the AutoSave feature in the VBAssist Options box automaticallysaves changes made to your project after a defined time interval. To temporarily bypass VBAssist’s Control Lock feature, hold down theCtrl
To toggle a variable between True and False, use the Not operator insteadof an If statement. Use the Not operator on those variables you have explicitlyset with the True or
To quickly set tab stops in list boxes, use the SendMessage API call.The units used are called Dialog Base Units, which average out to aboutfour per character. Some experimentation is
Because the picture control has more overhead than the image control,it’s best to use the image control when you need to display a graphic.Use the picture control when you need
If you need to reference every control on a form, using the Controlscollection will be faster than referencing every control directly. Forexample, if you have four command buttons on a
If your app uses database or other functions that can return Null variants,your app will crash sooner or later with that dreaded “Invalid Useof Null” error. Preventing it is simple:
Calling a function or procedure incurs some overhead. If you have atwo-line function that is called from only three places, you might considerputting those three lines in the functions themselves
When passing controls as parameters, make the function that is receivingthe parameter accept the specific object type instead of generic types.The exception to this is when multiple types of objects
If AutoRedraw is set to True, VB keeps a bitmap of the form in memorythat it uses to redraw the form after another window in front of it isclosed. Because
I often see questions in the VBPJ forum about comparative speedsfor different methods of performing actions in code. In many cases, a simplegeneralization of which is fastest cannot be made.
When unloading a form, use the following piece of code behind a Closebutton: Unload This code should also be put in the Form_Unload() event handlerfor that form: Set = Nothing
If you set a VB file’s DOS attribute to read-only, VB will show itwith a red lock in the project window and prevent it from being overwritten.This is a handy
Have you ever wanted to make that pesky scroll bar disappear when itis not needed, and reappear when the text exceeds the viewable area ofthe text box? Setting the scroll
The best way to save information about an application’s options, suchas toolbar positioning, is to write the settings to an INI file. To doso, two Windows API functions must be
Pressing Alt and F4 will close any window with a control box. Becauseyou can’t choose Alt and F4 as a shortcut key combination from the menudesigner, you must place it
Here’s the code I used to trap the Tab key and use it to generate a”real” tab in a text box: ‘ Trap the tab key to allow tabs in
When working in Windows, it is very easy to lose a minimized icon onthe desktop. Or you may forget you have an application running and tryto open it again from
When updating the values of several records in a loop, put a BeginTrans,CommitTrans around the loop. This will significantly speed up the updateprocess: BeginTrans Do Until dsData.EOF dsData.Edit dsData!sState_cd =
To allow the Enter key to function as a Tab, enter this code in theKeyPress event of your text boxes: Sub Text1_KeyPress (KeyAscii As Integer) If KeyAscii = 13 Then
To select multiple, nonconsecutive rows (a tagged list) in SheridanSoftware’s DataGrid (which is a part of its Data Widgets package), firstset the SelectionTypeRow property of the DataGrid to TagList. For
To create a 3-D text box, place a text box in a 3-D Panel and set thepanel’s AutoSize property to “Autosize Child to Panel.” Thenset the BevelOuter and BevelWidth properties
To add AutoTab to text boxes that have a set MaxLength, add this codeto the text box Change event: Sub Text1_Change () If Len(Text1) = Text1.MaxLength Then SendKeys “{Tab}” End
The latest trend in Windows programs is the use of a 3-D look thatmakes windows and controls appear to be three-dimensional. As a result,a number of tools for adding the
I often see questions in the VBPJ forum about comparative speedsfor different methods of performing actions in code. In many cases, a simplegeneralization of which is fastest cannot be made.
If you work with INI files, save yourself hours of work and downloadthe INIFILE.BAS module I’ve uploaded to the VBPJ and MSBASIC Forumson CompuServe (file KPINI.ZIP). There’s no charge for
There are lots of ways to test for whether a given file exists. Themost common method is to use the Dir$ function. If Dir$ returns a nullstring, then the file