I'm having few troubles by writing to textfiles...The code below is the code I wrote a few months ago. It simply writes Textboxes, OptionButtons, Checkboxes and Comboboxes to a specified file.

Text1|Valuetext
Text2|Blabla
CboBla|2
ChkBlabla|1

But I want the code not only to enter the name of the textbox...but also the Name of the form it belongs to. If the control is a control-array I also want his index....So it should look like this...

frmInput.Text1|Valuetext
frmInput.Text2(0)|BlaOne
frmInput.Text2(1)|BlaTwo

Hopefully someone can give me a hand...

VB Code:
  1. Option Explicit
  2. Public MyControl As Control
  3. Public FileName As String
  4. Public TextInfo As String
  5.  
  6. Public Sub Command1_Click()
  7. Dim fnum As String
  8.  
  9.     On Error GoTo ErrHandle
  10.  
  11.         frmInput.FileWindow.DialogTitle = "Save As"
  12.         frmInput.FileWindow.Filter = "MYFILE(*.myf)|*.myf|All Files(*.*)|*.*"
  13.         frmInput.FileWindow.FilterIndex = 0
  14.         frmInput.FileWindow.ShowSave
  15.        
  16.         fnum = FreeFile
  17.        
  18.         TextInfo = ""
  19.        
  20.         For Each MyControl In frmInput.Controls
  21.             If TypeOf MyControl Is TextBox Then
  22.             TextInfo = TextInfo & MyControl.Name & "|" & MyControl.Text & vbCrLf
  23.             ElseIf TypeOf MyControl Is OptionButton Then
  24.             TextInfo = TextInfo & MyControl.Name & "|" & MyControl.Value & vbCrLf
  25.             ElseIf TypeOf MyControl Is CheckBox Then
  26.             TextInfo = TextInfo & MyControl.Name & "|" & MyControl.Value & vbCrLf
  27.             ElseIf TypeOf MyControl Is ComboBox Then
  28.             TextInfo = TextInfo & MyControl.Name & "|" & MyControl.ListIndex & vbCrLf
  29.             End If
  30.         Next
  31.  
  32.         If Not frmInput.FileWindow.FileName = "" Then
  33.         Open frmInput.FileWindow.FileName For Output As #fnum
  34.         Print #fnum, TextInfo
  35.         Close #fnum
  36.        
  37.         MsgBox "File: (" & frmInput.FileWindow.FileName & ") saved correctly", vbInformation, "save"
  38.         End If
  39. Exit Sub
  40.    
  41. ErrHandle:
  42.     If frmInput.FileWindow.CancelError = True Then
  43.         MsgBox "No file saved", vbCritical, "Save"
  44.     Else
  45.         MsgBox "Error Bla Bla", vbCritical, "Error"
  46.     End If
  47. End Sub