Section 508 for Software Development Coding Examples
Visual Basic
Provision A
§1194.21(a) “When software is designed to run on a system that has a keyboard, product functions shall be executable from a keyboard where the function itself or the result of performing a function can be discerned textually.”
Visual Basic applications contain all the same functionality as the Windows operating system. User controls are all accessible through a keyboard. Pressing the Alt key and then the initial letter of the menu item can generally access objects that are normally accessed through the use of a pointer.
Form elements should be created with tab stops to allow intuitive navigation of the form. Form elements should also have labels to the left of any objects, which can be read by a screen reader to give a brief description of the object and what it does. Additionally, all functions that are performed from a key sequence, such as Copy and Paste, can be accessed with the usual Ctrl+C/Ctrl+V keyboard combinations.
This example code emulates the Windows Keyboard Accessibility settings for setting tabstops:
Private Sub Form_Load()
' Set the tab stops for all of the controls which can get the focus.
txtFirstName.TabStop = True
txtFirstName.TabIndex = 2
txtLastName.TabStop = True
txtLastName.TabIndex = 4
cmdSave.TabStop = True
cmdSave.TabIndex = 5
End Sub
This screen capture of a Name Information window demonstrates the product of this code.
Provision B
§1194.21(b) “Applications shall not disrupt or disable activated features of other products that are identified as accessibility features, where those features are developed and documented according to industry standards. Applications also shall not disrupt or disable activated features of any operating system that are identified as accessibility features where the application programming interface for those accessibility features has been documented by the manufacturer of the operating system and is available to the product developer.”
Visual Basic resides outside of the API for the Windows operating systems. In order to obtain the current user's settings, such as colors for screen objects, your code must retrieve the settings from a DLL file that usually resides in the WINDOWS\SYSTEM directory for Windows 9x or WINNT\SYSTEM32 directory for Windows NT or 2000.
Windows API DLLs do not provide type libraries (those libraries that can be called by TYPE and then reference any function within that library as if it were part of your VB project). A Declare statement must be used to tell VB where the DLL is, and how it can be called from the VB application. Use the available API Viewer in VB to display the proper Declare (also Constant, and Type) statement for all Windows API settings. Let's take a look at an example… This code declares an application-wide function that your Visual Basic code can use anywhere to get the current Windows Accessibility settings:
Public Declare Function SystemParametersInfo Lib "user32.dll" _ Alias "SystemParametersInfoA" (ByVal uAction As Long, _ ByVal uiParam As Long, pvParam As Any, ByVal fWinIni As Long) _ As Long
Remember to account for the differences in data types between the DLL values written in C/C++, and those written in Visual Basic to ensure accurate value evaluation in your code.
Once this is done, the code has access to the current Windows settings for the desired feature, and you can access these settings within your code in order to mimic the Windows environment, rather than override it.
This example code illustrates how to obtain the current Windows setting for StickyKeys and assign it to a variable for later keystroke evaluation within your application:
Dim sk As STICKYKEYS ' holds settings for StickyKeys Dim retval As Long ' return value sk.cbSize = Len(sk) ' set the size of the structure ' Load the StickyKeys settings into the structure. retval = SystemParametersInfo(SPI_GETSTICKYKEYS, Len(sk), sk, 0) ' don't need to notify ' Assign StickyKeys setting as on or off. If (sk.dwFlags And SKF_STICKYKEYSON) = SKF_STICKYKEYSON Then iStickyKeys = 1 ' is on Else iStickyKeys = 0 ' is off End If
Provision C
§1194.21(c) “A well-defined on-screen indication of the current focus shall be provided that moves among interactive interface elements as the input focus changes. The focus shall be programmatically exposed so that assistive technology can track focus and focus changes.”
Input Focus
Visual Basic, as with all languages, offers many ways to highlight the current window object that has focus. Colors, outlines, animation, and others can all signify the state of focus on the screen. Some controls, such as the lightweight controls, cannot receive focus. Lightweight controls include Frame, Image, Label, Line, and Shape controls. Additionally, an object can receive focus only if its Enabled and Visible properties are set to “True”. The Enabled property allows the object to respond to user-generated events such as keyboard and mouse events. The Visible property determines whether an object is visible on the screen.
Consider the following example of VB code that uniquely identifies a command button window object as having focus when the user's mouse passes over the command button:
Private Sub Command1_MouseMove (Button As Integer, Shift As Integer, _ X As Single, Y As Single) Command1.SetFocus End Sub
Provision D
§1194.21(d) “Sufficient information about a user interface element including the identity, operation and state of the element shall be available to assistive technology. When an image represents a program element, the information conveyed by the image must also be available in text.”
A Visual Basic Label should be placed on the form to the left of the image for assistive technology to read, and for a visual description of the meaning of the image. Other controls, such as Listbox, Textbox, and Command Button controls, are read accurately by most assistive technology software for these attributes.
This code is an example of how to add a text label in Visual Basic:
Private Sub Form_Load () Label1.Caption = “Help” End Sub
Provision E
§1194.21(e) “When bitmap images are used to identify controls, status indicators, or other programmatic elements, the meaning assigned to those images shall be consistent throughout an application's performance.”
Visual Basic, as with all languages, can use graphics along with text to identify the meaning assigned to screen-accessible controls. For example, a graphical button can contain both text and an image within its display area. Visual and textual attributes provide assistive technology with the purpose of the control. Visual Basic utilizes Resource files to identify elements in one location for an application. Resource files increase application performance through on-demand loading and eliminate the need for string literals, pictures, and data. They also eliminate the need to recode and recompile when changes need to be made for future application releases.
This code loads an image, identified as 10, into a picture box, named Picture1, from the resource file at run time:
Set Picture1.Picture = LoadResPicture(10, vbResBitmap)
Provision F
§1194.21(f) “Textual information shall be provided through operating system functions for displaying text. The minimum information that shall be made available is text content, text input caret location, and text attributes.”
Text Content
Visual Basic applications, which intercept any method of user input, must also allow the execution of built-in operating system functions to execute. When these applications intercept data and use their own methods of display, built-in operating system function calls must also be used. Screen readers and other assistive technologies depend on these operating system function calls to accurately convey screen information. By default, Visual Basic uses the built-in operating system function calls for user input and display.
A variety of methods are available to the developer to add text to editable and static controls within Visual Basic. Utilizing standard operating system text display functions, text information will be available to assistive technologies. In addition, most Windows controls that are standard within the Visual Basic IDE are already automatically accessible to assistive technologies since Windows exposes their attributes automatically. Any assistive technology, such as screen readers, utilizing the Microsoft Active Accessibility tools will have access to standard control attributes.
Let's look at two functions that provide the necessary operating system interface for text updates.
‘ Using standard Windows messages display the new edit text ‘ Initialize the text to display Dim EditText As String EditText = “Textual information shall be provided through operating _ system functions for displaying text. The minimum information _ that shall be made available is text content, text input caret _ location, and text attributes.” ‘ Display the edit text in a message box. MsgBox(EditText) ‘ Using a dialog function display the new edit text ‘ Initialize the text to display Dim EditText As String EditText = “Textual information shall be provided through operating _ system functions for displaying text. The minimum information _ that shall be made available is text content, text input caret _ location, and text attributes.” ‘ Display the edit text in a text box. TextDetails.Text = EditText
Caret Locations
There are a number of caret functions that can alter the system caret. One of the main functions to use would be the Focus method to set the system focus to a specific control within a window. This, in turn, will change the system caret to that control or field.
An example of this code is shown here:
‘ Set the focus and system caret to the edit text field TextDetails.SetFocus()
Provision G
§1194.21(g) “Applications shall not override user selected contrast and color selections and other individual display attributes.”
Visual Basic utilizes, by default, the current user’s Windows operating system settings. Color, contrast, and screen and font sizes are displayed relative to the current Windows settings. During application development, objects retain the proper display attributes (e.g., color, contrast, etc.) as they are added to the form. To avoid overriding the settings, do not use the Properties list to code or change control attributes.
Provision H
§1194.21(h) “When animation is displayed, the information shall be displayable in at least one non-animated presentation mode at the option of the user.”
If you are working in Visual Basic, remediation involves the replacement of animated objects with non-animated ones.
You can provide the user with the option to replace an animated image with a static single image of the same object. This is accomplished by creating and providing access to a replacement option (e.g., button click or key press combination). Let's take a look at an example of the code that could be used.
Private Sub Command1_Click()
‘ Change the default Animated Image to a static one
Picture1.Picture = LoadPicture("c:\myapp\pictures\StaticPic.gif")
End Sub
If you need to incorporate a Resource File the code would then look like this:
Private Sub Command1_Click() ‘ Change the default Animated Image to a static one Picture1.Picture = LoadResPicture(5, vbResBitmap) End Sub
You can also remove the animated picture from the form by using the following code:
Private Sub Command1_Click()
‘ Remove the default Animated Image at run time
Picture1.Picture = LoadPicture("")
End Sub
Provision I
§1194.21(i) “Color coding shall not be used as the only means of conveying information, indicating an action, prompting a response, or distinguishing a visual element.”
Button colors, such as red and green (which have a universal meaning of "stop" and "go") can be accompanied by descriptive text that conveys the purpose of the button to a user with a visual disability. "Select to Start," "Select to Begin," "Select to Stop," and "Select to Cancel" all aptly describe what red and green would symbolize for the user. The name of a color can also be incorporated into button text (so that the button's attributes are described exactly).
Let's take a look at some code. This example is used to display text on a button:
Button1.Caption = “Select Green Button to Start”
Provision J
§1194.21(j) “When a product permits a user to adjust color and contrast settings, a variety of color selections capable of producing a range of contrast levels shall be provided.”
Visual Basic has predefined controls that allow you to create grids of information so that a variety of color options are available to the user.
Let's take a look at an example. In Visual Basic, a developer could use this code to create a grid of 216 unique colors:
Private Sub Form_Load()
Call CreatePallet
Me.MSHFlexGrid1.GridLines = flexGridFlat
Call grdSetup
End Sub
Public Sub grdSetup()
With Me.MSHFlexGrid1
.ColWidth(0) = .RowHeight(0)
.RowHeight(1) = .RowHeight(1)
.Row = 0
.RowHeight(0) = 0
.ColWidth(0) = 0
For i = 1 To .Cols - 1
.ColWidth(i) = .RowHeight(1)
Next
End With
End Sub
Private Sub CreatePallet()
Dim i As Long
Dim j As Long
Dim r As Long
Dim g As Long
Dim b As Long
Dim x As Long
Dim y As Long
Dim one As Long
Dim two As Long
x = 1
y = 1
one = 1
two = 6
For i = 1 To Me.MSHFlexGrid1.Cols - 1
For r = 0 To 255 Step 51
For g = 0 To 255 Step 51
For b = 0 To 255 Step 51
If Me.MSHFlexGrid1.Rows = y Then Exit For
If (y Mod 2) = 0 Then
MSHFlexGrid1.Row = two
Else
MSHFlexGrid1.Row = one
End If
MSHFlexGrid1.Col = x
MSHFlexGrid1.CellBackColor = RGB(r, g, b)
x = x + 1
If x = 19 Then
x = 1
y = y + 1
If (y Mod 2) = 0 Then
two = two + 1
Else
one = one + 1
End If
End If
Next
Next
Next
Next
End Sub
The grid produced by this code is similar to the Control Panel that appears in the Windows operating system.
Provision K
§1194.21(k) “Software shall not use flashing or blinking text, objects, or other elements having a flash or blink frequency greater than 2 Hz and lower than 55 Hz.”
Visual Basic developers can control the frequency of blinking text through the use of the Visual Basic Timer control.
This control measures time in intervals of milliseconds. This means that a conversion rate of 1000/second must be considered during development. Since the converted rate for a Hertz is 1 to 1 (for Hertz to seconds), you should adapt this code to set the rates in your form:
Private Sub cmdSave_Click()
lblNameFlash.Caption = "Welcome: " & _
txtFirstName.Text & " " & txtLastName.Text
' Set timer to a random interval not between 182 (2 Hz) and 500 (55 Hz)
' Flashing can't be greater than 2Hz and lower than 55Hz.
' Flash the label slowly (less than 2Hz).
RandomizetmrFlasher.Interval = Int((181 * Rnd) + 1)
End Sub
Private Sub tmrFlasher_Timer()
' Blink the User's name to draw their attention.
If lblNameFlash.Visible = True Then
lblNameFlash.Visible = False
Else
lblNameFlash.Visible = True
End If
End Sub
Provision L
§1194.21(l) “When electronic forms are used, the form shall allow people using assistive technology to access the information, field elements, and functionality required for completion and submission of the form, including all directions and cues.”
Visual Basic, as with all languages, permits the user to access active controls on its forms by pressing the Tab key and accessing each control in the predefined order as coded by the developer.
When using Visual Basic, utilize these approaches to insure that all electronic forms are usable:
This code allows the user to access active controls on Visual Basic forms:
Private Sub Form_Load()
' Set the tab stops for all of the controls which can get the focus.
txtFirstName.TabStop = True
txtFirstName.TabIndex = 2
txtLastName.TabStop = True
txtLastName.TabIndex = 4
cmdSave.TabStop = True
cmdSave.TabIndex = 5
End Sub
The code produces this name information box:

Designating these tab stops is important as they allow intuitive navigation of the application by the user.