Site hosted by Angelfire.com: Build your free website today!

FREE Visual Basic Source Code

 

 

ENTER

 

 

 

 

 

 

 

Tips & Tricks

You can quickly navigate tips using the alphabetical topic list below.

A new Format function
Add a new line to existing textbox text
Confirm Screen Resolution
Convert NULL Values to Empty Strings to Avoid Errors
Create templates from existing forms
Creating an incrementing number box
Creating Professional Documents with Code
Enabling the horizontal scrollbar in a RichTextbox control
Enhancing Browser Page Load Performance

Finding the last day of the month
GETting the contents of a file
Implementing a "wait" function in VB
Importing Registry settings
Keep Your Background Processes Running
Keeping track of VB source code builds
Labeling your forms

Measuring a text extent
Nothing to declare?
Opening a browser to your homepage
Parsing Using SPLIT Function
Quick Text Select On GotFocus

Interested in submitting a "tip" or a "trick"? Send your tip, fully commented to: vbcoderz@aol.com



Add a new line to existing textbox text

Often, you may want to append additional information to existing text within a multiline textbox. For instance, suppose you want to add the string "Updated: " followed by the current date. To do so, you can take advantage of the SelStart and SelText properties. As you probably know, the SelStart property returns or sets the beginning of a selection. The SelText returns or sets the actual selected text. If there isn't a selection, then both properties return the insertion point. So, to insert a new line of text in a multiline textbox, use code similar to:

Dim strNewText As String
With Text1
strNewText = "Updated: " & Date
.SelStart = Len(.Text)
.SelText = vbNewLine & strNewText
End With

This code snippet moves the insertion point to the end of any existing text in Text1, then inserts a new line followed by the additional information.



Enabling the horizontal scrollbar in a RichTextbox control

By default, when you add a RichTextbox control to a form, VB sets the RightMargin property to 0. This means that the text you enter wraps in the control. To display the horizontal scroll bar, you must set the RightMargin property to a value greater than the control's width. Otherwise, even if you set the ScrollBars property to 1-rtfHorizontal, the RTB won't display the scrollbar.

As an example, add a 3200 wide RTB to a form, then set the RightMargin to 3300 and the ScrollBars to 1-rtfHorizontal. Run the project and type text into the control until it extends beyond the RTB's boundaries. When you do, VB displays the horizontal scroll bar.

Top of Page




Visible Cues from a Minimized Form

Suppose you want a form to perform a task while minimized, then notify the user without a message box and while remaining minimized. You can send a message via a changing icon on the minimized form in the taskbar.

Create a form containing a timer and an image list. Set the timer's Interval property to 2000, then use the ImageList control's Custom property to add three images. Finally, add this code to the Timer event:

Private Sub Timer1_Timer()
Static iImage As Integer
iImage = iImage + 1
If iImage > 3 Then iImage = 1
Me.Icon = ImageList1.ListImages(iImage).Picture
End Sub

Top of Page




Use the Timer control for longer than 1 minute

As you know, the Timer control provides a great way to schedule events in a VB project. When you enable the control, it fires off its Timer event every n milliseconds, as determined by the TimeInterval property. However, the TimeInterval property only accepts numbers up to 65,535, or just over one minute. As a result, you may have wondered how to use this control for periods longer than that. To do so, use a form, or project level, variable to keep track of how many times the Timer event fires. Then, in the Timer event, re-enable the control if enough time hasn't passed. For example, consider the code below that we attached to a standard form.

Option Explicit
Dim iElapsedMin As Integer
Const cMax_Min As Integer = 2

Private Sub Form_Load()
Timer1.Enabled = True
iElapsedMin = 1
End Sub

Private Sub Timer1_Timer()
lblText.Visible = (iElapsedMin = cMax_Min)
Timer1.Enabled = (iElapsedMin 

Top of Page




A new Format function

VB 5 has the Format command that almost works the same as Print. The difference is that Format shortens the output string length if all the format characters are not used. To work around this I wrote a Public Function called FormatNum.

Public Function FormatNum(MyNumber As Double, FormatStr As String) As String

   ' This Function returns number formatted as a string 
   '    with the desired minimum number of characters
   ' MyNumber - Use CDbl(MyNumber) in the function 
   '    call to prevent type mismatch error.
   '
   FormatNum = Format$(MyNumber, FormatStr)
   If Len(FormatNum) 

Use this function like this:

Print #FileNumber, FormatNum(CDbl(MyVariable), " #### ")

Top of Page




Using Server.HTMLEncode() Function

Although it is not recommended (and almost always a bad idea) many ASP applications contain and pass connection string information. If your ASP application was written with ActiveX Data Objects (ADO) 1.x and it passed the ADO ConnectionString property using HTTP POST or GET, it may fail when switched to ADO 2.0. ADO 2.0 returns the ConnectionString with the "Extended Properties" argument in double-quotes. If this value is passed to an HTML property, it will result in a truncated ConnectionString value at the first double-quotes encountered. An example of the ConnectionString property returned using ADO 2.0 is displayed below:

Provider="MSDASQL.1;Data Source=Mytest;Connect Timeout=15;
Extended Properties="DSN=MyTest;DBQ=C:\MyTest.mdb;
DriverId=25;FIL=MS Access;MaxBufferSize=512;PageTimeout=5;";
Locale Identifier=1033

The problem may be remedied by displaying the Server.HTMLEncode() function as:

<%@ LANGUAGE="VBScript"%>
<%
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "TheConnectString.."
%%>

<form method=post action=test.asp>

<input type=hidden name=txtConnString
value="<%=Server.HTMLEncode(objConn.ConnectionString)%>">

<input type=submit value=" Submit! ">
</form>

Top of Page




Using Response.IsClientConnected Property to Determine Browser Connection

When a browser requests an ASP page from the Web Server, but does not wait for the entire page to be downloaded, the server continues to process the request, wasting valuable CPU cycles. If running Internet Information Server (IIS) 4.0, you can use the Response.IsClientConnected property to determine whether or not the browser is still connected to the server.

If it is not connected to the server, processing can be stopped to conserve CPU cycles. To do this, request an ASP page that contains the script below and use PerfMon to monitor the CPU cycles on the Web server. Note if you click "Stop" in the browser, the number of CPU cycles will decrease sooner than if the loop had continued.

<%@ LANGUAGE="VBSCRIPT" %>
<%
Function IsConnectedAfter(Seconds)
Dim StartTime
Dim PauseTime

IsConnectedAfter = True
StartTime = Now

Do While DateDiff("s", StartTime, Now) < Seconds
PauseTime = Now
Do While DateDiff("s", PauseTime, Now) < 1
'Do Nothing
Loop
Response.Write "."
If Response.IsClientConnected = False then
IsConnectedAfter = False
Exit Function
End If

Loop
End Function
%>

Top of Page




Enhancing Browser Page Load Performance

If your ASP application is experiencing browser page load performance problems consider implementing one or both of the following techniques.

One easy way to improve the speed performance of an ASP page is to set the @ENABLESESSIONSTATE to False if an ASP page does not use any session variables. To accomplish this, insert the following line of code at the top of the ASP page.

<%@ENABLESESSIONSTATE = False%>

Page performance also may be improved by copying the values of collection variables into local variables (as opposed to referencing the object each time the variable value is needed). For example, if you want to reference the Request.ServerVariable collection to determine the users logon id, you would use the following line of script:

Request.ServerVariables("LOGON_USER")

If you need to use this value in several places on your page, it is much more efficient to store this value to a local variable and then reference the local variable.

<%

Dim User

User = Request.ServerVariables("LOGON_USER")

Request.Write User

%>

Top of Page




Switching to Design View after Modifying ASP Script in Visual InterDev

When developing an Active Server site using Visual InterDev6 you may have encountered the annoying problem of not being able to switch the editor into Design view after you have modified the ASP script. The Visual InterDev editor can't switch into Design view because there is unquoted ASP script inside of an attribute value or inside of a <select> tag. The problem is that the Design Editor doesn't know how to handle ASP script within certain HTML tags. Inserting the code below into an ASP page from the Visual InterDev source Editor and then switching to Design view will demonstrate this problem:

<SELECT>
<OPTION value="<%=Value1%>">First Option</OPTION>
</SELECT>

To get around this problem, you need to use the Response.Write method to write out the HTML that contains the embedded ASP. You will then be able to switch to Design view. The HTML control however will not appear on the page. The code below demonstrates how to accomplish this.

<SELECT>
<%
Response.Write "<OPTION value=" & Value1 & "> First Option</OPTION>"
%>
</SELECT>

Top of Page




Parsing Using SPLIT Function

Parsing functions are one of the most commonly, over-written string manipulation functions. Visual Basic 6.0 answered this problem by adding a SPLIT function. The function is very easy to use and, with only one line of code, you can parse any string using a specific delimiter. The code looks like this:



Dim strAnimals As String
Dim iCounter As Integer
Dim arrAnimals() As String

strAnimals = "Cats,Dogs,Horses,Birds"

'-- Parse String
arrAnimals = Split(strAnimals, ",")

'-- Loop through array
For iCounter = LBound(arrAnimals) To UBound(arrAnimals)
MsgBox arrAnimals(iCounter)
Next

Top of Page




Keep Your Background Processes Running

In Visual Basic, if you make a call to the MSGBOX function all other background processes that you may have running (counters, timer events, etc) are stopped until the user acknowledges the Msgbox dialog box. This can be potentially devastating if you write an application that runs unattended.

To overcome this problem, you must use the Windows API call for the MessageBox function. It looks and acts the same as the VB "msgbox" function, but does not stop the background processes from running.

In a module, paste the following API declaration:

Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As
Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As
Long) As Long

Next, on the default form add a timer control, 2 command buttons, and a label. Then type the following code into the form, which demonstrates the VB msgbox and API MessageBox functions. That's all there is to it.

Private Sub Command1_Click()
MsgBox "The Timer STOPS!"
End Sub

Private Sub Command2_Click()
MessageBox Me.hwnd, "Notice the timer does not stop!", "API Call", _ vbOKOnly + vbExclamation
End Sub

Private Sub Timer1_Timer()
Label1.Caption = Time
End Sub

Top of Page




Creating Professional Documents with Code

Have you ever wanted to create polished, professional documents, like those created in Microsoft Word, through the use of code? Follow these easy steps to make it happen:

First add a reference to your project for "Microsoft Word 8.0 Object Library" (MSWORD8.OLB).

Then add the following code to create an instance of Word and add text to a new document:

Dim objWord As New Word.Application

'-- Show Microsoft Word
objWord.Visible = True

'-- Add new Document
objWord.Documents.Add

'-- Add text to Document
objWord.Selection.TypeText "Visual Basic!"

'-- Select all Text
objWord.Selection.WholeStory

'-- Change Font Size
objWord.Selection.Font.Size = 50

Set objWord = Nothing

Check out the Object Browser for more properties and methods exposed by the Word Object.

Top of Page




Convert NULL Values to Empty Strings to Avoid Errors

One way to avoid errors from occurring when retrieving NULL values from a recordset object is to inspect the field's value. If it is NULL, then convert it to an empty string or zero. For example:

If isnull(rs("Field")) then tmp="" else tmp=rs("Field")
form.textfield=tmp

An even simpler way is to use the format function, which will convert a NULL value to an empty string automatically, avoiding any error messages. It will look like this:

form.textfield=format(rs("Field"))

Top of Page



Writing to the Windows NT event log

Windows applications typically write to the NT event log to provide the user with useful information. In VB5/6, the App object now provides methods to make writing to the event log in Windows NT a snap:

'-- Start Event Logging
Call App.StartLogging("", vbLogToNT)

'-- Log Events to NT
Call App.LogEvent("Info", vbLogEventTypeInformation)
Call App.LogEvent("Error", vbLogEventTypeError)
Call App.LogEvent("Warning", vbLogEventTypeWarning)

Top of Page



Keeping track of VB source code builds

Keeping track of source code builds in VB can be easy, if you use the Version Numbering feature provided in EXE creations. Click on the options button when creating an EXE file. Then turn on the "Auto Increment" checkbox.

Versioning supports a three-segment version number: Major, Minor and Revision. The Auto Increment feature, if selected, will automatically increase the Revision number by one each time you run the Make Project command for this project.

Typically, build information will go on an About form. Just add a label called, "lblVersion" and add the following code to your form:

lblVersion.Caption = "Version: " & App.Major & "." & App.Minor & "."
& App.Revision

If my Major version number is 2, the Minor number is 1 and the Revision is 12, the label will display: "Version: 2.1.12"

For keeping track of your individual code snippets try downloading CodeKeeper. It's a freeware code storage utility that can be used to store all types of code.

Top of Page



Implementing a "wait" function in VB

How may times have you needed your app to "slow down"?

Here's a simple way of implementing an accurate "wait" function in VB.

  1. Add a timer called timer1 to a form. Set its Interval property to 0 and it's enabled property to FALSE.
  2. Add two labels (label1 and label2) and a command button (command1) to the form.
  3. Add the following subroutine and Timer1 event code:
    Public Sub Wait(seconds)
    
        '-- Turn timer on
        Timer1.Enabled = True
    
        '-- Set Timer Interval
        Me.Timer1.Interval = 1000 * seconds
        While Me.Timer1.Interval > 0
            DoEvents
        Wend
    
        '-- Turn timer off
        Timer1.Enabled = False
    End Sub
    
    Private Sub Timer1_Timer()
    
        Timer1.Interval = 0
    End Sub
    


That's it! Use the Wait function anywhere a delay is required, for example:

Private Sub Command1_Click()
    Label1.Caption = Now
    Wait (5)
    Label2.Caption = Now
End Sub

Top of Page



Create templates from existing forms

Here's a way for you to create a template from an existing form so you can use it to design future forms. Once you've created the 'perfect' form, place it in the ..\Template\Forms\ subdirectory. Now, the next time you want to add a new form to your project, you'll see that the newly created form is in the list of available form templates! Just select it and you're on your way. This tip also applies to modules, classes, etc.

Top of Page



Nothing to declare?

When you use the Windows API, you should never need to write your own Declare statement. The API Text Viewer utility loads in a text file (WIN31API.TXT for 16-bit, and WIN32API.TXT for 32-bit) and lets you copy declares, global constants, and user-defined types. You can also convert the text file to an Access database for faster searching. Handy, eh?

Top of Page



Figuring out the current screen resolution

You can use the following small piece of code to detect the current screen resolution and then act on the information - for instance, by resizing form objects to suit the user's resolution.

Dim x,y As Integer
    x = Screen.Width / 15
    y = Screen.Height / 15
    If x = 640 And y = 480 Then MsgBox ("640 * 480")
    If x = 800 And y = 600 Then MsgBox ("800 * 600")
    If x = 1024 And y = 768 Then MsgBox ("1024 * 768")

Top of Page



Finding the last day of the month
In many industries ( particularly in [my] the insurance industry ), it's important to know the last day of the month. To find the last day of a given month, add a text box and a command button to a form. Enter the following code in the command button:

Dim TEMP2 As Date
Dim nLastDay As Integer
TEMP2 = InputBox$("Please Enter A Date", "LastDay")
nLastDay = DatePart("d", DateAdd("M", 1, TEMP2 - DatePart("d", TEMP2)))
Text1.Text = nLastDay

When you run the application and click the button, you'll be prompted for a date. Then, the program will display the last day of that month of any year.

Top of Page



GETting the contents of a file

To read a complete file in VB, the normal procedure is to read the contents of the file line by line and accumulate it into a string. Instead, you can use the GET function to read the file with a single call. Doing so simplifies and speeds up the process of reading a file.

You can use the following function:

    Dim Handle As Integer
    Dim FileString As String
    Handle = FreeFile
    Open "C:\TEMP\TST.TXT" For Binary As #Handle
    FileString = Space(FileLen("C:\TEMP\TST.TXT"))
    Get #Handle, ,FileString  
    Close #Handle

This code involves a single call to return the contents of the file.

Top of Page



Help with Shell

Suppose you have a DOS program, Dosapp.exe. This program produces an output file that will subsequently be processed, and you want to do this N times. The code might look like this:

    for Trial = 1 to N
    x=shell("Dosapp.exe",vbHide)
    Process the output 
    Next Trial

The problem is, the code after the Shell may be executed before the Shelled Dosapp.exe has created the file. There are complicated ways of solving this, including API calls, but here's a simple solution: the FileLen function. If the file to be processed is x$, you can just insert a few lines of code:

    for Trial = 1 to N
    Open x$ for output as 1
    Close 1
    ' This sets file length equal to zero
    x=shell("Dosapp.exe",vbHide)
    Do While FileLen(x$) = 0
    DoEvents
    ' Halt further execution until x$ is created and closed
    Loop

    ' Process the output to add to a new file
    Next Trial

You may want to do other things such as using Timer to prevent an infinite Do Loop, but this is the main idea. FileLen() works because even if x$ is open and has data in it, FileLen(x$) = 0. Thus you're assured that the process code won't execute until x$ is fully created.

Top of Page



Watch your window state

My application saves the window location and size, so it will open the next time at the same screen location. This technique is great and pleases customers. But after several months, the program wouldn't start right -- it would die with an 'overflow error'. We tried every possible test, and could only determined that something in the INI file had become corrupted. Finally, we found that the window's Top, Left, Width, and Height values were incorrect. When the program started and read these wrong numbers, the 'overflow error' was the result.

As it turned out, the numbers were being thrown off when the user minimized the window and exited Windows with it minimized. As the program closes, it saves the position values of the minimized state -- which messes up the values. To fix the problem, we added some code to check the windowstate. If it's vbMinimized, the program skips the code that saves the window position.

Top of Page



Tracking down Resume Next

This tip is extremely simple. But try it, and see if it helps you some time in the future.

Maybe you've inherited a large chunk of code from that developer who's smiling on the way out the door. Or, perhaps you're getting ready to ship that version 1.0 application to 100 users, try this. In any case, take a minute to search all of the code for the string

     On Error Resume Next

In fact, try this even if you don't want to ship your code to 100 users -- or especially if you have code that seems to fail "for no reason." You might be surprised at what that ol' Resume Next is hiding.

Top of Page



Labeling your forms

Do you have a ton of screens in your application? Do you also have plenty of users who want to "help you" by pointing out buttons that are one twip out of place? Sometimes it's hard to know what screen users are talking about when they're trying to communicate a problem -- particularly if they're in a different location than you.

To reduce the pain of this process, I add a label (called lblHeader) to the top of each GUI window, nominally to hold start-up information for users when they first open the window. You can also use this label to hold the name of the window the user is looking at, by using the following code:

Private Sub Form_Load()

    SetupScreen me

End Sub





Public SetupScreen (frm as Form)

    ' Do other set-up stuff here (fonts, colors).

    HookInFormName frm

End Sub



Public Sub HookInFormName(frm As Form)

    ' The Resume Next on Error allows forms that do not use a standard

    ' header label to get past this.

    On Error Resume Next

    frm.lblHeader.Caption = "(" & frm.Name & ") " & frm.lblHeader.Caption

End Sub

Note that if you don't want to use a label, that you can also use code like

    frm.print frm.name 

to print to the back of the window itself.

Top of Page



Opening a browser to your homepage

You can use code like the following to open a browser to your homepage. Modify filenames, paths, and URLs as necessary to match the values on your system.

Dim FileName As String, Dummy As String

Dim BrowserExec As String * 255

Dim RetVal As Long

Dim FileNumber As Integer

Const SW_SHOWNORMAL = 1 ' Restores Window if Minimized or



Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _

(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _

ByVal lpParameters As String, ByVal lpDirectory As String, _

ByVal nShowCmd As Long) As Long



Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _

(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As _

String) As Long

'<Code> ---------



BrowserExec = Space(255)

FileName = "C:\temphtm.HTM"



FileNumber = FreeFile()     ' Get unused file number



Open FileName For Output As #FileNumber  ' Create temp HTML file

  Write #FileNumber, "
"  ' Output text

Close #FileNumber   ' Close file



' Then find the application associated with it.

  RetVal = FindExecutable(FileName, Dummy, BrowserExec)

  BrowserExec = Trim$(BrowserExec)

  ' If an application is found, launch it!

  If RetVal <= 32 Or IsEmpty(BrowserExec) Then ' Error



    Msgbox "Could not find a browser"



  Else

    RetVal = ShellExecute(frmMain.hwnd, "open", BrowserExec, _

      "www.myurl.com", Dummy, SW_SHOWNORMAL)

    If RetVal <= 32 Then ' Error

      Msgbox "Web Page not Opened"

    End If

  End If



Kill FileName  ' delete temp HTML file

Top of Page



Creating a incrementing number box

You can't increment a vertical scroll bar's value -- a fact that can become annoying. For example, start a new project and place a text box and a vertical scroll bar on the form. Place the vertical scroll bar to the right of the text box and assign their Height and Top properties the same values. Assign the vertical scroll bar a Min property value of 1 and a Max value of 10. Place the following code in the vertical scroll bar's Change event:

Text1.Text = VScroll1.Value

Now press [F5] to run the project. Notice that if you click on the bottom arrow of the vertical scroll bar, the value increases; if you click on the top arrow, the value decreases. From my perspective, it should be the other way around.

To correct this, change the values of the Max and Min properties to negative values. For example, end the program and return to the design environment. Change the vertical scroll bar's Max value to -1 and its Min value to -10. In its Change event, replace the line you entered earlier with the following:

Text1.Text = Abs(Vscroll1.Value)

Now press [F5] to run the project. When you click on the top arrow of the vertical scroll bar, the value now increases. Adjust the Height properties of the text box and the scroll bar so you can't see the position indicator, and your number box is ready to go.

Top of Page


Measuring a text extent

It's very simple to determine the extent of a string in VB. You can do so with WinAPI functions, but there's an easier way: Use the AutoSize property of a Label component. First, insert a label on a form (labMeasure) and set its AutoSize property to True and Visible property to False. Then write this simple routine:

Private Function TextExtent(txt as String) as Integer

   labMeasure.Caption = txt

   TextExtent = labMeasure.Width

End Function

When you want to find out the extent of some text, simply call this function with the string as a parameter.

In my case it turned out that the measure was too short. I just added some blanks to the string. For example:

Private Function TextExtent(txt As String) As Integer

   labMeasure.Caption = "  " & txt

   TextExtent = labMeasure.Width

End Function

Top of Page



Importing Registry settings

You can use just a few lines of code to import Registry settings. If you have an application called myapp.exe and a Registry file called myapp.reg, the following code will put those settings into the Registry without bothering the user.

Dim strFile As String

strFile = App.Path & "\" & opts.AppExeName & ".reg"

If Len(Dir$(strFile)) > 1 Then

    lngRet = Shell("Regedit.exe /s " & strFile, vbNormalFocus)

End If

Top of Page



Use FreeFile to Prevent File Open Conflicts

Both Access and VB let you hard code the file numbers when using the File Open statement. For example:

     Open "myfile.txt" for Append as #1

     Print #1,"a line of text"

     Close #1

The problem with this method of coding is that you never know which file numbers may be in use somewhere else in your program. If you attempt to use a file number already occupied, you'll get a file error. To prevent this problem, you should always use the FreeFile function. This function will return the next available file number for your use. For example:

     IntFile=FreeFile()

     Open "myfile.txt" for Append as #intFile

     Print #intFile,"a line of text"

     Close #intFile

Top of Page



Confirm Screen Resolution

Here's a great way to stop the user from running your application in the wrong screen resolution. First, create a function called CheckRez:

Public Function CheckRez(pixelWidth As Long, pixelHeight As Long) As Boolean

    '

    Dim lngTwipsX As Long

    Dim lngTwipsY As Long

    '

    ' convert pixels to twips

    lngTwipsX = pixelWidth * 15

    lngTwipsY = pixelHeight * 15

    '

    ' check against current settings

    If lngTwipsX <> Screen.Width Then

        CheckRez = False

    Else

        If lngTwipsY <> Screen.Height Then

            CheckRez = False

        Else

            CheckRez = True

        End If

    End If

    '

End Function

Next, run the following code at the start of the program:

    If CheckRez(640, 480) = False Then

        MsgBox "Incorrect screen size!"

    Else

        MsgBox "Screen Resolution Matches!"

    End If

Top of Page


Quick Text Select On GotFocus

When working with data entry controls, the current value in the control often needs to be selected when the control received focus. This allows the user to immediately begin typing over any previous value. Here's a quick subroutine to do just that:

Public Sub FocusMe(ctlName As Control)

    '

    With ctlName

        .SelStart = 0

        .SelLength = Len(ctlName)

    End With

    '

End Sub

Now add a call to this subroutine in the GotFocus event of the input controls:

Private Sub txtFocusMe_GotFocus()

    Call FocusMe(txtFocusMe)

End Sub

 

 

Visual Basic Links

 

VB Code.com - Thousands of lines of Visual Basic Source Code. Featuring:vb, VB3, VB4, VB5, VBScript, VBA, vb game programming, vb certification, OCX, VBX, OLE, DCOM, COM, DNA, JET, DLL, ADO, DAO, ODBC, RDO, DCOM, Win API, dbgrid and much more!

Planet-Source-Code  - Planet Source code is a searchable online database of over 62,000 lines of FREE Visual Basic code, code snippets, modules, .bas files, functions, sprites, you name it....it's here!

Web Solutions  - An awesome resource site with tons of Visual Basic, Visual Fox Pro and other widgets, snippets, database stuffs and FYI's. VB/VFP Tips and Gotchas and much more!

Andy's Visual Basic Site - A great site containg heaps of Source Code, API's, Sample Projects, Forums, Help with Controls, Links and heaps more.

Extreme VB - Programming language, VB code, msaccess , downloads, freeware, shareware, tutorials - This site is an absolute MUST SEE with hundreds upon hundreds of source code samples as well as actual projects. Well worth a click and be darn sure to bookmark this site!

Programming Jobs - Jobs all over the United States. Employers, if you want to find quality personnel just ask for my friends at Programming Jobs - [ac-resources.com].

Andrea VB Programming - Here's the Code you're looking for! Tips and Tricks, Source Code, Printing and Programming Techniques, Advanced API Programming and FREE Downloads for Visual Basic.

Add to your Programming Knowledge - This site has VB4, VB5, VBScript, VBA, vb game programming, vb certification, OCX, VBX, OLE, DCOM, COM, DNA, JET, DLL, ADO, DAO, ODBC, RDO, DCOM, Win API, dbgrid, database front end, certify, decompiling, decompiler, visual basic for applications,sql,SQL Server,Structured Query Language, Visual Basic tutorials, examples, downloads, links. If you're just starting out in VB, or are already quite a way into it, this site is for you.

Visual Basic Web Directory - A comprehensive guide and directory featuring thousands of web resources for Visual Basic developers. This site has links to: Visual Basic source code, programming language insight, VB code, msaccess , downloads, freeware, shareware, tutorials, winapi, vb, VB3, VB4, VB5, VBScript, VBA and even vb game programming.

FREE Microsoft Downloads - Lots of FREE Microsoft Stuff. If you have Netscape then you can't see all the cool VBScript stuff. So, go download it!

Visual Basic Bookmark - A comprehensive directory of programming resources and development information for Visual Basic programmers, Database developers & web designers.

Visual Basic Explorer - Absolutely the most extensive VB site that I have ever had the opportunity to cruise. As a matter of fact, I remember copping code from this site before I started my site. Tutorials, examples, sample code, projects. Learn how to build awesome video games with online, step-by-step instructions.

 

 

Copyright © 1999 InteliDev. All rights reserved.