Microsoft KB Archive/214830

= BUG: Tab Control Does Not Initialize Correctly from Load Event Using Control Array =

Article ID: 214830

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q214830



SYMPTOMS
The Tab Control is not able to initialize correctly when placing controls that are members of a control array on separate tabs from the load event of the form on which the Tab Control was placed. All the controls are drawn on a single tab instead of on the tabs for which they were intended. This problem occurs in Visual Basic 6.0 and Visual Basic 5.0 with service pack 2 or later.



Method 1
To work around this problem, move the code that places controls on the tabs from the load event to the Activate event of the form. Use a global flag to determine if the Activate event was fired without unloading the form. For example, use the sample project created in "Steps to Reproduce Behavior" below and follow these steps:  Move the code listed in step 5 from the Load event to the Activate event of Form1.  Modify the code in the Activate event by replacing it with the following: Dim i as integer If ActivateFlag = False Then For i = 1 To 3 SSTab1.Tab = i - 1 Load Text1(i) Set Text1(i).Container = SSTab1 Text1(i).Top = i * (SSTab1.TabHeight + 100) Text1(i).Left = i * 200 Text1(i).Visible = True Next i   ActivateFlag = True End If                     From the Project menu, add a Standard Module (Module1) to the project and add the following line of code to Module1: Public ActivateFlag as Boolean   Place the following line of code in the Unload event of Form1: ActivateFlag = False  Run the application and note that all members of the TextBox control array are displayed on the correct tab.

Method 2
Another workaround is to place the control loading code in a global procedure. Call this procedure before calling the Show method for the form containing the tab control. For example:  Follow the steps 1 through 4 in "Steps to Reproduce Behavior" below.</li>  From the Project menu, add a (BAS) Module to the project and copy and paste the following code to General Declarations area of Module1: Sub MyTabSetup Dim i As Integer With Form1 For i = 1 To 3 .SSTab1.Tab = i - 1 Load .Text1(i) Set .Text1(i).Container = .SSTab1 .Text1(i).Top = i * (.SSTab1.TabHeight + 100) .Text1(i).Left = i * 200 .Text1(i).Visible = True Next i   End With End Sub </li>  Create a Sub Main procedure to be set as Startup object for the project by adding the following code to Module1: Sub Main MyTabSetup Form1.Show End Sub </li> From the Project menu, select Project1 Properties, and on the General tab, select Sub Main as the Startup Object.</li> Run the application and there should be one TextBox on each tab.</li>  The procedure can also be called before the Show method of the form when ever the form needs to be displayed. For example, if the form was closed and needed to be shown from the click event of a CommandButton, simply place the following code in the click event of the CommandButton: Private Sub Command1_Click MyTabSetup Form1.Show End Sub </li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

Steps to Reproduce Behavior
 Create a Standard EXE project. Form1 is created by default.</li> From the Project menu, select Components, select Microsoft Tabbed Dialog Control 6.0, and click OK.</li> Draw the tab control (SSTab1) on the default form (Form1).</li> Draw a TextBox (Text1) on Form1 and set the Index property of Text1 to 0 and set the Visible property to False.</li>  Place the following code in the load event of Form1: Dim i as integer For i = 1 To 3 SSTab1.Tab = i - 1 Load Text1(i) Set Text1(i).Container = SSTab1 Text1(i).Top = i * (SSTab1.TabHeight + 100) Text1(i).Left = i * 200 Text1(i).Visible = True Next i Run the program and note that all the TextBox controls appear on a single tab instead of one on each tab. </li></ol>

Keywords: kbbug kbtabctrl kbpending KB214830

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.