VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5520
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   5520
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command2 
      Caption         =   "Save + Load"
      Height          =   375
      Left            =   4080
      TabIndex        =   6
      Tag             =   "save+load"
      Top             =   600
      Width           =   1335
   End
   Begin VB.Frame Frame1 
      Caption         =   "Frame1"
      Height          =   975
      Index           =   1
      Left            =   2040
      TabIndex        =   5
      Top             =   1080
      Width           =   1815
   End
   Begin VB.Frame Frame1 
      Caption         =   "Frame1"
      Height          =   975
      Index           =   0
      Left            =   120
      TabIndex        =   4
      Top             =   1080
      Width           =   1815
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   375
      Index           =   1
      Left            =   2040
      TabIndex        =   3
      Top             =   600
      Width           =   1815
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Index           =   1
      Left            =   2040
      TabIndex        =   2
      Text            =   "Text1"
      Top             =   120
      Width           =   1815
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   375
      Index           =   0
      Left            =   120
      TabIndex        =   1
      Top             =   600
      Width           =   1815
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   120
      Width           =   1815
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   255
      Index           =   1
      Left            =   2040
      TabIndex        =   8
      Top             =   2160
      Width           =   1815
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   7
      Top             =   2160
      Width           =   1815
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Enum controlType
    nTextBox
    nCommandButton
    nFrame
    nLabel
End Enum

Private Type minorSettingsType
    name As String
    text As String
    type As Long
End Type
Private Type globalSettingsType
    myCtrl() As minorSettingsType
End Type



Private Sub Command2_Click()
    
    Dim myControl As Control
    
    
    
    '' save the settings
    ''
    Dim x As globalSettingsType
    ReDim x.myCtrl(0)
    For Each myControl In Controls
        With x.myCtrl(UBound(x.myCtrl))
            .name = myControl.name
            Select Case TypeName(myControl)
                Case "TextBox":       .type = nTextBox:       .text = myControl.text
                Case "CommandButton": .type = nCommandButton: .text = myControl.Caption
                Case "Label":         .type = nLabel:         .text = myControl.Caption
                Case "Frame":         .type = nFrame:         .text = myControl.Caption
            End Select
        End With
        ReDim Preserve x.myCtrl(UBound(x.myCtrl) + 1)
    Next
    Open "c:\settings.dat" For Binary As #1
        Put #1, , x
    Close #1
    MsgBox "Have saved settings. Now about to clear form", vbInformation
    
    '' clear the screen
    ''
    For Each myControl In Controls
        If Not myControl.Tag = "save+load" Then
            Select Case True
                Case TypeName(myControl) = "TextBox": myControl.text = ""
                Case (TypeName(myControl) = "CommandButton") Or _
                    (TypeName(myControl) = "Label") Or _
                    (TypeName(myControl) = "Frame"): myControl.Caption = ""
            End Select
        End If
    Next
    MsgBox "Screen cleared. Now loading information back in", vbInformation
    
    '' read back the settings
    ''
    Dim y As globalSettingsType, i As Long
    Open "c:\settings.dat" For Binary As #1
        Get #1, , y
    Close #1
    For i = 0 To UBound(y.myCtrl) - 1
        For Each myControl In Controls
            If myControl.name = y.myCtrl(i).name Then
                Select Case True
                    Case y.myCtrl(i).type = nTextBox: myControl.text = y.myCtrl(i).text
                    Case (y.myCtrl(i).type = nCommandButton) Or _
                         (y.myCtrl(i).type = nFrame) Or _
                         (y.myCtrl(i).type = nLabel): myControl.Caption = y.myCtrl(i).text
                End Select
            End If
        Next
    Next
    MsgBox "Information loaded", vbInformation
    
End Sub
