473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Enhancement to handle multiple files

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
8 1766
iburyak
1,017 Expert 512MB
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
Killer42
8,435 Expert 8TB
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
SAIRAAM
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
SAIRAAM
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
1,017 Expert 512MB
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
SAIRAAM
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
SAIRAAM
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
43
Yeh that is one thing i wanted to know as well
Apr 19 '07 #9

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

Similar topics

15
by: Riccardo Galli | last post by:
Hi, I noticed that when I use os.listdir I need to work with absolute paths 90% of times. While I can use a for cycle, I'd prefere to use a list comprehension, but it becomes too long. I...
4
by: Dalan | last post by:
I have been using a module for printing labels in Access 97, and although it works fine, I would like to add a small enhancement to it. The module allows for setting the number of labels to print...
19
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple...
104
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
5
by: Kieran Benton | last post by:
Hello, I'm currently in the tail end process of developing a high scalability server for my employer. Essentially it receives short socket based connections with an ASCII message, parses that...
6
by: skyy | last post by:
Hi.. i would like to know how to handle multiple upload files with the cgi module in perl script.. With single file, my $my_cgi new CGI; my $upload_filehandle = cgi ->upload('file1'); my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.