|
-
Feb 2nd, 2001, 05:29 PM
#1
Thread Starter
Member
oki dokey, one more question...
I've got a form with 200+ controls (don't ask .) I've created a class to loop through all the controls on the form and save their values to an .ini file. I'm only interested in saving textboxes, combo lists, etc. - not every control.
How should I go about determining what type of control a control is?
Thanks a million!
-
Feb 2nd, 2001, 05:37 PM
#2
Code:
Private Sub Command1_Click()
Dim MyControl As Control
Dim iList As Integer
For Each MyControl In Me.Controls
If TypeOf MyControl Is TextBox Then
'save code
Open "C:\MyFile.txt" For Append As #1
Print #1, MyControl.Text
Close #1
End If
If TypeOf MyControl Is ComboBox Then
Open "C:\MyFile.txt" For Append As #1
For iList = 0 To MyControl.ListCount - 1
Print #1, MyControl.List(iList)
Next iList
Close #1
End If
Next
End Sub
Small mistake, thanks for correcting me Megatron .
-
Feb 2nd, 2001, 05:42 PM
#3
Try this:
Code:
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "TextBox" Then
'Do something
End If
Next
Hope this helps.
-
Feb 2nd, 2001, 05:43 PM
#4
Oooh... I never get to post first.
-
Feb 2nd, 2001, 06:28 PM
#5
Matthew Gates: Your line for saving the ComboBox reads For iList = 0 To Combo1.ListCount - 1; It should be For iList = 0 To MyControl.ListCount - 1
Freefly21:
Since ComboBoxes and Listboxes are the same (with respect to their list properties), you can save both of them with the same code.
Code:
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
Open "C:\MyFile.txt" For Append As #1
Print #1, ctl.Text
Close #1
End If
If (TypeOf ctl Is ComboBox) Or (TypeOf ctl Is ComboBox) Then
Open "C:\MyFile.txt" For Append As #1
For i = 0 To ctl.ListCount - 1
Print #1, ctl.List(i)
Next i
Close #1
End If
Next ctl
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|