Results 1 to 7 of 7

Thread: [RESOLVED] kill command browse

  1. #1

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Resolved [RESOLVED] kill command browse

    Hi again! is it possible to completly get rid of the cmdBrowse_Click function!
    i dont want to have to manually select the file each time! is it possible to just put the path of the file in the lblShortPath?




    VB Code:
    1. Option Explicit
    2. Dim FileToAttach As String
    3. Dim ActualNumberOfOccurrences As Integer
    4. Dim AnsParseStr As String
    5. Dim position As Integer
    6. Dim NumCharInString As Integer
    7. Dim checkit As Boolean
    8. Dim RetVal As Variant
    9.  
    10. Private Sub cmdBrowse_Click()
    11.  
    12. '***********************************************************************
    13. 'Give the file selection window a title.
    14.     cdlOpen.DialogTitle = "Pick A File To Attach To Outlook Express"
    15.     'The file selection window will start in the
    16.     'applications directory.
    17.     cdlOpen.InitDir = App.Path
    18.        
    19.     'Show all files
    20.     cdlOpen.Filter = "All Files (*.*)|*.*"
    21.                        
    22.     'Open the file selection window.
    23.     cdlOpen.ShowOpen
    24.    
    25.     FileToAttach = cdlOpen.FileName
    26. '***********************************************************************
    27. 'How many back slashes \ in our files path name
    28.     position = 1
    29.  
    30. Do Until position = 0
    31.  
    32.    position = InStr(position + 1, FileToAttach, "\")
    33.    ActualNumberOfOccurrences = ActualNumberOfOccurrences + 1
    34.  
    35. Loop
    36.  
    37. 'Parse the string to get the part after the last backslash \
    38.  AnsParseStr = ParseStr(FileToAttach, "\", ActualNumberOfOccurrences, ActualNumberOfOccurrences)
    39.  
    40.  
    41.  '****************************************************************
    42.     'Check to see if a file has been selected.
    43.     Select Case FileToAttach
    44.    
    45.        Case vbNullString
    46.             'Do not allow empty strings.
    47.             checkit = False
    48.             Exit Sub
    49.            
    50.         Case Else
    51.             checkit = True
    52.             lblShortPath.Visible = True
    53.             lblShortPath = AnsParseStr
    54.            
    55.     End Select
    56.  
    57. End Sub
    58.  
    59. Private Sub cmdEnd_Click()
    60.     Unload Me
    61. End Sub
    62.  
    63. Private Sub Form_Load()
    64.     'Center the Form on the Screen
    65.     Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
    66. End Sub
    67.  
    68. Private Sub lblShortPath_Click()
    69.  
    70. End Sub
    71.  
    72. Private Sub Option1_Click(Index As Integer)
    73.  
    74. If txtSendTo = "" Then
    75.     RetVal = MsgBox("Send To not filled in", 16, "Send An Attachment in Outlook Express")
    76.     Option1(0).Value = False
    77.     Option1(1).Value = False
    78.     txtSendTo.SetFocus
    79.     Exit Sub
    80. End If
    81.  
    82. If checkit = False Then
    83.     RetVal = MsgBox("No File Selected", 16, "Send An Attachment in Outlook Express")
    84.     Option1(0).Value = False
    85.     Option1(1).Value = False
    86.     cmdBrowse.SetFocus
    87.     Exit Sub
    88. End If
    89.  
    90. 'Add the MAPI components (MSMAPI32.OCX)
    91.  
    92. MAPISession1.SignOn
    93. MAPISession1.DownLoadMail = False
    94. DoEvents
    95.     MAPIMessage1.SessionID = MAPISession1.SessionID
    96.     MAPIMessage1.Compose
    97.    
    98.     MAPIMessage1.RecipAddress = txtSendTo
    99.     MAPIMessage1.ResolveName
    100.     MAPIMessage1.MsgSubject = AnsParseStr
    101.     MAPIMessage1.AttachmentPathName = FileToAttach
    102.     MAPIMessage1.AttachmentName = AnsParseStr
    103. '**********************************************************************
    104. '**********************************************************************
    105. 'Supply your own information here
    106.     MAPIMessage1.MsgNoteText = "Attached File:  - " & AnsParseStr _
    107.         & vbCrLf & vbCrLf & vbCrLf & "Regards," & vbCrLf & vbCrLf _
    108.         & "Your Name" & vbCrLf & vbCrLf & "YourEmail@someserver.com"
    109. '**********************************************************************
    110. '**********************************************************************
    111.     Select Case Index 'Do you want to open Outlook Express?
    112.    
    113.         Case 0
    114.             MAPIMessage1.Send True 'yes we want to see it
    115.            
    116.         Case Else
    117.             MAPIMessage1.Send False 'no we don't need to see it
    118.                           'just send it
    119.     End Select
    120. '**************************************************************************************
    121.  
    122. MAPISession1.SignOff
    123.  
    124. End Sub
    125.  
    126. Private Sub txtSendTo_GotFocus()
    127.     txtSendTo.SelStart = 0
    128.     txtSendTo.SelLength = Len(txtSendTo)
    129. End Sub
    130. Function ParseStr(ByVal Text, ByVal separator, ByVal start As Integer, _
    131. ByVal toEnd As Integer) As String
    132.    
    133.     Dim i As Integer, Temp As String, result As String
    134.     Dim ParseStrBegin As Integer, t As Integer, Count As Integer
    135.     Dim ParseStrEnd As Integer, Found As Integer
    136.    
    137.     ParseStr = ""
    138.     If Text = "" Then Exit Function
    139.     If separator = "" Then Exit Function
    140.     If Not (start > 0) Then start = 1
    141.     If toEnd < start Then toEnd = start
    142.     'Find first instance of the separator
    143.      t = InStr(1, Text, separator)
    144.    
    145.     'If no occurence return original string and exit
    146.     If t = 0 Then
    147.     ParseStr = Text
    148.     Exit Function
    149.     End If
    150.  
    151.  
    152.     'If first ParseStr, return left most data and exit
    153.  
    154.     If (start = 1) And (start = toEnd) Then
    155.     If t = 1 Then
    156.         ParseStr = ""
    157.         Exit Function
    158.     Else
    159.         ParseStr = Left(Text, t - 1)
    160.         Exit Function
    161.     End If
    162.     End If
    163.    
    164.     ParseStrBegin = 1
    165.     For i = 1 To start - 1
    166.        t = InStr(ParseStrBegin, Text, separator)
    167.        If t = 0 Then Exit For
    168.        ParseStrBegin = t + 1
    169.        Next i
    170.    
    171.     ' If there is no separator exit function with "" result
    172.     If t = 0 Then Exit Function
    173.    
    174.     'If only one ParseStr to return, find it and exit
    175.     If start = toEnd Then
    176.     t = InStr(ParseStrBegin, Text, separator)
    177.     If t = 0 Then t = Len(Text) + 1
    178.     result = Left(Text, t - 1)
    179.     ParseStr = Right(result, t - ParseStrBegin)
    180.     Exit Function
    181.     End If
    182.    
    183.     'Find last ParseStr then exit
    184.  
    185.     ParseStrEnd = t + 1
    186.     If start = 1 Then start = 2
    187.     For i = start To toEnd
    188.  
    189.     t = InStr(ParseStrEnd, Text, separator)
    190.     If t = 0 Then
    191.         t = Len(Text) + 1
    192.         Exit For
    193.     End If
    194.     ParseStrEnd = t + 1
    195.     Next i
    196.     If t = 0 Then t = Len(Text) + 1
    197.     result = Left(Text, t - 1)
    198.     ParseStr = Right(result, t - ParseStrBegin)
    199.  
    200. End Function

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: kill command browse

    Just check if variable has some value:
    VB Code:
    1. Private Sub cmdBrowse_Click()
    2.  
    3. '***********************************************************************
    4. 'check if FileToAttach holds some value
    5. [B]If Trim(FileToAttach) = "" Then[/B]
    6.     'Give the file selection window a title.
    7.     cdlOpen.DialogTitle = "Pick A File To Attach To Outlook Express"
    8.     'The file selection window will start in the
    9.     'applications directory.
    10.     cdlOpen.InitDir = App.Path
    11.        
    12.     'Show all files
    13.     cdlOpen.Filter = "All Files (*.*)|*.*"
    14.                        
    15.     'Open the file selection window.
    16.     cdlOpen.ShowOpen
    17.    
    18.     FileToAttach = cdlOpen.FileName
    19. [B]End If[/B]
    20. '***********************************************************************
    21.  
    22. '...
    23.  
    24. End Sub

  3. #3

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: kill command browse

    what you have above is all i need for that command?

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: kill command browse

    What command?
    You said you don't want "to have to manually select the file each time" so do it once and write selected file name to a variable (like you do: FileToAttach = cdlOpen.FileName) and keep that value for as long as you want to...

  5. #5

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: kill command browse

    So it should look like this then
    VB Code:
    1. Option Explicit
    2. Dim FileToAttach As String
    3. Dim ActualNumberOfOccurrences As Integer
    4. Dim AnsParseStr As String
    5. Dim position As Integer
    6. Dim NumCharInString As Integer
    7. Dim checkit As Boolean
    8. Dim RetVal As Variant
    9.  
    10. Private Sub cmdBrowse_Click()
    11. 'check if FileToAttach holds some value
    12. If Trim(FileToAttach) = "" Then
    13.     'Give the file selection window a title.
    14.     cdlOpen.DialogTitle = "C:\myfile.txt"
    15.     'The file selection window will start in the
    16.     'applications directory.
    17.     cdlOpen.InitDir = App.Path
    18.        
    19.     'Show all files
    20.     cdlOpen.Filter = "All Files (*.*)|*.*"
    21.                        
    22.     'Open the file selection window.
    23.     cdlOpen.ShowOpen
    24.    
    25.     FileToAttach = cdlOpen.FileName
    26. End If
    27.  
    28.  
    29. End Sub
    30.  
    31. Private Sub cmdEnd_Click()
    32.     Unload Me
    33. End Sub
    34.  
    35. Private Sub Form_Load()
    36.     'Center the Form on the Screen
    37.     Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
    38. End Sub
    39.  
    40. Private Sub Option1_Click(Index As Integer)
    41.  
    42. If txtSendTo = "" Then
    43.     RetVal = MsgBox("Send To not filled in", 16, "Send An Attachment in Outlook Express")
    44.     Option1(0).Value = False
    45.     Option1(1).Value = False
    46.     txtSendTo.SetFocus
    47.     Exit Sub
    48. End If
    49.  
    50. If checkit = False Then
    51.     RetVal = MsgBox("No File Selected", 16, "Send An Attachment in Outlook Express")
    52.     Option1(0).Value = False
    53.     Option1(1).Value = False
    54.     cmdBrowse.SetFocus
    55.     Exit Sub
    56. End If
    57.  
    58. 'Add the MAPI components (MSMAPI32.OCX)
    59.  
    60. MAPISession1.SignOn
    61. MAPISession1.DownLoadMail = False
    62. DoEvents
    63.     MAPIMessage1.SessionID = MAPISession1.SessionID
    64.     MAPIMessage1.Compose
    65.    
    66.     MAPIMessage1.RecipAddress = txtSendTo
    67.     MAPIMessage1.ResolveName
    68.     MAPIMessage1.MsgSubject = AnsParseStr
    69.     MAPIMessage1.AttachmentPathName = FileToAttach
    70.     MAPIMessage1.AttachmentName = AnsParseStr
    71. '**********************************************************************
    72. '**********************************************************************
    73. 'Supply your own information here
    74.     MAPIMessage1.MsgNoteText = "Attached File:  - " & AnsParseStr _
    75.         & vbCrLf & vbCrLf & vbCrLf & "Regards," & vbCrLf & vbCrLf _
    76.         & "Your Name" & vbCrLf & vbCrLf & "YourEmail@someserver.com"
    77. '**********************************************************************
    78. '**********************************************************************
    79.     Select Case Index 'Do you want to open Outlook Express?
    80.    
    81.         Case 0
    82.             MAPIMessage1.Send True 'yes we want to see it
    83.            
    84.         Case Else
    85.             MAPIMessage1.Send False 'no we don't need to see it
    86.                           'just send it
    87.     End Select
    88. '**************************************************************************************
    89.  
    90. MAPISession1.SignOff
    91.  
    92. End Sub
    93.  
    94. Private Sub txtSendTo_GotFocus()
    95.     txtSendTo.SelStart = 0
    96.     txtSendTo.SelLength = Len(txtSendTo)
    97. End Sub
    98. Function ParseStr(ByVal Text, ByVal separator, ByVal start As Integer, _
    99. ByVal toEnd As Integer) As String
    100.    
    101.     Dim i As Integer, Temp As String, result As String
    102.     Dim ParseStrBegin As Integer, t As Integer, Count As Integer
    103.     Dim ParseStrEnd As Integer, Found As Integer
    104.    
    105.     ParseStr = ""
    106.     If Text = "" Then Exit Function
    107.     If separator = "" Then Exit Function
    108.     If Not (start > 0) Then start = 1
    109.     If toEnd < start Then toEnd = start
    110.     'Find first instance of the separator
    111.      t = InStr(1, Text, separator)
    112.    
    113.     'If no occurence return original string and exit
    114.     If t = 0 Then
    115.     ParseStr = Text
    116.     Exit Function
    117.     End If
    118.  
    119.  
    120.     'If first ParseStr, return left most data and exit
    121.  
    122.     If (start = 1) And (start = toEnd) Then
    123.     If t = 1 Then
    124.         ParseStr = ""
    125.         Exit Function
    126.     Else
    127.         ParseStr = Left(Text, t - 1)
    128.         Exit Function
    129.     End If
    130.     End If
    131.    
    132.     ParseStrBegin = 1
    133.     For i = 1 To start - 1
    134.        t = InStr(ParseStrBegin, Text, separator)
    135.        If t = 0 Then Exit For
    136.        ParseStrBegin = t + 1
    137.        Next i
    138.    
    139.     ' If there is no separator exit function with "" result
    140.     If t = 0 Then Exit Function
    141.    
    142.     'If only one ParseStr to return, find it and exit
    143.     If start = toEnd Then
    144.     t = InStr(ParseStrBegin, Text, separator)
    145.     If t = 0 Then t = Len(Text) + 1
    146.     result = Left(Text, t - 1)
    147.     ParseStr = Right(result, t - ParseStrBegin)
    148.     Exit Function
    149.     End If
    150.    
    151.     'Find last ParseStr then exit
    152.  
    153.     ParseStrEnd = t + 1
    154.     If start = 1 Then start = 2
    155.     For i = start To toEnd
    156.  
    157.     t = InStr(ParseStrEnd, Text, separator)
    158.     If t = 0 Then
    159.         t = Len(Text) + 1
    160.         Exit For
    161.     End If
    162.     ParseStrEnd = t + 1
    163.     Next i
    164.     If t = 0 Then t = Len(Text) + 1
    165.     result = Left(Text, t - 1)
    166.     ParseStr = Right(result, t - ParseStrBegin)
    167.  
    168. End Function

  6. #6

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: kill command browse

    so if im reading this right i still have to "manually" select the file one time? And after that it will keep calling the file till the user closes the program?
    Thanks for the patience!

  7. #7

    Thread Starter
    Member bammoeller's Avatar
    Join Date
    Apr 2006
    Posts
    61

    Re: kill command browse

    i figurd it out
    MAPISession1.SignOn
    MAPISession1.DownLoadMail = False
    DoEvents
    MAPIMessage1.SessionID = MAPISession1.SessionID
    MAPIMessage1.Compose

    MAPIMessage1.RecipAddress = txtSendTo
    MAPIMessage1.ResolveName
    MAPIMessage1.AttachmentPathName = lblShortPath

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width