473,407 Members | 2,315 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,407 software developers and data experts.

Evaluating result of a variable from multiple checkboxes

14
I have a routine that searches a directory structure for files. Right now the file pattern is simply *.* and when it is finished, I have a cleanup routine that strips out the file extensions that I don't want (*.m3u, and files which the routine will flag as 'unknown')

What I would like to do is to populate a variable with the acceptable file extensions based on the users choice.

For example, I setup four checkboxes, each a different type of file (i.e., audio, video, etc.)

Each type has a checkbox. How can I populate a variable (ScanExt) based on the slection of checkboxes. So if the user chose only audio, the variable might read *.mp3, *.wma, and if they chose audio and video (then it would read *.mp3, *.wma, *.wmv, *.avi.

Does anyone have any suggestions on how I might acheive this?

Thanks,
CJ
Dec 31 '08 #1
12 1669
DonRayner
489 Expert 256MB
Put this at the top of your forms module

Expand|Select|Wrap|Line Numbers
  1. public myvar as string
  2.  
put this in the on change event for each checkbox

Expand|Select|Wrap|Line Numbers
  1. Call VarString
  2.  
Add this to the bottom of the forms module

Expand|Select|Wrap|Line Numbers
  1. Public Sub VarString ()
  2. If cb1 then
  3.     myvar = "*.mp3"
  4. Else
  5.     myvar = ""
  6. End if
  7.  
  8. if cb2 then
  9.     if myvar <> "" then
  10.         myvar = myvar & ", *.wma"
  11.     else
  12.         myvar = "*.wma"
  13.     end if
  14.  
  15. if cb3 then
  16.     if myvar <> "" then
  17.         myvar = myvar & ", *.wmv"
  18.     else
  19.         myvar = "*.wmv"
  20.     end if
  21.  
  22. if cb4 then
  23.     if myvar <> "" then
  24.         myvar = myvar & ", *.avi"
  25.     else
  26.         myvar = "*.avi"
  27.     end if
  28. End If
  29. End Sub
  30.  
Replace the cb1, cb2, cb3, cb4 with the actual names of your checkboxes.
Dec 31 '08 #2
Airtech
14
I see what this is trying to achieve and it is working but only partially.
I get lots of errors on the fourth check box about being null, and it doesn't quite work if the audio option gets turned off.

I have the code below:
Expand|Select|Wrap|Line Numbers
  1. Public Sub MediaString()
  2.  
  3. If chkAudio Then
  4.     If ScanExt <> "" Then
  5.         ScanExt = ScanExt & "*.mp3, *.wma"
  6.     Else
  7.         ScanExt = ""
  8.     End If
  9. End If
  10.  
  11. If chkVideo Then
  12.     If ScanExt <> "" Then
  13.         ScanExt = ScanExt & ", *.avi"
  14.     Else
  15.         ScanExt = "*.mp3,*.wma"
  16.     End If
  17. End If
  18.  
  19. If chkImages Then
  20.     If ScanExt <> "" Then
  21.         ScanExt = ScanExt & ", *.jpg, *.gif"
  22.     Else
  23.         ScanExt = "*.avi"
  24.     End If
  25. End If
  26.  
  27. If chkKaraoke Then
  28.     If ScanExt <> "" Then
  29.         ScanExt = ScanExt & ", *.CDG, *.KAR"
  30.     Else
  31.         ScanExt = ", *.jpg, *.gif"
  32.     End If
  33. End If
  34.  
  35. If chkAudio And chkVideo And chkImages And chkKaraoke Then
  36.     ScanExt = "*.*"
  37. End If
  38.  
  39. End Sub
I included the last piece so that if they are all left on at the default, then it would simply include all files.
I am still struggling with this and trying to polish it.

Any combo of the four checkboxes could be on or off, and being a file filter the format is as your code suggests, *.mp3, *.wav, *.avi, etc.

The only thing I have not tried, and perhaps I missed this in your code, was having a seperate checkbox for each extension, but that would many more checkboxes than I have now, about 9 off them if I split this out into a seperate checkbox for each extension possible. Then adding extensions would require additional checkboxes.

What do you think?
Dec 31 '08 #3
Airtech
14
I had to tweak the first one, to try and get the formatting right, but that doesn't seem to to the trick either.
Dec 31 '08 #4
DonRayner
489 Expert 256MB
Try it like this

Expand|Select|Wrap|Line Numbers
  1. Public Sub MediaString()
  2. If chkAudio Then
  3.  ScanExt = "*.mp3, *.wma"
  4. Else
  5.  ScanExt = ""
  6. End If
  7.  
  8. If chkVideo Then
  9.  If ScanExt <> "" Then
  10.   ScanExt = ScanExt & ", *.avi"
  11.  Else
  12.   ScanExt = "*.avi"
  13.  End If
  14. End If
  15. If chkImages Then
  16.  If ScanExt <> "" Then
  17.   ScanExt = ScanExt & ", *.jpg, *.gif"
  18.  Else
  19.   ScanExt = "*.jpg, *.gif"
  20.  End If
  21. End If
  22. If chkKaraoke Then
  23.  If ScanExt <> "" Then
  24.   ScanExt = ScanExt & ", *.CDG, *.KAR"
  25.  Else
  26.   ScanExt = "*.CDG, *.KAR"
  27.  End If
  28. End If
  29. If chkAudio And chkVideo And chkImages And chkKaraoke Then
  30. ScanExt = "*.*"
  31. End If
  32. End Sub
  33.  
Jan 1 '09 #5
DonRayner
489 Expert 256MB
oops, add the following between lines one and two of my previous post.

Expand|Select|Wrap|Line Numbers
  1. scanext = ""
  2.  
you can then delete lines 4,5 or leave as is.
Jan 1 '09 #6
Airtech
14
Thank you for sending this, I see where I got the intention of your original suggestion built with a couple mistakes. I still get the error on chkKaraoke, but I think I can put in some handling.

This looks like it will work great.

THANKS.!!!!! I appreciate your help.

CJ
Jan 1 '09 #7
Airtech
14
I seem to have found a pretty effective workaround. What seems to be happening is that the check on chkKaraoke isn't taking, and the logic was having trouble with the fact that it was Null, so I added the following code for this and seem to have a workaround, that stops generating errors, you just don't get the check mark,.

If IsNull(chkKaraoke) Then
GoTo MediaString_Exit
End If

While not ideal, if this is the worst thing that my code has to deal with for this function, then it works for me.

Thanks again for your help. Basic, to the point, and it gets the job done.
Now I will take that variable and can use it in the file scan module for the project.

PROGRESS!!!!!! I Love it!
Jan 1 '09 #8
DonRayner
489 Expert 256MB
That's great, good luck on the rest of your project. You can fix the error you're getting by setting the default value of your fields to false.
Jan 1 '09 #9
Airtech
14
I will actually have to use the other one, because the default is to scan all files.
But you are right, and either way should be perfectly functional.
Jan 1 '09 #10
Airtech
14
Don,

OK, I am adding to this one, because what this solution resolved, lead to another issue. I suspect you will probably have a fast answer.
I am using the AllenBrowne code of "filldirlisttotable"

The code works great. Only one issue, I cannot find anywhere on the net any notes about using the filespec option.
By default it uses *.*, and I can make it work by specifying only one extension, such as *.jpg, but it becomes useless when I specify multiple extensions such as *.jpg, *.gif, *.png.

Obviously that must be the wrong way to provide the filespec.
Have you used this function? I am providing part of it below.
There may even be a better way of doing this, but I have written substantial code around this.

I am kind of thinking that unless this code simply canot handle the multiple extensions regardless of how they are provided, then I may have to re-write this section of code. This is what the previous issue is feeding into to allow the user to search only certain types of files.
Expand|Select|Wrap|Line Numbers
  1. Call FillDirToTable(colDirList, strpath, strFileSpec, bIncludeSubfolders)
This goes to:
Expand|Select|Wrap|Line Numbers
  1. Private Function FillDirToTable(colDirList As Collection _
  2.     , ByVal strFolder As String _
  3.     , strFileSpec As String _
  4.     , bIncludeSubfolders As Boolean)
  5.  
  6.     'Build up a list of files, and then add add to this list, any additional folders
  7.     On Error GoTo Err_Handler
  8.  
  9.     Dim strTemp As String
  10.     Dim colFolders As New Collection
  11.     Dim vFolderName As Variant
  12.     Dim strSQL As String
  13.  
  14.     'Add the files to the folder.
  15.     strFolder = TrailingSlash(strFolder)
  16.     strTemp = Dir(strFolder & strFileSpec)
  17.     Do While strTemp <> vbNullString
  18.          gCount = gCount + 1
  19.          SysCmd acSysCmdSetStatus, gCount
  20.          strSQL = "INSERT INTO zzLibScan " _
  21.           & " (MediaFileName, MediaPath) " _
  22.           & " SELECT """ & strTemp & """" _
  23.           & ", """ & strFolder & """;"
  24.          CurrentDb.Execute strSQL
  25.         colDirList.Add strFolder & strTemp
  26.         strTemp = Dir
  27.     Loop
  28.  
  29.     If bIncludeSubfolders Then
  30.         'Build collection of additional subfolders.
  31.         strTemp = Dir(strFolder, vbDirectory)
  32.         Do While strTemp <> vbNullString
  33.             If (strTemp <> ".") And (strTemp <> "..") Then
  34.                 If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0& Then
  35.                     colFolders.Add strTemp
  36.                 End If
  37.             End If
  38.             strTemp = Dir
  39.         Loop
  40.         'Call function recursively for each subfolder.
  41.         For Each vFolderName In colFolders
  42.             Call FillDirToTable(colDirList, strFolder & TrailingSlash(vFolderName), strFileSpec, True)
  43.         Next vFolderName
  44.     End If
  45.  
  46. Exit_Handler:
  47.  
  48.     Exit Function
  49.  
  50. Err_Handler:
  51.     strSQL = "INSERT INTO zzLibScan " _
  52.     & " (MediaFileName, MediaPath) " _
  53.     & " SELECT ""  ~~~ ERROR ~~~""" _
  54.     & ", """ & strFolder & """;"
  55.     CurrentDb.Execute strSQL
  56.  
  57.     Resume Exit_Handler
  58. End Function
  59.  
  60. Public Function TrailingSlash(varIn As Variant) As String
  61.     If Len(varIn) > 0& Then
  62.         If Right(varIn, 1&) = "\" Then
  63.             TrailingSlash = varIn
  64.         Else
  65.             TrailingSlash = varIn & "\"
  66.         End If
  67.     End If
  68. End Function
What do you think?
Jan 2 '09 #11
DonRayner
489 Expert 256MB
Airtech, sorry I'm so slow getting back to you, I was away over the weekend. I'll take a look at this later today and see what's up with.
Jan 5 '09 #12
DonRayner
489 Expert 256MB
Airtech, can you post the actual line of code that you are using to call this function.
Jan 6 '09 #13

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

Similar topics

3
by: Daniel Ehrenberg | last post by:
One of the most common bugs that people have on the Python Tutor list are caused by the fact the default arguments for functions are evaluated only once, not when the function is called. The...
3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
5
by: @(none) | last post by:
I have a page which is a set of CheckBoxes generated daily and thus the number of Checkboxes changes each day. What I want to do is allow the user to select one or more checkboxes and the push a...
6
by: jeffsnox | last post by:
Hi, I have multiple checkboxes on the same form as follows: <input type='checkbox' name='cbtype' value='1'> <input type='checkbox' name='cbtype' value='2'> <input type='checkbox'...
1
by: projectjakecs | last post by:
Hi, I am working on a ms access database and I am having trouble using a form to create new records in an associative table. Here is the breakdown of my database: Main Table - Computer...
4
by: ramapv | last post by:
can i highlight a checkbox from a group of checkbox with particular name which is given as a search key. I am having a list of checkboxes and i have to select some of them and form a group.but i'm...
5
by: jhurrell | last post by:
I have been having some trouble getting my XSL style sheet to parse correctly. I have some XML outputted from an SQL-Server, that I then need to turn into multiple HTML files. This I have done...
5
by: TechnoAtif | last post by:
Hi All..'mAtif..i've got stuck within checkboxes these days..i've got many input items like checkboxes,textarea and along with them there are many checkboxes...all the data except the checkbox's is...
0
by: Ned Balzer | last post by:
Hi, Can anyone point me in the direction of a solution for validating multiple checkboxes in an asp.net 2.0 page? 1) This is not a checkboxlist, it is a number of separate checkboxes 2) I do...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.