Natavia Finnie
asked on
GetNextControl is saving repeated data when used with for loop
Dim cntrl As Control
Dim I As Integer
For I = 0 To Me.tabControl.TabPages.Count-1
cntrl = Me.tabControl.TabPages(I)
Do
cntrl = Me.GetNextControl(cntrl, True)
If TypeOf cntrl Is TextBox Then
outputFile.wplWriteLine(cntrl.Name, Trim(cntrl.Text))
End If
......other code here.....
Loop While Not (cntrl Is Nothing) And (cntrl.Parent.Name <> Me.tabControl.TabPages(I).Name)
Next I
I am saving data from all my controls on the interface using the code here, which works great. One of my controls is a CheckedListBox which is located on the first tab. This CheckedListBox show/hides other tabs. The problem is that it saves the first tab's data then moves on to the other tabs and saves the data per tab. Then it loops back and continues to save the data again, which is shown in the attached file.I tried using a uniqueTabNameList that adds the tab name and then continues to process the code if the tab name is NOT there...and that does not work either.
' the code below is entered after cntrl = Me.AllTabs.TabPages(i) and before the 'Do"
If Not tabNameList.Contains(cntrl
tabNameList.Add(cntrl.Name
... embedded code here....
end if
Dim cntrl As Control
Dim I As Integer
For I = 0 To Me.tabControl.TabPages.Count-1
cntrl = Me.tabControl.TabPages(I)
Do
cntrl = Me.GetNextControl(cntrl, True)
If TypeOf cntrl Is TextBox Then
outputFile.wplWriteLine(cntrl.Name, Trim(cntrl.Text))
End If
......other code here.....
Loop While Not (cntrl Is Nothing) And (cntrl.Parent.Name <> Me.tabControl.TabPages(I).Name)
Next I
savingGeneral2.txt
ASKER
@duy,
It is not doing anything. Nothing is saving. I had to change
Me.tabControl.TabPages(I). Count to Me.tabControl.TabPages(I). Count.Cont rols.Count -1 to make the eror message go away that I was receiving.
Help!!!!!
It is not doing anything. Nothing is saving. I had to change
Me.tabControl.TabPages(I).
Help!!!!!
@taviaf: Sorry, my bad copy/paste. There is an error line line 7, it should be Me.tabControl.TabPages(I). Controls.C ount instead of Me.tabControl.TabPages(I). Count
Dim cntrl As Control
Dim I As Integer
Dim J As Integer
For I = 0 To Me.tabControl.TabPages.Count-1
cntrl = Me.tabControl.TabPages(I)
For J = 1 To Me.tabControl.TabPages(I).Controls.Count
cntrl = Me.GetNextControl(cntrl, True)
If TypeOf cntrl Is TextBox Then
outputFile.wplWriteLine(cntrl.Name, Trim(cntrl.Text))
End If
......other code here.....
Next J
Next I
ASKER
@Duy,
I had already caught that and fixed that error. I also added the Do-While loop and it is still not iterating through any of the controls. cntrl returns nothing so nothing is saving.....
It is not working with or without the Do-While loop
I had already caught that and fixed that error. I also added the Do-While loop and it is still not iterating through any of the controls. cntrl returns nothing so nothing is saving.....
It is not working with or without the Do-While loop
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Duy,
I still get NOTHING.....I do believe that it works for you. It is just not working for what I am trying to do, for some reason. I have 13 tab pages with several group boxes per page. Each group box may have several different controls on them, including text boxes, combo boxes, datagrids, and/or other group boxes and more. I am handling each control differently depended on type.
I still get NOTHING.....I do believe that it works for you. It is just not working for what I am trying to do, for some reason. I have 13 tab pages with several group boxes per page. Each group box may have several different controls on them, including text boxes, combo boxes, datagrids, and/or other group boxes and more. I am handling each control differently depended on type.
For I = 0 To AllTabs.TabPages.Count - 1
cntrl = AllTabs.TabPages(I)
For J = 1 To AllTabs.TabPages(I).Controls.Count - 1
cntrl = Me.GetNextControl(cntrl, True)
' Search for a TextBox
If TypeOf cntrl Is TextBox Then
outputFile.wplWriteLine(cntrl.Name, Trim(cntrl.Text))
End If
' Search for a DateTimePicker
Dim ctlDate As DateTimePicker
If TypeOf cntrl Is DateTimePicker Then
ctlDate = cntrl
If Me.ProtocolReport.Checked Then
outputFile.wplWriteLine(ctlDate.Name, ctlDate.Value.ToString("MMMM yyyy"))
ElseIf Me.FinalReport.Checked Then
outputFile.wplWriteLine(ctlDate.Name, ctlDate.Value.ToString("MMMM dd, yyyy"))
End If
End If
'Search for a RadioButton
Dim ctlRadioBtn As RadioButton
If TypeOf cntrl Is RadioButton Then
ctlRadioBtn = cntrl
If ctlRadioBtn.Checked Then
outputFile.wplWriteLine(ctlRadioBtn.Name, "TRUE")
Else
outputFile.wplWriteLine(ctlRadioBtn.Name, "")
End If
End If
Next
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@taviaf; You're welcome :).
And since I didn't help to solve the issue, so it's totally fine if you just close the request without giving me any point.
And since I didn't help to solve the issue, so it's totally fine if you just close the request without giving me any point.
ASKER
I was able to fix the problem and i would like to share the code as a solution....
ASKER
@Duy,
It was your assistance that led me to the following code that works with GetNextControl. All we had to was set GetNextControl = TabPage.GetNextControl because it will get the next control of the tab page. I kept setting GetNextControl = Me.GetNextControl and it would start with the form and move forward and that is why it kept giving me duplicates. It was going back-and-forth. #TeamWork
It was your assistance that led me to the following code that works with GetNextControl. All we had to was set GetNextControl = TabPage.GetNextControl because it will get the next control of the tab page. I kept setting GetNextControl = Me.GetNextControl and it would start with the form and move forward and that is why it kept giving me duplicates. It was going back-and-forth. #TeamWork
For Each TabPage As TabPage In Me.AllTabs.TabPages
Dim cntrl As Control = TabPage
Do Until cntrl Is Nothing
cntrl = TabPage.GetNextControl(cntrl, True)
*****code here******
Loop
Next
Sample code (tested):
Open in new window