Attribute VB_Name = "File_Bits"
Public Sub Load_File()


Dim file_temp, temp As String
Dim N As Integer, i As Integer, j As Integer, Split As Integer, Split_2 As Integer
Dim Sub_Num As Integer, temp_pos As Long, temp_data1 As Integer, temp_data2 As Integer
Dim temp_string2 As String, temp_string As String, stemp As String
Dim position As Long, Filenum As Integer, temp_pos2 As Long
Dim Screen_Max As Integer
Dim ArtNet_Needed As Boolean

Load frmOpenDlg
If Current_Project <> "" Then
    frmOpenDlg.dlgOpenFile.FileName = Current_Project
Else
    frmOpenDlg.dlgOpenFile.FileName = "*.xml"
End If

frmOpenDlg.dlgOpenFile.Filter = "XML|*.xml"
frmOpenDlg.dlgOpenFile.DialogTitle = " Load DMX Desk Project"
frmOpenDlg.dlgOpenFile.ShowOpen
If Err <> 0 Then
        ' No file selected from the Open File dialog box.
        Exit Sub
End If
Current_Project = frmOpenDlg.dlgOpenFile.FileName
currentshow = Current_Project
   
If Current_Project = "*.xml" Then Exit Sub
    Filenum = FreeFile
    Open Current_Project For Binary Access Read As #Filenum
    stemp = Space$(LOF(Filenum))
    Get #Filenum, , stemp
    Close #Filenum
    
    '*********  look for Project ********************************
    position = 1
    temp_string = FindNode(0, stemp, "Project")
    
    If temp_string <> vbNullString Then
        Desk_Project.Name = FindNode(1, temp_string, "Name")
        Desk_Project.Date = FindNode(1, temp_string, "Date")
        Desk_Project.Version = FindNodeValue(1, temp_string, "Version")
        Desk_Project.Text = FindNode(1, temp_string, "Text")
        DMX_Adapter = FindNodeValue(1, temp_string, "Adapter")
        'DMX_Desk_Network = FindNodeValue(1, temp_string, "Network")
        ArtNet = False
        i = 0
Project_Loop:
        temp_string2 = FindNode(position, temp_string, "Network")
        If temp_string2 <> vbNullString Then
            Sub_Num = FindNodeValue(1, temp_string2, "Universe")
            Art_Data(Sub_Num).Universe = Sub_Num
            Art_Data(Sub_Num).Active = True
            ArtNet_Needed = True
            GoTo Project_Loop
        End If
        
        BCF_Status = FindNodeValue(1, temp_string, "BCF")
        If BCF_Status > 0 Then ' Connect to BCF
                Load BCF
                BCF.Hide
                BCF.Connect_BCF
        End If
        If ArtNet_Needed = True Then
            
                Load Art_Config
                Art_Config.Configure_art_net
            
        End If
    End If
        
    ' ****************** look for Submixes **********************
    
    
    position = 1
    
subloop:
    temp_string = FindNode(position, stemp, "Submix")
    If temp_string <> vbNullString Then
        temp_pos = 1
        Sub_Num = FindNodeValue(0, temp_string, "Num")
        Sub_Mix(Sub_Num).Name = FindNode(0, temp_string, "Name")
        Sub_Mix(Sub_Num).Colour = FindNode(0, temp_string, "Colour")
        For i = 0 To 63
            Sub_Mix(Sub_Num).Channel(i) = 0
            Sub_Mix(Sub_Num).Level(i) = 0
        Next i
        j = 0
subloop2:
        temp_data1 = FindNodeData(temp_pos, temp_string, "Level", temp_data2)
        If temp_data1 <> 0 Or temp_data2 <> 0 Then
            Sub_Mix(Sub_Num).Level(j) = temp_data2 ' Level
            Sub_Mix(Sub_Num).Channel(j) = temp_data1 ' Channel
            j = j + 1
            GoTo subloop2
        End If
        
        GoTo subloop:
    End If

'   ***************** Fader Names ********************

 position = 1

Fader_Name_Loop:
    temp_string = FindNode(position, stemp, "FaderName")
    If temp_string <> vbNullString Then
        temp_data1 = FindNode(1, temp_string, "Num")
        FaderNames(temp_data1).Name = FindNode(1, temp_string, "Desc")
        FaderNames(temp_data1).Short_Name = FindNode(1, temp_string, "Name")
        FaderNames(temp_data1).Colour = FindNode(1, temp_string, "Colour")
        FaderNames(temp_data1).Main_Fade = FindNodeValue(1, temp_string, "Main_F")
        FaderNames(temp_data1).Cross_Fade = FindNodeValue(1, temp_string, "Cross_F")
        GoTo Fader_Name_Loop
    End If

' ****************** Buttons ***********************

position = 1
        Call Clear_Buttons
Buttonloop:
    temp_string = FindNode(position, stemp, "Button")
    If temp_string <> vbNullString Then
        temp_data1 = FindNode(1, temp_string, "Number")
         
         Button(temp_data1).Name = FindNode(1, temp_string, "Name")
         Button(temp_data1).Number = FindNodeValue(1, temp_string, "Value")
         Button(temp_data1).Colour = FindNode(1, temp_string, "Colour")
         Button(temp_data1).Function = FindNodeValue(1, temp_string, "Function")
         Button(temp_data1).Latch = FindNodeValue(1, temp_string, "Latch")
         Button(temp_data1).Channel1 = FindNodeValue(1, temp_string, "Channel1")
         Button(temp_data1).Channel2 = FindNodeValue(1, temp_string, "Channel2")
         Button(temp_data1).Channel3 = FindNodeValue(1, temp_string, "Channel3")
         Button(temp_data1).Data1 = FindNodeValue(1, temp_string, "Data1")
         Button(temp_data1).Data2 = FindNodeValue(1, temp_string, "Data2")
         Button(temp_data1).Data3 = FindNodeValue(1, temp_string, "Data3")
         Button(temp_data1).Level = FindNodeValue(1, temp_string, "Level")
         Button(temp_data1).Preset = FindNodeValue(1, temp_string, "Preset")
         GoTo Buttonloop
    End If
    
         
' ****************** Faders ***********************

position = 1
        Call Clear_Faders
Faderloop:
    temp_string = FindNode(position, stemp, "Fader")
    If temp_string <> vbNullString Then
        temp_data1 = FindNode(1, temp_string, "Number")
         
         Fader(temp_data1).Name = FindNode(1, temp_string, "Name")
         Fader(temp_data1).Number = FindNodeValue(1, temp_string, "Value")
         Fader(temp_data1).Colour = FindNode(1, temp_string, "Colour")
         Fader(temp_data1).Function = FindNodeValue(1, temp_string, "Function")
         Fader(temp_data1).Channel1 = FindNodeValue(1, temp_string, "Channel1")
         Fader(temp_data1).Channel2 = FindNodeValue(1, temp_string, "Channel2")
         Fader(temp_data1).Channel3 = FindNodeValue(1, temp_string, "Channel3")
         Fader(temp_data1).Data1 = FindNodeValue(1, temp_string, "Data1")
         Fader(temp_data1).Data2 = FindNodeValue(1, temp_string, "Data2")
         Fader(temp_data1).Data3 = FindNodeValue(1, temp_string, "Data3")
         Fader(temp_data1).Level = FindNodeValue(1, temp_string, "Level")
         
         GoTo Faderloop
    End If
' ********************* Patches *****************************


    temp_string = FindNode(position, stemp, "Patch")
    If temp_string <> vbNullString Then
            temp_pos = 1
            i = 0
Patchloop:
            Split = InStr(temp_pos, temp_string, ",")
            If Split = 0 Then ' Last one
                    string_temp2 = Right$(temp_string, Len(temp_string) - temp_pos + 1)
                    Split_2 = InStr(string_temp2, ":")
        
                    If Split_2 > 0 Then
                        outpatch(val(Left$(string_temp2, Split_2)) - 1) = val(Right$(string_temp2, Len(string_temp2) - Split_2))
                    End If
                    GoTo PatchExit
            End If
            string_temp2 = Mid$(temp_string, temp_pos, Split - temp_pos)
            Split_2 = InStr(string_temp2, ":")
        
            If Split_2 > 0 Then
                 outpatch(val(Left$(string_temp2, Split_2))) = val(Right$(string_temp2, Len(string_temp2) - Split_2))
             '    Debug.Print outpatch(val(left$(string_temp2, Split_2))) & "  " & val(left$(string_temp2, Split_2)) & "  " & val(right$(string_temp2, Len(string_temp2) - Split_2))
            End If
            temp_pos = Split + 1
            'I = I + 1
            GoTo Patchloop
    End If
PatchExit:
    
' ****************** Screen *****************************

    position = 1
    Screen_Max = 0
screenloop:
    temp_string = FindNode(position, stemp, "Screen")
    
    If temp_string <> vbNullString Then
        Sub_Num = FindNode(1, temp_string, "Num")
        If Sub_Num > Screen_Max Then Screen_Max = Sub_Num   ' Look for highest screen
        Screen(Sub_Num).Name = FindNode(1, temp_string, "Name")
        Screen(Sub_Num).Next = FindNodeValue(1, temp_string, "Next")
        Screen(Sub_Num).Instant = FindNodeValue(1, temp_string, "Instant")
        Screen(Sub_Num).Colour = FindNode(1, temp_string, "Colour")
        Screen(Sub_Num).Preset_Main = FindNodeValue(1, temp_string, "Preset_l")
        Screen(Sub_Num).Auto_next = FindNodeValue(1, temp_string, "Auto")
        Screen(Sub_Num).Fade_Time = FindNodeValue(1, temp_string, "Time")
        Screen(Sub_Num).Delay = FindNodeValue(1, temp_string, "Delay")
        temp_pos = 1

screenloop2:
        temp_data1 = FindNodeData(temp_pos, temp_string, "Fad_Sel", temp_data2) ' Load Fader Levels
        If temp_data1 > 0 Or temp_data2 > 0 Then
            Screen(Sub_Num).Fader_Sel(temp_data1) = temp_data2
            GoTo screenloop2
        End If
        
        temp_pos = 1
screenloop3:
        temp_data1 = FindNodeData(temp_pos, temp_string, "Preset", temp_data2) ' Load Preset Levels
        If temp_data1 > 0 Or temp_data2 > 0 Then
            Screen(Sub_Num).Presets(temp_data1) = temp_data2
            GoTo screenloop3
        End If

        temp_pos = 1
screenloop4:
        temp_data1 = FindNodeValue(temp_pos, temp_string, "But_Sel") ' Load Buttons Levels
        If temp_data1 > 0 Then
            Screen(Sub_Num).Button_Sel(temp_data1) = True
            GoTo screenloop4
        End If
        
        GoTo screenloop:
        
    End If
    If Screen_Max > 0 Then
        screen_end = Screen_Max
    End If
    
' ************************  Chase **************************
 position = 1
chaseloop:
    temp_string = FindNode(position, stemp, "Chase")
    
    If temp_string <> vbNullString Then
        Sub_Num = FindNode(1, temp_string, "Num")
        Chase(Sub_Num).Name = FindNode(1, temp_string, "Name")
        Chase(Sub_Num).Colour = FindNode(1, temp_string, "Colour")
        Chase(Sub_Num).Steps = FindNodeValue(1, temp_string, "Steps")
        Chase(Sub_Num).Fixture = FindNodeValue(1, temp_string, "Fixture")
        Chase(Sub_Num).Loop = FindNodeValue(1, temp_string, "Loop")
        temp_string3 = FindNode(1, temp_string, "Channels")
        
        temp_pos = 1
        N = 0
Chaseloop6:
        Split = InStr(temp_pos, temp_string3, ":")
        If Split <> 0 Then
            Chase(Sub_Num).channels(N) = val(Mid$(temp_string3, temp_pos, Split - temp_pos))
            'Chase_channels(I,N) = val(mid$(temp_string3, temp_pos, Split - temp_pos))
            temp_pos = Split + 1
            N = N + 1
            GoTo Chaseloop6
        Else
            Chase(Sub_Num).channels(N) = val(Right$(temp_string3, Len(temp_string3) - temp_pos + 1))
            'Chase_channels(I, N) = val(right$(temp_string3, Len(temp_string3) - temp_pos + 1))
        End If
                
        temp_pos2 = 1
chaseloop2:
        temp_string2 = FindNode(temp_pos2, temp_string, "Step")
    
        If temp_string2 <> vbNullString Then
            i = FindNode(1, temp_string2, "Num")
            Chase(Sub_Num).Speed(i) = FindNode(1, temp_string2, "Speed")
            Chase(Sub_Num).Fade_Time(i) = FindNode(1, temp_string2, "Time")
            
            temp_string3 = FindNode(1, temp_string2, "Data") ' Load Chase Data
            temp_pos = 1
            N = 0
Chaseloop3:
            Split = InStr(temp_pos, temp_string3, ":")
            If Split <> 0 Then
                Chase(Sub_Num).data(i, N) = val(Mid$(temp_string3, temp_pos, Split - temp_pos))
                temp_pos = Split + 1
                N = N + 1
                GoTo Chaseloop3
            Else
                Chase(Sub_Num).data(i, N) = val(Right$(temp_string3, Len(temp_string3) - temp_pos + 1))
            End If
            
            temp_string3 = FindNode(1, temp_string2, "Fade") ' Load Fade Data
            temp_pos = 1
            N = 0
Chaseloop4:
            Split = InStr(temp_pos, temp_string3, ":")
            If Split <> 0 Then
                Chase(Sub_Num).Fade(i, N) = val(Mid$(temp_string3, temp_pos, Split - temp_pos))
                temp_pos = Split + 1
                N = N + 1
                GoTo Chaseloop4
            Else
                Chase(Sub_Num).Fade(i, N) = val(Right$(temp_string3, Len(temp_string3) - temp_pos + 1))
            End If
       
            temp_string3 = FindNode(1, temp_string2, "Fix") ' Load Fixture Data
            temp_pos = 1
            N = 0
Chaseloop5:
            Split = InStr(temp_pos, temp_string3, ":")
            If Split <> 0 Then
                Chase(Sub_Num).Fixture_Data(i, N) = val(Mid$(temp_string3, temp_pos, Split - temp_pos))
                temp_pos = Split + 1
                N = N + 1
                GoTo Chaseloop5
            Else
                Chase(Sub_Num).Fixture_Data(i, N) = val(Right$(temp_string3, Len(temp_string3) - temp_pos + 1))
            End If
        GoTo chaseloop2
        End If
    GoTo chaseloop
    End If
    
    '   ***************** Pages ********************

 position = 1

Page_Loop:
    temp_string = FindNode(position, stemp, "Page")
    If temp_string <> vbNullString Then
        temp_data1 = FindNode(1, temp_string, "Num")
        Page(temp_data1).Name = FindNode(1, temp_string, "Name")
        Page(temp_data1).Text = FindNode(1, temp_string, "Text")
        Page(temp_data1).Colour = FindNode(1, temp_string, "Colour")
        GoTo Page_Loop
    End If
    
 Hoofdblad.Status.Text = "Project Loaded "
 Playdesk.Status.Text = "Project Loaded"
 End Sub
    
Public Function Find_FileName(Description As String) As String

Load frmOpenDlg
If Current_Project <> "" Then
    frmOpenDlg.dlgOpenFile.FileName = Current_Project
Else
    frmOpenDlg.dlgOpenFile.FileName = "*.xml"
End If

frmOpenDlg.dlgOpenFile.Filter = "XML|*.xml"
frmOpenDlg.dlgOpenFile.DialogTitle = Description
frmOpenDlg.dlgOpenFile.ShowSave
If Err <> 0 Then
        ' No file selected from the Open File dialog box.
        Exit Function
End If
Find_FileName = frmOpenDlg.dlgOpenFile.FileName

End Function

Public Sub Save_As_Project()
Dim stemp As String

Current_Project = Find_FileName("Save DMX Project")
If Current_Project = "" Then Exit Sub
stemp = "<DMX_Desk_XML>" + vbCr + Project_data + Submix_data + Patch_Data
stemp = stemp + Fadernames_Data + Button_Data + Fader_Data + Chase_Save_Data
stemp = stemp + Screen_Data + Page_Data + "</DMX_Desk_XML>" + vbCr

 'MsgBox stemp
Filenum = FreeFile
    
 
 ' Open the file.
    Open Current_Project For Output As #Filenum
    
    Print #Filenum, stemp
    Close #Filenum

Hoofdblad.Status.Text = " Project Saved "
 Playdesk.Status.Text = " Project Saved"
End Sub

Public Sub Save_Project()
Dim stemp As String

If Current_Project = "" Then
    Current_Project = Find_FileName("Save DMX Project")
End If

If Current_Project = "" Then Exit Sub
stemp = "<DMX_Desk_XML>" + vbCr + Project_data + Submix_data + Patch_Data
stemp = stemp + Fadernames_Data + Button_Data + Fader_Data + Chase_Save_Data
stemp = stemp + Screen_Data + Page_Data + "</DMX_Desk_XML>" + vbCr

 'MsgBox stemp
Filenum = FreeFile
    
 
 ' Open the file.
    Open Current_Project For Output As #Filenum
    
    Print #Filenum, stemp
    Close #Filenum
    
Hoofdblad.Status.Text = " Project Saved "
Playdesk.Status.Text = " Project Saved"

End Sub
Public Sub Save_Submix()
Dim stemp As String

Current_Project = Find_FileName("Save DMX Submixes")
If Current_Project = "" Then Exit Sub
stemp = "<DMX_Desk_XML>" + vbCr + Submix_data + "</DMX_Desk_XML>" + vbCr

' MsgBox stemp
Filenum = FreeFile
    Open Current_Project For Output As #Filenum
    
    Print #Filenum, stemp
    Close #Filenum
    
Hoofdblad.Status.Text = " Submix Saved "
 Playdesk.Status.Text = " Submix Saved"
End Sub

Public Sub Save_Patch()
Dim stemp As String

Current_Project = Find_FileName("Save DMX Patches")
If Current_Project = "" Then Exit Sub
stemp = "<DMX_Desk_XML>" + vbCr + Patch_Data + "</DMX_Desk_XML>" + vbCr

 'MsgBox stemp
Filenum = FreeFile
    Open Current_Project For Output As #Filenum
    
    Print #Filenum, stemp
    Close #Filenum
    
Hoofdblad.Status.Text = " Patches Saved "
 Playdesk.Status.Text = " Patches Saved"
End Sub
Public Sub Save_Chase()
Dim stemp As String

Current_Project = Find_FileName("Save DMX Sequences")
If Current_Project = "" Then Exit Sub
stemp = "<DMX_Desk_XML>" + vbCr + Chase_Save_Data + "</DMX_Desk_XML>" + vbCr

' MsgBox stemp
Filenum = FreeFile
    Open Current_Project For Output As #Filenum
    
    Print #Filenum, stemp
    Close #Filenum
    
Hoofdblad.Status.Text = " Sequences Saved "
 Playdesk.Status.Text = " Sequences Saved"
End Sub
Public Function Project_data() As String
Dim String_A As String
Dim String_B As String
Dim i As Integer
String_A = vbNullString
String_B = vbNullString

       'Project Name
        If Desk_Project.Name <> vbNullString Then String_A = String_A & vbTab & vbTab & "<Name>" & Desk_Project.Name & "</Name>" & vbCr
       ' Date
        String_A = String_A & vbTab & vbTab & "<Date>" & Format(Date, "dd/mm/yyyy") & "</Date>" & vbCr
        ' Version
        Desk_Project.Version = Desk_Project.Version + 1
        String_A = String_A & vbTab & vbTab & "<Version>" & LTrim$(Str$(Desk_Project.Version)) & "</Version>" & vbCr
       ' Text
         If Desk_Project.Text <> vbNullString Then String_A = String_A & vbTab & vbTab & "<Text>" & Desk_Project.Text & "</Text>" & vbCr
      ' Adapter
        String_A = String_A & vbTab & vbTab & "<Adapter>" & LTrim$(Str$(DMX_Adapter)) & "</Adapter>" & vbCr
        ' Network
        For i = 0 To 8
            If Art_Data(i).Active = True Then
                  String_A = String_A & vbTab & vbTab & "<Network>" & vbCr
                  String_A = String_A & vbTab & vbTab & vbTab & "<Universe>" & LTrim$(Str$(Art_Data(i).Universe)) & "</Universe>" & vbCr & vbTab & vbTab & "</Network>" & vbCr
            End If
        Next i
        
       ' BCF
        String_A = String_A & vbTab & vbTab & "<BCF>" & LTrim$(Str$(BCF_Status)) + "</BCF>" + vbCr
      
        Project_data = vbTab & "<Project>" & vbCr & String_A & vbTab & "</Project>" & vbCr
End Function

Public Function Submix_data() As String
Dim String_A As String, i As Integer
Submix_data = vbNullString
                
    For i = 0 To Max_Submix
        String_A = vbNullString
        If Sub_Mix(i).Name <> "" Then String_A = String_A + vbTab + vbTab + "<Name>" + Sub_Mix(i).Name + "</Name>" + vbCr
        If Sub_Mix(i).Colour <> "" Then String_A = String_A + vbTab + vbTab + "<Colour>" + Sub_Mix(i).Colour + "</Colour>" + vbCr
        For j = 0 To 63
                If Sub_Mix(i).Level(j) > 0 Then String_A = String_A + vbTab + vbTab + "<Level>" + LTrim$(Str$(Sub_Mix(i).Channel(j))) + ":" + LTrim$(Str$(Sub_Mix(i).Level(j))) + "</Level>" + vbCr
        Next j
        
        If String_A <> "" Then
            Submix_data = Submix_data + vbTab + "<Submix>" + vbCr + vbTab + vbTab + "<Num>" + LTrim$(Str$(i)) + "</Num>" + vbCr + String_A + vbTab + "</Submix>" + vbCr
        End If
    Next i
End Function

Public Function Fadernames_Data() As String
Dim String_A As String, i As Integer, String_B As String
Fadernames_Data = vbNullString
                
    For i = 0 To Max_Channel
        String_A = vbNullString
        'String_B =str$(I + 1)
        If FaderNames(i).Name <> LTrim$(Str$(i + 1)) Then
        
            String_A = String_A + vbTab + vbTab + "<Desc>" + FaderNames(i).Name + "</Desc>" + vbCr
            String_A = String_A + vbTab + vbTab + "<Name>" + FaderNames(i).Short_Name + "</Name>" + vbCr
            String_A = String_A + vbTab + vbTab + "<Colour>" + FaderNames(i).Colour + "</Colour>" + vbCr
            If FaderNames(i).Main_Fade = True Then String_A = String_A + vbTab + vbTab + "<Main_F>1</Main_F>" + vbCr
            If FaderNames(i).Cross_Fade = True Then String_A = String_A + vbTab + vbTab + "<Cross_F>1</Cross_F>" + vbCr
        End If
        
        If String_A <> "" Then
            Fadernames_Data = Fadernames_Data + vbTab + "<FaderName>" + vbCr + vbTab + vbTab + "<Num>" + LTrim$(Str$(i)) + "</Num>" + vbCr + String_A + vbTab + "</FaderName>" + vbCr
        End If
    Next i
End Function

Public Function Patch_Data() As String
Dim String_A As String, i As Integer, String_B As String
Patch_Data = vbNullString
String_B = vbNullString
String_A = vbNullString
    For i = 0 To 512
        'String_A = vbnullstring
        If outpatch(i) <> 0 Then
            String_A = String_A + String_B + LTrim$(Str$(i)) + ":" + LTrim$(Str$(outpatch(i)))
            String_B = ","
        End If
    Next i
        
        
        If String_A <> "" Then
            Patch_Data = vbTab + "<Patch>" + String_A + "</Patch>" + vbCr
        End If
    'Next I
End Function

Public Function Button_Data() As String
Dim String_A As String, i As Integer, j As Integer
Button_Data = vbNullString
                
    For i = 0 To Max_Buttons * 16
        String_A = vbNullString
        
        If Button(i).Function < 4 Then
            If Button(i).Name <> "" Then String_A = String_A + vbTab + vbTab + "<Name>" + Button(i).Name + "</Name>" + vbCr
            If Button(i).Number > 0 Then String_A = String_A + vbTab + vbTab + "<Value>" + LTrim$(Str$(Button(i).Number)) + "</Value>" + vbCr
            If Button(i).Colour <> "" Then String_A = String_A + vbTab + vbTab + "<Colour>" + Button(i).Colour + "</Colour>" + vbCr
            If Button(i).Function > 0 Then String_A = String_A + vbTab + vbTab + "<Function>" + LTrim$(Str$(Button(i).Function)) + "</Function>" + vbCr
            If Button(i).Latch = True Then String_A = String_A + vbTab + vbTab + "<Latch>1</Latch>" + vbCr
            If Button(i).Channel1 > 0 Then String_A = String_A + vbTab + vbTab + "<Channel1>" + LTrim$(Str$(Button(i).Channel1)) + "</Channel1>" + vbCr
            If Button(i).Channel2 > 0 Then String_A = String_A + vbTab + vbTab + "<Channel2>" + LTrim$(Str$(Button(i).Channel2)) + "</Channel2>" + vbCr
            If Button(i).Channel3 > 0 Then String_A = String_A + vbTab + vbTab + "<Channel3>" + LTrim$(Str$(Button(i).Channel3)) + "</Channel3>" + vbCr
            If Button(i).Data1 > 0 Then String_A = String_A + vbTab + vbTab + "<Data1>" + LTrim$(Str$(Button(i).Data1)) + "</Data1>" + vbCr
            If Button(i).Data2 > 0 Then String_A = String_A + vbTab + vbTab + "<Data2>" + LTrim$(Str$(Button(i).Data2)) + "</Data2>" + vbCr
            If Button(i).Data3 > 0 Then String_A = String_A + vbTab + vbTab + "<Data3>" + LTrim$(Str$(Button(i).Data3)) + "</Data3>" + vbCr
            If Button(i).Level > 0 Then String_A = String_A + vbTab + vbTab + "<Level>" + LTrim$(Str$(Button(i).Level)) + "</Level>" + vbCr
            If Button(i).Preset = True Then String_A = String_A + vbTab + vbTab + "<Preset>1</Preset>" + vbCr
        
            If String_A <> vbNullString Then
                Button_Data = Button_Data + vbTab + "<Button>" + vbCr + vbTab + vbTab + "<Number>" + LTrim$(Str$(i)) + "</Number>" + vbCr + String_A + vbTab + "</Button>" + vbCr
            End If
        End If
           
    Next i
End Function

Public Function Fader_Data() As String
Dim String_A As String, i As Integer, j As Integer
Fader_Data = vbNullString
                
    For i = 0 To Max_Faders * 12
        String_A = vbNullString
        
        If Fader(i).Function < 4 Then
            If Fader(i).Name <> "" Then String_A = String_A + vbTab + vbTab + "<Name>" + Fader(i).Name + "</Name>" + vbCr
            If Fader(i).Number > 0 Then String_A = String_A + vbTab + vbTab + "<Value>" + LTrim$(Str$(Fader(i).Number)) + "</Value>" + vbCr
            If Fader(i).Colour <> "" Then String_A = String_A + vbTab + vbTab + "<Colour>" + Fader(i).Colour + "</Colour>" + vbCr
            If Fader(i).Function > 0 Then String_A = String_A + vbTab + vbTab + "<Function>" + LTrim$(Str$(Fader(i).Function)) + "</Function>" + vbCr
            If Fader(i).Channel1 > 0 Then String_A = String_A + vbTab + vbTab + "<Channel1>" + LTrim$(Str$(Fader(i).Channel1)) + "</Channel1>" + vbCr
            If Fader(i).Channel2 > 0 Then String_A = String_A + vbTab + vbTab + "<Channel2>" + LTrim$(Str$(Fader(i).Channel2)) + "</Channel2>" + vbCr
            If Fader(i).Channel3 > 0 Then String_A = String_A + vbTab + vbTab + "<Channel3>" + LTrim$(Str$(Fader(i).Channel3)) + "</Channel3>" + vbCr
            If Fader(i).Data1 > 0 Then String_A = String_A + vbTab + vbTab + "<Data1>" + LTrim$(Str$(Fader(i).Data1)) + "</Data1>" + vbCr
            If Fader(i).Data2 > 0 Then String_A = String_A + vbTab + vbTab + "<Data2>" + LTrim$(Str$(Fader(i).Data2)) + "</Data2>" + vbCr
            If Fader(i).Data3 > 0 Then String_A = String_A + vbTab + vbTab + "<Data3>" + LTrim$(Str$(Fader(i).Data3)) + "</Data3>" + vbCr
            If Fader(i).Level > 0 Then String_A = String_A + vbTab + vbTab + "<Level>" + LTrim$(Str$(Fader(i).Level)) + "</Level>" + vbCr
        
            If String_A <> vbNullString Then
                Fader_Data = Fader_Data + vbTab + "<Fader>" + vbCr + vbTab + vbTab + "<Number>" + LTrim$(Str$(i)) + "</Number>" + vbCr + String_A + vbTab + "</Fader>" + vbCr
            End If
        End If
    Next i
End Function

Public Function Screen_Data() As String
        
Dim String_A As String, i As Integer, j As Integer

Screen_Data = vbNullString
                
    For i = 0 To screen_end
        String_A = vbNullString
        If Screen(i).Name <> "" Then String_A = String_A + vbTab + vbTab + "<Name>" + Screen(i).Name + "</Name>" + vbCr
        String_A = String_A + vbTab + vbTab + "<Next>" + LTrim$(Str$(Screen(i).Next)) + "</Next>" + vbCr
        String_A = String_A + vbTab + vbTab + "<Colour>" + Screen(i).Colour + "</Colour>" + vbCr
        If Screen(i).Instant = False Then
            String_A = String_A + vbTab + vbTab + "<Instant>0</Instant>" + vbCr
        Else
            String_A = String_A + vbTab + vbTab + "<Instant>1</Instant>" + vbCr
        End If
        If Screen(i).Auto_next = False Then
            String_A = String_A + vbTab + vbTab + "<Auto>0</Auto>" + vbCr
        Else
            String_A = String_A + vbTab + vbTab + "<Auto>1</Auto>" + vbCr
        End If
        
        If Screen(i).Preset_Main > 0 Then String_A = String_A + vbTab + vbTab + "<Preset_l>" + LTrim$(Str$(Screen(i).Preset_Main)) + "</Preset_l>" + vbCr
        If Screen(i).Delay > 0 Then String_A = String_A + vbTab + vbTab + "<Delay>" + LTrim$(Str$(Screen(i).Delay)) + "</Delay>" + vbCr
        If Screen(i).Fade_Time > 0 Then String_A = String_A + vbTab + vbTab + "<Time>" + LTrim$(Str$(Screen(i).Fade_Time)) + "</Time>" + vbCr
         
        For j = 0 To 60
            If Screen(i).Fader_Sel(j) <> 0 Then
                String_A = String_A + vbTab + vbTab + "<Fad_Sel>" + LTrim$(Str$(j)) + ":" + LTrim$(Str$(Screen(i).Fader_Sel(j))) + "</Fad_Sel>" + vbCr
            End If
        Next j
        For j = 0 To 63
            If Screen(i).Presets(j) <> 0 Then
                String_A = String_A + vbTab + vbTab + "<Preset>" + LTrim$(Str$(j)) + ":" + LTrim$(Str$(Screen(i).Presets(j))) + "</Preset>" + vbCr
            End If
        Next j
        For j = 0 To 80
            If Screen(i).Button_Sel(j) = True Then
                String_A = String_A + vbTab + vbTab + "<But_Sel>" + LTrim$(Str$(j)) + "</But_Sel>" + vbCr
            End If
        Next j
        If String_A <> "" Then
            Screen_Data = Screen_Data + vbTab + "<Screen>" + vbCr + vbTab + vbTab + "<Num>" + LTrim$(Str$(i)) + "</Num>" + vbCr + String_A + vbTab + "</Screen>" + vbCr
        End If
    Next i
End Function

Public Function Chase_Save_Data() As String
Dim String_A As String, i As Integer, String_B As String, j As Integer

Chase_Save_Data = vbNullString
'String_B = vbnullstring
String_A = vbNullString
    For i = 0 To 31
        String_A = vbNullString
        If Chase(i).Steps > 1 Then
            String_A = String_A + vbTab + vbTab + "<Num>" + LTrim$(Str$(i)) + "</Num>" + vbCr ' Chase Number
            String_A = String_A + vbTab + vbTab + "<Name>" + Chase(i).Name + "</Name>" + vbCr  ' Chase Name
            String_A = String_A + vbTab + vbTab + "<Colour>" + Chase(i).Colour + "</Colour>" + vbCr  ' Chase Colour
            String_A = String_A + vbTab + vbTab + "<Steps>" + LTrim$(Str$(Chase(i).Steps)) + "</Steps>" + vbCr  ' Chase Steps
            String_A = String_A + vbTab + vbTab + "<Fixture>" + LTrim$(Str$(Chase(i).Fixture)) + "</Fixture>" + vbCr  ' Fixture
            String_A = String_A + vbTab + vbTab + "<Loop>" + LTrim$(Str$(Chase(i).Loop)) + "</Loop>" + vbCr ' Loops
                       
                String_A = String_A + vbTab + vbTab + "<Channels>"
                String_B = vbNullString
            For j = 0 To 23
                String_A = String_A + String_B + LTrim$(Str$(Chase(i).channels(j)))
                String_B = ":"
            Next j
            String_A = String_A + "</Channels>" + vbCr
            For j = 0 To Chase(i).Steps
                String_A = String_A + vbTab + vbTab + "<Step>" + vbCr
                String_A = String_A + vbTab + vbTab + vbTab + "<Num>" + LTrim$(Str$(j)) + "</Num>" + vbCr ' Step Number
                'String_A = String_A + vbTab + vbTab + vbTab + "<Speed>" + ltrim$(str$(Chase_speed(I, J))) + "</Speed>" + vbCr ' Chase Speed
                'String_A = String_A + vbTab + vbTab + vbTab + "<Time>" + ltrim$(str$(Chase_fade_time(I, J))) + "</Time>" + vbCr ' Chase Fade Times
                String_A = String_A + vbTab + vbTab + vbTab + "<Speed>0" + LTrim$(Str$(Chase(i).Speed(j))) + "</Speed>" + vbCr   ' Chase Speed
                String_A = String_A + vbTab + vbTab + vbTab + "<Time>0" + LTrim$(Str$(Chase(i).Fade_Time(j))) + "</Time>" + vbCr  ' Chase Fade Times
                                
                String_B = vbNullString
                String_A = String_A + vbTab + vbTab + vbTab + "<Data>"
                For k = 0 To 23
                    String_A = String_A + String_B + LTrim$(Str$(Chase(i).data(j, k)))
                    String_B = ":"
                Next k
                String_A = String_A + "</Data>" + vbCr + vbTab + vbTab + vbTab + "<Fade>"
                String_B = vbNullString
                For k = 0 To 23
                    String_A = String_A + String_B + LTrim$(Str$(Chase(i).Fade(j, k)))
                    String_B = ":"
                Next k
                String_A = String_A + "</Fade>" + vbCr + vbTab + vbTab + vbTab + "<Fix>"
                String_B = vbNullString
                For k = 0 To 5
                    String_A = String_A + String_B + LTrim$(Str$(Chase(i).Fixture_Data(j, k)))
                    String_B = ":"
                Next k
                String_A = String_A + "</Fix>" + vbCr + vbTab + vbTab + "</Step>" + vbCr
            Next j
        Chase_Save_Data = Chase_Save_Data + vbTab + "<Chase>" + vbCr + String_A + vbTab + "</Chase>" + vbCr
        'String_A = vbnullstring
        End If
    Next i
        
        
   'Chase_Save_Data = String_A

End Function

Public Function Page_Data() As String
Dim String_A As String, i As Integer, String_B As String
Page_Data = vbNullString
                
    For i = 0 To 4
        String_A = vbNullString
        
        If Page(i).Name <> vbNullString Then
            String_A = String_A + vbTab + vbTab + "<Name>" + Page(i).Name + "</Name>" + vbCr
        End If
        
        If Page(i).Text <> vbNullString Then
            String_A = String_A + vbTab + vbTab + "<Text>" + Page(i).Text + "</Text>" + vbCr
        End If
        
        If Page(i).Colour <> vbNullString Then
            String_A = String_A + vbTab + vbTab + "<Colour>" + Page(i).Name + "</Colour>" + vbCr
        End If
        
        If String_A <> vbNullString Then
            Page_Data = Page_Data + vbTab + "<Page>" + vbCr + vbTab + vbTab + "<Num>" + LTrim$(Str$(i)) + "</Num>" + vbCr + String_A + vbTab + "</Page>" + vbCr
        End If
    Next i
End Function

Private Sub Clear_Buttons()
Dim i As Integer

For i = 0 To Max_Buttons * 16
    Button(i).Function = 4  ' Off function
Next i

End Sub

Private Sub Clear_Faders()

Dim i As Integer
For i = 0 To Max_Faders * 12
    Fader(i).Function = 4 ' Off function
Next i
End Sub
