Attribute VB_Name = "modCmnDlg"
Option Explicit

Function ReadFile(strFilename As String, ceFile As FILECTLCtl.File) As String
  Dim strBuffer As String
  
  ceFile.Open strFilename, fsModeInput, fsAccessRead, fsLockRead
  If Not ceFile.EOF Then
    strBuffer = ceFile.Input(ceFile.LOF)
  End If
  ceFile.Close
  ReadFile = strBuffer
End Function

Sub WriteFile(strFilename As String, strData As String, ceFile As FILECTLCtl.File)
  ceFile.Open strFilename, fsModeOutput, fsAccessWrite, fsLockReadWrite
  ceFile.LinePrint strData
  ceFile.Close
End Sub

Function GetFileNameTXT(ComDlg As CEComDlgCtl.CommonDialog, bOpen As Boolean) As String
  ComDlg.DefaultExt = "txt"
  ComDlg.Filter = "Text (*.txt)|*.txt|All (*.*)|*.*"
  'If Not bOpen Then ComDlg.FileName = sCurrentFilename
  ComDlg.CancelError = True
  
  On Error Resume Next
  If bOpen Then
    ComDlg.ShowOpen
  Else
    ComDlg.ShowSave
  End If
  
  If Err = 0 Then 'picked a file name
    GetFileNameTXT = ComDlg.FileName
  End If
  
End Function

Function GetFileNameMCA(ComDlg As CEComDlgCtl.CommonDialog, bOpen As Boolean) As String
  ComDlg.DefaultExt = "mca"
  ComDlg.Filter = "Amptek Spectrum (*.mca)|*.mca|All (*.*)|*.*"
  'If Not bOpen Then ComDlg.FileName = sCurrentFilename
  ComDlg.CancelError = True
  
  On Error Resume Next
  If bOpen Then
    ComDlg.ShowOpen
  Else
    ComDlg.ShowSave
  End If
  
  If Err = 0 Then 'picked a file name
    GetFileNameMCA = ComDlg.FileName
  End If
  
End Function

Function GetFileNameCFG(ComDlg As CEComDlgCtl.CommonDialog, bOpen As Boolean) As String
  ComDlg.DefaultExt = "cfg"
  ComDlg.Filter = "Amptek Config (*.cfg)|*.cfg|All (*.*)|*.*"
  'If Not bOpen Then ComDlg.FileName = sCurrentFilename
  ComDlg.CancelError = True
  
  On Error Resume Next
  If bOpen Then
    ComDlg.ShowOpen
  Else
    ComDlg.ShowSave
  End If
  
  If Err = 0 Then 'picked a file name
    GetFileNameCFG = ComDlg.FileName
  End If
  
End Function

