DlgFocus (statement)


DlgFocus ControlName$ | ControlIndex


Sets focus to the specified control.


A runtime error results if the specified control is hidden, disabled, or nonexistent.

The ControlName$ parameter contains the name of the .Identifier parameter associated with a control in the dialog box template. A case-insensitive comparison is used to locate the specific control within the template. Alternatively, by specifying the ControlIndex parameter, a control can be referred to using its index in the dialog box template (0 is the first control in the template, 1 is the second, and so on).


This code fragment makes sure the user enters a correct value. If not, the control returns focus back to the TextBox for correction.

Function DlgProc(ControlName$,Action%,SuppValue%) As Integer

  If Action% = 2 and ControlName$ ="OK" Then
    If IsNumeric(DlgText$("TextBox1")) Then
      Msgbox "Duly Noted."
      Msgbox "Sorry, you must enter a number."
      DlgFocus "TextBox1"
      DlgProc = 1
    End If
  End If
End Function


Sub Main()

  Dim ListBox1$()
  Begin Dialog UserDialog ,,112,74,"Untitled",.DlgProc
    TextBox 12,20,88,12,.TextBox1
    OKButton 12,44,40,14
    CancelButton 60,44,40,14
    Text 12,11,88,8,"Enter Desired Salary:",.Text1
  End Dialog
  Dim d As UserDialog
  Dialog d
End Sub

See Also

DlgEnable (function); DlgEnable (statement); DlgFocus (function); DlgListBoxArray (function); DlgListBoxArray (statement); DlgSetPicture (statement); DlgText (statement); DlgText$ (function); DlgValue (function); DlgValue (statement); DlgVisible (statement); DlgVisible (function).

More information