home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / PGUIDE / SDI / SDINOTE.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-09-16  |  6.4 KB  |  193 lines

  1. Attribute VB_Name = "Module1"
  2. '*** Global module for MDI Notepad sample application.  ***
  3. '**********************************************************
  4. Option Explicit
  5.  
  6. ' User-defined type to store information about child forms
  7. Type FormState
  8.     Deleted As Integer
  9.     Dirty As Integer
  10.     Color As Long
  11. End Type
  12.  
  13. Public FState As FormState              ' Array of user-defined types
  14. Public gFindString As String            ' Holds the search text.
  15. Public gFindCase As Integer             ' Key for case sensitive search
  16. Public gFindDirection As Integer        ' Key for search direction.
  17. Public gCurPos As Integer               ' Holds the cursor location.
  18. Public gFirstTime As Integer            ' Key for start position.
  19. Public Const ThisApp = "MDINote"        ' Registry App constant.
  20. Public Const ThisKey = "Recent Files"   ' Registry Key constant.
  21.  
  22.  
  23.  
  24.  
  25.  
  26. Sub EditCopyProc()
  27.     ' Copy the selected text onto the Clipboard.
  28.     Clipboard.SetText frmSDI.txtNote.SelText
  29. End Sub
  30.  
  31. Sub EditCutProc()
  32.     ' Copy the selected text onto the Clipboard.
  33.     Clipboard.SetText frmSDI.txtNote.SelText
  34.     ' Delete the selected text.
  35.     frmSDI.txtNote.SelText = ""
  36. End Sub
  37.  
  38. Sub EditPasteProc()
  39.     ' Place the text from the Clipboard into the active control.
  40.     frmSDI.txtNote.SelText = Clipboard.GetText()
  41. End Sub
  42.  
  43. Sub FileNew()
  44.     Dim intResponse As Integer
  45.     
  46.     ' If the file has changed, save it
  47.     If FState.Dirty = True Then
  48.         intResponse = FileSave
  49.         If intResponse = False Then Exit Sub
  50.     End If
  51.     ' Clear the textbox and update the caption.
  52.     frmSDI.txtNote.Text = ""
  53.     frmSDI.Caption = "SDI NotePad - Untitled"
  54. End Sub
  55. Function FileSave() As Integer
  56.     Dim strFilename As String
  57.  
  58.     If frmSDI.Caption = "SDI NotePad - Untitled" Then
  59.         ' The file hasn't been saved yet.
  60.         ' Get the filename, and then call the save procedure, GetFileName.
  61.         strFilename = GetFileName(strFilename)
  62.     Else
  63.         ' The form's Caption contains the name of the open file.
  64.         strFilename = Right(frmSDI.Caption, Len(frmSDI.Caption) - 14)
  65.     End If
  66.     ' Call the save procedure. If Filename = Empty, then
  67.     ' the user chose Cancel in the Save As dialog box; otherwise,
  68.     ' save the file.
  69.     If strFilename <> "" Then
  70.         SaveFileAs strFilename
  71.         FileSave = True
  72.     Else
  73.         FileSave = False
  74.     End If
  75. End Function
  76.  
  77.  
  78. Sub FindIt()
  79.     Dim intStart As Integer
  80.     Dim intPos As Integer
  81.     Dim strFindString As String
  82.     Dim strSourceString As String
  83.     Dim strMsg As String
  84.     Dim intResponse As Integer
  85.     Dim intOffset As Integer
  86.     
  87.     ' Set offset variable based on cursor position.
  88.     If (gCurPos = frmSDI.txtNote.SelStart) Then
  89.         intOffset = 1
  90.     Else
  91.         intOffset = 0
  92.     End If
  93.  
  94.     ' Read the public variable for start position.
  95.     If gFirstTime Then intOffset = 0
  96.     ' Assign a value to the start value.
  97.     intStart = frmSDI.txtNote.SelStart + intOffset
  98.         
  99.     ' If not case sensitive, convert the string to upper case
  100.     If gFindCase Then
  101.         strFindString = gFindString
  102.         strSourceString = frmSDI.txtNote.Text
  103.     Else
  104.         strFindString = UCase(gFindString)
  105.         strSourceString = UCase(frmSDI.txtNote.Text)
  106.     End If
  107.             
  108.     ' Search for the string.
  109.     If gFindDirection = 1 Then
  110.         intPos = InStr(intStart + 1, strSourceString, strFindString)
  111.     Else
  112.         For intPos = intStart - 1 To 0 Step -1
  113.             If intPos = 0 Then Exit For
  114.             If Mid(strSourceString, intPos, Len(strFindString)) = strFindString Then Exit For
  115.         Next
  116.     End If
  117.  
  118.     ' If the string is found...
  119.     If intPos Then
  120.         frmSDI.txtNote.SelStart = intPos - 1
  121.         frmSDI.txtNote.SelLength = Len(strFindString)
  122.     Else
  123.         strMsg = "Cannot find " & Chr(34) & gFindString & Chr(34)
  124.         intResponse = MsgBox(strMsg, 0, App.Title)
  125.     End If
  126.     
  127.     ' Reset the public variables
  128.     gCurPos = frmSDI.txtNote.SelStart
  129.     gFirstTime = False
  130. End Sub
  131.  
  132. Sub GetRecentFiles()
  133.     ' This procedure demonstrates the use of the GetAllSettings function,
  134.     ' which returns an array of values from the Windows registry. In this
  135.     ' case, the registry contains the files most recently opened.  Use the
  136.     ' SaveSetting statement to write the names of the most recent files.
  137.     ' That statement is used in the WriteRecentFiles procedure.
  138.     Dim i As Integer
  139.     Dim varFiles As Variant ' Varible to store the returned array.
  140.     
  141.     ' Get recent files from the registry using the GetAllSettings statement.
  142.     ' ThisApp and ThisKey are constants defined in this module.
  143.     If GetSetting(ThisApp, ThisKey, "RecentFile1") = Empty Then Exit Sub
  144.     
  145.     varFiles = GetAllSettings(ThisApp, ThisKey)
  146.     
  147.     For i = 0 To UBound(varFiles, 1)
  148.         frmSDI.mnuRecentFile(0).Visible = True
  149.         frmSDI.mnuRecentFile(i + 1).Caption = varFiles(i, 1)
  150.         frmSDI.mnuRecentFile(i + 1).Visible = True
  151.     Next i
  152. End Sub
  153. Sub ResizeNote()
  154.     ' Expand text box to fill the form's internal area.
  155.     If frmSDI.picToolbar.Visible Then
  156.         frmSDI.txtNote.Height = frmSDI.ScaleHeight - frmSDI.picToolbar.Height
  157.         frmSDI.txtNote.Width = frmSDI.ScaleWidth
  158.         frmSDI.txtNote.Top = frmSDI.picToolbar.Height
  159.     Else
  160.         frmSDI.txtNote.Height = frmSDI.ScaleHeight
  161.         frmSDI.txtNote.Width = frmSDI.ScaleWidth
  162.         frmSDI.txtNote.Top = 0
  163.     End If
  164. End Sub
  165.  
  166.  
  167. Sub WriteRecentFiles(OpenFileName)
  168.     ' This procedure uses the SaveSettings statement to write the names of
  169.     ' recently opened files to the System registry. The SaveSetting
  170.     ' statement requires three parameters. Two of the parameters are
  171.     ' stored as constants and are defined in this module.  The GetAllSettings
  172.     ' function is used in the GetRecentFiles procedure to retrieve the
  173.     ' file names stored in this procedure.
  174.     
  175.     Dim i As Integer
  176.     Dim strFile As String
  177.     Dim strKey As String
  178.  
  179.     ' Copy RecentFile1 to RecentFile2, and so on.
  180.     For i = 3 To 1 Step -1
  181.         strKey = "RecentFile" & i
  182.         strFile = GetSetting(ThisApp, ThisKey, strKey)
  183.         If strFile <> "" Then
  184.             strKey = "RecentFile" & (i + 1)
  185.             SaveSetting ThisApp, ThisKey, strKey, strFile
  186.         End If
  187.     Next i
  188.   
  189.     ' Write the open file to first recent file.
  190.     SaveSetting ThisApp, ThisKey, "RecentFile1", OpenFileName
  191. End Sub
  192.  
  193.