home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD8725882000.psc / modMain.bas < prev   
Encoding:
BASIC Source File  |  2000-08-04  |  7.9 KB  |  270 lines

  1. Attribute VB_Name = "modMain"
  2. Option Explicit
  3. Const CurrentModule As String = "modMain"
  4.  
  5. Private Const BIF_RETURNONLYFSDIRS = 1
  6. Private Const BIF_DONTGOBELOWDOMAIN = 2
  7. Private Const MAX_PATH = 260
  8. Public Const PROMPT_NONE As Long = 1
  9. Public Const MIME_TYPE As Long = 2
  10.  
  11. Public Settings As clsSettings
  12. Public CN As clsTCP
  13. Public DB As clsDatabase
  14. Public Const vbQuote = """"
  15. Public Receiving As Boolean
  16.  
  17. Public Type typeUser
  18.     ID As Long
  19.     Name As String
  20.     Email As String
  21.     Password As String
  22.     SMTP As String
  23.     POP3 As String
  24. End Type
  25.  
  26. Public Type typeMail
  27.     ID As Long
  28.     Folder As Long
  29.     From As String
  30.     To As String
  31.     Subject As String
  32.     Date As Date
  33.     Read As Boolean
  34.     Header As String
  35.     Body As String
  36.     Boundary As String
  37.     Attachments As Long
  38. End Type
  39.  
  40. Private Type BrowseInfo
  41.     hWndOwner As Long
  42.     pIDLRoot As Long
  43.     pszDisplayName As Long
  44.     lpszTitle As Long
  45.     ulFlags As Long
  46.     lpfnCallback As Long
  47.     lParam As Long
  48.     iImage As Long
  49. End Type
  50.  
  51. Public Type typeRule
  52.     PartID As Long
  53.     FindPhrase As String
  54.     FolderID As Long
  55. End Type
  56.  
  57. Public Rules() As typeRule
  58.  
  59. Public User As typeUser
  60.  
  61. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  62. Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
  63. Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
  64. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
  65. Public Declare Function GetNumFilesToDecode Lib "DECENC32.DLL" (ByVal strInFile As String) As Long
  66. Public Declare Function GetEncodedFile Lib "DECENC32.DLL" (ByVal strOutFile As String, ByVal nIndex As Long) As Long
  67. Public Declare Function DecodeFile Lib "DECENC32.DLL" (ByVal strInFile As String, ByVal strOutFile As String, ByVal nPrompts As Long) As Long
  68. Public Declare Sub SetEncodingApplication Lib "DECENC32.DLL" (ByVal strInFile As String)
  69. Public Declare Function EncodeFile Lib "DECENC32.DLL" (ByVal SourceFile As String, ByVal EncodedFile As String, ByVal strBoundary As String, ByVal CodeOption As Long, ByVal xAppend As Long) As Long
  70. Public Declare Sub FinishAttachments Lib "DECENC32.DLL" (ByVal strFileOut As String)
  71. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
  72. Public Declare Function timeGetTime Lib "winmm.dll" () As Long
  73.  
  74. Public Sub Main()
  75.     On Error GoTo Err_Init
  76.     Set Settings = New clsSettings
  77.     Set DB = New clsDatabase
  78.     Set CN = New clsTCP
  79.     frmLogon.Show vbModal
  80.     Exit Sub
  81.  
  82. Err_Init:
  83.     HandleError CurrentModule, "Main", Err.Number, Err.Description
  84. End Sub
  85.  
  86. Public Sub ShutDown()
  87.     On Error GoTo Err_Init
  88.     Set CN = Nothing
  89.     Set DB = Nothing
  90.     Set Settings = Nothing
  91.     Unload frmMain
  92.     End
  93.     Exit Sub
  94.  
  95. Err_Init:
  96.     HandleError CurrentModule, "ShutDown", Err.Number, Err.Description
  97. End Sub
  98.  
  99. Public Sub Status(ByVal i As Long, ByVal s As String)
  100.     On Error GoTo Err_Init
  101.     frmMain.StatusBar1.Panels(i).Text = s
  102.     Exit Sub
  103.  
  104. Err_Init:
  105.     HandleError CurrentModule, "Status", Err.Number, Err.Description
  106. End Sub
  107.  
  108. Public Sub HandleError(ByVal TheMod As String, ByVal TheSub As String, ByVal ErrNo As Long, ByVal ErrDescription As String)
  109.     MsgBox "Module:   " & TheMod & vbCrLf & _
  110.            "Function: " & TheSub & vbCrLf & _
  111.            "Error #:    " & ErrNo & vbCrLf & vbCrLf & _
  112.     ErrDescription, _
  113.     vbCritical, "Error"
  114. End Sub
  115.  
  116. Public Sub SaveFile(ByVal s As String, ByVal FileName As String)
  117.     On Error GoTo Err_Init
  118.     Dim FileNo As Integer
  119.     FileNo = FreeFile
  120.     Open FileName For Output As #FileNo
  121.     Print #FileNo, s
  122.     Close #FileNo
  123.     Exit Sub
  124.  
  125. Err_Init:
  126.     HandleError CurrentModule, "SaveFile", Err.Number, Err.Description
  127. End Sub
  128.  
  129. Public Sub OpenFile(ByVal FileName As String)
  130.     On Error GoTo Err_Init
  131.     Call ShellExecute(0&, vbNullString, FileName, vbNullString, vbNullString, vbNormalFocus)
  132.     Exit Sub
  133.  
  134. Err_Init:
  135.     HandleError CurrentModule, "OpenFile", Err.Number, Err.Description
  136. End Sub
  137.  
  138. Public Function GetFolderName() As String
  139.     On Error GoTo Err_Init
  140.     'Opens a Treeview control that displays
  141.     '     the directories in a computer
  142.     Dim lpIDList As Long
  143.     Dim sBuffer As String
  144.     Dim szTitle As String
  145.     Dim tBrowseInfo As BrowseInfo
  146.     szTitle = "This is the title"
  147.  
  148.  
  149.     With tBrowseInfo
  150.         .hWndOwner = 0 'Me.hwnd
  151.         .lpszTitle = lstrcat(szTitle, "")
  152.         .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
  153.     End With
  154.     lpIDList = SHBrowseForFolder(tBrowseInfo)
  155.  
  156.  
  157.     If (lpIDList) Then
  158.         sBuffer = Space(MAX_PATH)
  159.         SHGetPathFromIDList lpIDList, sBuffer
  160.         sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
  161.     End If
  162.     
  163.     GetFolderName = sBuffer
  164.     Exit Function
  165.  
  166. Err_Init:
  167.     HandleError CurrentModule, "GetFolderName", Err.Number, Err.Description
  168. End Function
  169.  
  170. Public Function GetFileName(ByVal Filter As String) As String
  171.     On Error GoTo Err_Init
  172.     With frmMail
  173.         .CommonDialog1.Filter = "AllFiles|*.*"
  174.         '.CommonDialog1.
  175.         .CommonDialog1.CancelError = True
  176.         .CommonDialog1.ShowOpen
  177.         GetFileName = .CommonDialog1.FileName
  178.     End With
  179.     Exit Function
  180.  
  181. Err_Init:
  182.     If Err.Number = 32755 Then
  183.         'user cancelled
  184.     Else
  185.         HandleError CurrentModule, "GetFileName", Err.Number, Err.Description
  186.     End If
  187. End Function
  188.  
  189. Public Function LeftPart(ByVal s As String) As String
  190.     On Error GoTo Err_Init
  191.     Dim c As Long
  192.     c = InStr(1, s, "@")
  193.     If c = 0 Then
  194.         LeftPart = s
  195.     Else
  196.         LeftPart = Left$(s, c - 1)
  197.     End If
  198.     Exit Function
  199.  
  200. Err_Init:
  201.     HandleError CurrentModule, "LeftPart", Err.Number, Err.Description
  202. End Function
  203.  
  204. Public Function RightPart(ByVal s As String) As String
  205.     On Error GoTo Err_Init
  206.     Dim c As Long
  207.     c = InStr(1, s, "@")
  208.     If c = 0 Then
  209.         RightPart = s
  210.     Else
  211.         RightPart = Right$(s, Len(s) - c)
  212.     End If
  213.     Exit Function
  214.  
  215. Err_Init:
  216.     HandleError CurrentModule, "RightPart", Err.Number, Err.Description
  217. End Function
  218.  
  219. Public Function LineBreak(ByVal s As String, ByVal LineLength As Long) As String
  220. 'This routine inserts line breaks at the desired column.
  221. 'Note that it will only break words up on spaces - if a line is too long
  222. 'AND has no spaces, it won't be broken.
  223.  
  224.     Dim c As Long, t As Long, LastLineBreak As Long, LastSpace As Long
  225.     
  226.     On Error GoTo Err_Init
  227.     
  228.     'Insert line breaks
  229.     Do
  230.         c = c + 1 'run of characters without spaces
  231.         t = t + 1 'all characters
  232.         If t > Len(s) Then
  233.             Exit Do
  234.         End If
  235.         'Grab the last line break and space characters.
  236.         If Mid$(s, t, 2) = vbCrLf Then
  237.             LastLineBreak = t
  238.             c = 0
  239.         ElseIf Mid$(s, t, 1) = " " Then
  240.             LastSpace = t
  241.         End If
  242.         'Is the line too long?
  243.         If c > LineLength Then
  244.             'the line's too long
  245.             If LastSpace > (t - LineLength) Then
  246.                 'break at the last space found on the prior line
  247.                 Mid(s, LastSpace, 1) = Chr$(1)
  248.             Else
  249.                 'don't break
  250.             End If
  251.             c = 0
  252.         End If
  253.     Loop
  254.     
  255.     'Replace all chr$(1)'s with vbcrlf's
  256.     Do While InStr(1, s, Chr$(1), vbTextCompare) > 0
  257.         s = Replace(s, Chr$(1), vbCrLf)
  258.     Loop
  259.     
  260.     'Assign to function and return.
  261.     LineBreak = s
  262.     Exit Function
  263.     
  264. Err_Init:
  265.     HandleError CurrentModule, "LineBreak", Err.Number, Err.Description
  266.     Resume Next
  267. End Function
  268.  
  269.  
  270.