home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD112141122000.psc / IniViewer / Modules / modCommonDialog.bas
Encoding:
BASIC Source File  |  2000-11-02  |  2.9 KB  |  82 lines

  1. Attribute VB_Name = "modCommonDialog"
  2. ' ***********************************************
  3. ' * Common Dialog Code                          *
  4. ' * Code by: Michael Heath                      *
  5. ' * Code Date: Sometime in '99                  *
  6. ' * Email:  mheath@indy.net                     *
  7. ' * -----------------------                     *
  8. ' * Simple CommonDialog Routines for Open/Save  *
  9. ' * File operations.                            *
  10. ' * Being revised from time to time.            *
  11. ' ***********************************************
  12.  
  13. Public CurrentFileName As String     ' Holds filename
  14. Public NoOpen As Boolean             ' Flag for file operation
  15. Public vFileName As String           ' Name of File without the path
  16. Public strAppName As String          ' Name of this App
  17. Public Sub OpenFile(vForm As Form, vFilter As String)
  18. ' Reset the NoOpen flag
  19. NoOpen = False
  20. CurrentFileName = ""
  21. ' Handle errors
  22.     On Error GoTo OpenProblem
  23.     vForm.CommonDialog1.InitDir = "c:\windows"
  24.     vForm.CommonDialog1.Filter = vFilter
  25.     vForm.CommonDialog1.FilterIndex = 1
  26.     ' Display an Open dialog box.
  27.     vForm.CommonDialog1.Action = 1
  28.     vForm.Caption = strAppName & " - " & vForm.CommonDialog1.FileName
  29.     vForm.Caption = strAppName & " - " & vForm.CommonDialog1.FileName
  30.     CurrentFileName = vForm.CommonDialog1.FileName
  31.     vFileName = vForm.CommonDialog1.FileTitle
  32.     If CurrentFileName = "" Then NoOpen = True
  33.     Exit Sub
  34. OpenProblem:
  35.     ' There was a problem so let's flag NoOpen as true
  36.     NoOpen = True
  37.     Exit Sub
  38.  
  39. End Sub
  40.  
  41. Public Sub SaveFile(vForm As Form, vFilter As String)
  42. On Error GoTo SaveERR
  43.     Dim FileNum As Integer
  44.     ' Set Initial Directory to open and FileTypes
  45.         vForm.CommonDialog1.InitDir = App.Path & "\Save"
  46.         ' vForm.CommonDialog1.Filter = "ALL Files | *.*"
  47.         
  48.         vForm.CommonDialog1.Filter = vFilter
  49.         If CurrentFileName = "" Then
  50.             ' Code revised - Do nothing
  51.             CurrentFileName = "NewFile"
  52.         Else
  53.             vForm.CommonDialog1.FileName = CurrentFileName
  54.         End If
  55.             vForm.CommonDialog1.ShowSave
  56.             CurrentFileName = vForm.CommonDialog1.FileName
  57. Exit Sub
  58. SaveERR:
  59.     ' No real error trap, just exit the sub and give a description of the error
  60.     MsgBox "An error occured. " & Err.Description, vbOKOnly + vbInformation, "Save Error"
  61. End Sub
  62.  
  63. Public Function PutFileInString(sFileName As String) As String
  64.     'sFileName must include Path and file na
  65.     '     me
  66.     'eg "c:\Windows\notepad.exe"
  67.     Dim iFree As Integer, sizeOfFile As Long
  68.     Dim sFileString As String, sTemp As String
  69.     iFree = FreeFile
  70.     Open sFileName For Binary Access Read As iFree
  71.     sizeOfFile = LOF(iFree)
  72.     sFileString = Space$(sizeOfFile)
  73.     Get iFree, , sFileString
  74.     Close #iFree
  75.     PutFileInString = sFileString
  76.     
  77.     ' Thanks to Robert Carter for this function
  78. End Function
  79.  
  80.  
  81.  
  82.