By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Enhancement to handle multiple files

P: 45
hi all

i am right now examing one of the project thats avaliable.in which they have taken single log file as input. the code for it is given below.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdInputBrowse_Click()
  2.    On Error GoTo ErrorLine
  3.    Dim fname As String
  4.    Dim fso As New FileSystemObject
  5.    Dim ext, newext As Variant
  6.    Dim stat, i As Integer
  7.    stat = 0
  8.  
  9.     If txtInputPath.Text <> "" Then
  10.         If fso.FileExists(txtInputPath.Text) Then
  11.             fname = Split(txtInputPath.Text, Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1))(0)
  12.         ElseIf fso.FolderExists(txtInputPath.Text) Then
  13.             fname = txtInputPath.Text
  14.         Else
  15.             fname = Split(txtInputPath.Text, Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1))(0)
  16.  
  17.             If InStr(1, txtInputPath.Text, ".") > 0 Then
  18.                 ext = "*." & Split(Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1), ".")(1)
  19.             Else
  20.                 ext = "*.csv"
  21.             End If
  22.             MsgBox ext
  23.             stat = 1
  24.         End If
  25.  
  26.         If Not fso.FolderExists(fname) Then
  27.             MsgBox "Folder specified does not exist", , "Input Log File"
  28.             txtInputPath.Text = ""
  29.             Exit Sub
  30.         End If
  31.  
  32.         CDBrowseFile.InitDir = fname
  33.     Else
  34.         CDBrowseFile.InitDir = App.Path
  35.     End If
  36.  
  37.     CDBrowseFile.Filter = "*.csv|*.csv;" & Chr(124) & "*.log|*.log;" & Chr(124) & "*.txt|*.txt" & Chr(124) & "*.*|*.*"
  38.  
  39.  
  40.  
  41.     CDBrowseFile.DialogTitle = "Select the Log File"
  42.  
  43.  
  44.     If stat = 0 Then
  45.         CDBrowseFile.FilterIndex = 1
  46.     Else
  47.         If ext = "*.csv" Then
  48.             CDBrowseFile.FilterIndex = 1
  49.         ElseIf ext = "*.log" Then
  50.             CDBrowseFile.FilterIndex = 2
  51.         ElseIf ext = "*.txt" Then
  52.             CDBrowseFile.FilterIndex = 3
  53.         Else
  54.             CDBrowseFile.FilterIndex = 4
  55.         End If
  56.     End If
  57.     CDBrowseFile.ShowOpen
  58.     If CDBrowseFile.FileName <> "" Then
  59.         If fso.FileExists(CDBrowseFile.FileName) = True Then
  60.             txtInputPath.Text = CDBrowseFile.FileName
  61.             gstrInputFile = Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1)
  62.             CmdCompute.Enabled = True
  63.             CDBrowseFile.FileName = ""
  64.         Else
  65.             MsgBox "File does not exist", vbCritical, "Input File"
  66.         End If
  67.     End If
  68.    If txtInputPath.Text <> "" Then
  69.     TxtOutputPath.Text = Mid(txtInputPath.Text, 1, InStrRev(txtInputPath.Text, "\") - 1)
  70.     End If
  71.  
  72.     If TxtInputTimerFile.Text = "" Then
  73.         TxtInputTimerFile.Text = Mid(txtInputPath.Text, 1, InStrRev(txtInputPath.Text, "\") - 1) & "\"
  74.     End If
  75.     Exit Sub
  76.  
  77. ErrorLine:
  78.     'MsgBox "Error-Number:" & Err.Number & vbCrLf & "Error Description:" & Err.DESCRIPTION & vbCrLf & "Error At: Selecting input file"
  79. End Sub
the extensions that are specified here are log files extensions.... can i enhance this code to take in multiple log files as input...if i can then where should i edit the existing code to take multiple files..

can anyone guide me in this

awating a reply

thanks in advance for whatever help i get

thanks
sairaam
Apr 16 '07 #1
Share this Question
Share on Google+
8 Replies


iburyak
Expert 100+
P: 1,017
Expand|Select|Wrap|Line Numbers
  1. 1. CDBrowseFile.Filter = "*.csv|*.csv;" & Chr(124) & "*.log|*.log;" & Chr(124) & "*.txt|*.txt" & Chr(124) & "*.*|*.*"
  2.  
  3.  
  4.  
  5. 2.    CDBrowseFile.DialogTitle = "Select the Log File"
  6.  
  7.  
  8. 3.    If stat = 0 Then
  9. 4.        CDBrowseFile.FilterIndex = 1
Line one in code above controls which file extensions to show.
You can change file index in line 4 to a different number like.

Expand|Select|Wrap|Line Numbers
  1. CDBrowseFile.FilterIndex = 3
Good Luck.
Apr 16 '07 #2

Expert 5K+
P: 8,434
One thing I would recommend is to move the browsing code into a separate Sub, rather than having it hanging off a button like this. Once you encapsulate it as a self-contained routine, it becomes much simpler to reuse it or change the way that you call it.
Apr 17 '07 #3

P: 45
Expand|Select|Wrap|Line Numbers
  1. 1. CDBrowseFile.Filter = "*.csv|*.csv;" & Chr(124) & "*.log|*.log;" & Chr(124) & "*.txt|*.txt" & Chr(124) & "*.*|*.*"
  2.  
  3.  
  4.  
  5. 2.    CDBrowseFile.DialogTitle = "Select the Log File"
  6.  
  7.  
  8. 3.    If stat = 0 Then
  9. 4.        CDBrowseFile.FilterIndex = 1
Line one in code above controls which file extensions to show.
You can change file index in line 4 to a different number like.

Expand|Select|Wrap|Line Numbers
  1. CDBrowseFile.FilterIndex = 3
Good Luck.
hi


i had changed the file index as you had specified.... but now also am not able to select multiple files... the selection here i mean selecting more than 1 file at a stroke....

can u help me

thanks
sairaam
Apr 17 '07 #4

P: 45
One thing I would recommend is to move the browsing code into a separate Sub, rather than having it hanging off a button like this. Once you encapsulate it as a self-contained routine, it becomes much simpler to reuse it or change the way that you call it.
sir am not allowed to change the existing code entirely... can just modify it so cant move into a sub since the existing buutton system should be present....can u suggest me some other idea

thanks for suggestion

thanks
sairaam
Apr 17 '07 #5

iburyak
Expert 100+
P: 1,017
Sorry, at first I didn't really understand your question correctly.

Make your textbox MultiLine = True

Use code below.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.  On Error GoTo ErrorLine
  3.    Dim fname As String
  4.    Dim fso As New FileSystemObject
  5.    Dim ext, newext As Variant
  6.    Dim stat, i As Integer
  7.    stat = 0
  8.  
  9.     If txtInputPath.Text <> "" Then
  10.         If fso.FileExists(txtInputPath.Text) Then
  11.             fname = Split(txtInputPath.Text, Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1))(0)
  12.         ElseIf fso.FolderExists(txtInputPath.Text) Then
  13.             fname = txtInputPath.Text
  14.         Else
  15.             fname = Split(txtInputPath.Text, Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1))(0)
  16.  
  17.             If InStr(1, txtInputPath.Text, ".") > 0 Then
  18.                 ext = "*." & Split(Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1), ".")(1)
  19.             Else
  20.                 ext = "*.csv"
  21.             End If
  22.             MsgBox ext
  23.             stat = 1
  24.         End If
  25.  
  26.         If Not fso.FolderExists(fname) Then
  27.             MsgBox "Folder specified does not exist", , "Input Log File"
  28.             txtInputPath.Text = ""
  29.             Exit Sub
  30.         End If
  31.  
  32.         CDBrowseFile.InitDir = fname
  33.     Else
  34.         CDBrowseFile.InitDir = App.Path
  35.     End If
  36.  
  37.     CDBrowseFile.Filter = "*.csv|*.csv;" & Chr(124) & "*.log|*.log;" & Chr(124) & "*.txt|*.txt" & Chr(124) & "*.*|*.*"
  38.     CDBrowseFile.Flags = cdlOFNAllowMultiselect
  39.  
  40.  
  41.     CDBrowseFile.DialogTitle = "Select the Log File"
  42.  
  43.  
  44.     If stat = 0 Then
  45.         CDBrowseFile.FilterIndex = 1
  46.     Else
  47.         If ext = "*.csv" Then
  48.             CDBrowseFile.FilterIndex = 1
  49.         ElseIf ext = "*.log" Then
  50.             CDBrowseFile.FilterIndex = 2
  51.         ElseIf ext = "*.txt" Then
  52.             CDBrowseFile.FilterIndex = 3
  53.         Else
  54.             CDBrowseFile.FilterIndex = 4
  55.         End If
  56.     End If
  57.  
  58.  
  59.     CDBrowseFile.ShowOpen
  60.     If CDBrowseFile.FileName <> "" Then
  61.         Dim retFiles, j As Integer
  62.         retFiles = Split(CDBrowseFile.FileName, " ")
  63.         If UBound(retFiles) = 0 Then
  64.             txtInputPath.Text = retFiles(0)
  65.         Else
  66.             For j = 1 To UBound(retFiles)
  67.                 txtInputPath.Text = txtInputPath.Text & vbCrLf & retFiles(0) & "\" & retFiles(j)
  68.             Next
  69.         End If
  70. '        If fso.FileExists(CDBrowseFile.FileName) = True Then
  71. '            txtInputPath.Text = CDBrowseFile.FileName
  72. '            gstrInputFile = Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1)
  73. '            CmdCompute.Enabled = True
  74. '            CDBrowseFile.FileName = ""
  75. '        Else
  76. '            MsgBox "File does not exist", vbCritical, "Input File"
  77. '        End If
  78.     End If
  79.  
  80.    If txtInputPath.Text <> "" Then
  81.     TxtOutputPath.Text = Mid(txtInputPath.Text, 1, InStrRev(txtInputPath.Text, "\") - 1)
  82.     End If
  83.  
  84.     If TxtInputTimerFile.Text = "" Then
  85.         TxtInputTimerFile.Text = Mid(txtInputPath.Text, 1, InStrRev(txtInputPath.Text, "\") - 1) & "\"
  86.     End If
  87.     Exit Sub
  88.  
  89. ErrorLine:
  90.     'MsgBox "Error-Number:" & Err.Number & vbCrLf & "Error Description:" & Err.DESCRIPTION & vbCrLf & "Error At: Selecting input file"
  91. End Sub
I commented out some of your code because wasn't sure how you want to change it with multiple files:

[PHP]
' If fso.FileExists(CDBrowseFile.FileName) = True Then
' txtInputPath.Text = CDBrowseFile.FileName
' gstrInputFile = Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1)
' CmdCompute.Enabled = True
' CDBrowseFile.FileName = ""
' Else
' MsgBox "File does not exist", vbCritical, "Input File"
' End If[/PHP]

Good Luck.
Apr 17 '07 #6

P: 45
Sorry, at first I didn't really understand your question correctly.

Make your textbox MultiLine = True

Use code below.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.  On Error GoTo ErrorLine
  3.    Dim fname As String
  4.    Dim fso As New FileSystemObject
  5.    Dim ext, newext As Variant
  6.    Dim stat, i As Integer
  7.    stat = 0
  8.  
  9.     If txtInputPath.Text <> "" Then
  10.         If fso.FileExists(txtInputPath.Text) Then
  11.             fname = Split(txtInputPath.Text, Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1))(0)
  12.         ElseIf fso.FolderExists(txtInputPath.Text) Then
  13.             fname = txtInputPath.Text
  14.         Else
  15.             fname = Split(txtInputPath.Text, Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1))(0)
  16.  
  17.             If InStr(1, txtInputPath.Text, ".") > 0 Then
  18.                 ext = "*." & Split(Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1), ".")(1)
  19.             Else
  20.                 ext = "*.csv"
  21.             End If
  22.             MsgBox ext
  23.             stat = 1
  24.         End If
  25.  
  26.         If Not fso.FolderExists(fname) Then
  27.             MsgBox "Folder specified does not exist", , "Input Log File"
  28.             txtInputPath.Text = ""
  29.             Exit Sub
  30.         End If
  31.  
  32.         CDBrowseFile.InitDir = fname
  33.     Else
  34.         CDBrowseFile.InitDir = App.Path
  35.     End If
  36.  
  37.     CDBrowseFile.Filter = "*.csv|*.csv;" & Chr(124) & "*.log|*.log;" & Chr(124) & "*.txt|*.txt" & Chr(124) & "*.*|*.*"
  38.     CDBrowseFile.Flags = cdlOFNAllowMultiselect
  39.  
  40.  
  41.     CDBrowseFile.DialogTitle = "Select the Log File"
  42.  
  43.  
  44.     If stat = 0 Then
  45.         CDBrowseFile.FilterIndex = 1
  46.     Else
  47.         If ext = "*.csv" Then
  48.             CDBrowseFile.FilterIndex = 1
  49.         ElseIf ext = "*.log" Then
  50.             CDBrowseFile.FilterIndex = 2
  51.         ElseIf ext = "*.txt" Then
  52.             CDBrowseFile.FilterIndex = 3
  53.         Else
  54.             CDBrowseFile.FilterIndex = 4
  55.         End If
  56.     End If
  57.  
  58.  
  59.     CDBrowseFile.ShowOpen
  60.     If CDBrowseFile.FileName <> "" Then
  61.         Dim retFiles, j As Integer
  62.         retFiles = Split(CDBrowseFile.FileName, " ")
  63.         If UBound(retFiles) = 0 Then
  64.             txtInputPath.Text = retFiles(0)
  65.         Else
  66.             For j = 1 To UBound(retFiles)
  67.                 txtInputPath.Text = txtInputPath.Text & vbCrLf & retFiles(0) & "\" & retFiles(j)
  68.             Next
  69.         End If
  70. '        If fso.FileExists(CDBrowseFile.FileName) = True Then
  71. '            txtInputPath.Text = CDBrowseFile.FileName
  72. '            gstrInputFile = Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1)
  73. '            CmdCompute.Enabled = True
  74. '            CDBrowseFile.FileName = ""
  75. '        Else
  76. '            MsgBox "File does not exist", vbCritical, "Input File"
  77. '        End If
  78.     End If
  79.  
  80.    If txtInputPath.Text <> "" Then
  81.     TxtOutputPath.Text = Mid(txtInputPath.Text, 1, InStrRev(txtInputPath.Text, "\") - 1)
  82.     End If
  83.  
  84.     If TxtInputTimerFile.Text = "" Then
  85.         TxtInputTimerFile.Text = Mid(txtInputPath.Text, 1, InStrRev(txtInputPath.Text, "\") - 1) & "\"
  86.     End If
  87.     Exit Sub
  88.  
  89. ErrorLine:
  90.     'MsgBox "Error-Number:" & Err.Number & vbCrLf & "Error Description:" & Err.DESCRIPTION & vbCrLf & "Error At: Selecting input file"
  91. End Sub
I commented out some of your code because wasn't sure how you want to change it with multiple files:

[PHP]
' If fso.FileExists(CDBrowseFile.FileName) = True Then
' txtInputPath.Text = CDBrowseFile.FileName
' gstrInputFile = Mid(txtInputPath.Text, InStrRev(txtInputPath.Text, "\") + 1)
' CmdCompute.Enabled = True
' CDBrowseFile.FileName = ""
' Else
' MsgBox "File does not exist", vbCritical, "Input File"
' End If[/PHP]

Good Luck.

am really thankful for the guidence that you are doing... here am able to select muliple files but am not able to display them on to the input path...i set that text box multiline property to true also....


can i have any suggessions for it..

thanks
sairaam
Apr 18 '07 #7

P: 45
am in urgent need please can some one help me out...to solve the problem which i have mentioned earlier...


thanks
sairaam
Apr 19 '07 #8

sumaiya
P: 43
Yeh that is one thing i wanted to know as well
Apr 19 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.