Multiple Checkbox use

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 3 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
mattys
Posts: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

Multiple Checkbox use

Post by mattys »

Im stumped. I have a form with multiple check boxes. These check boxes represent different file extensions.
Is my logic wrong? I can get to work in ISE, but not getting accurate results with Studio and check boxes.
  1.     #Get File Types from checkbox choices#
  2.     $filetypes = @()
  3.     if ($checkboxpdf.Checked)
  4.     { $filetypes += '*.pdf'}
  5.     elseif ($checkboxtxt.Checked)
  6.     { $filetypes += '*.txt'}
  7.     ELSE { $filetypes = '*.asdfasdfasdf'}
  8.    
  9.     Get-ChildItem $Path  -include $filetypes -Recurse -ErrorAction SilentlyContinue
I've tried holding back, but to a point where I have to ask for help.

Thanks in advance
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multiple Checkbox use

Post by jvierra »

What is you question? YOu have only stated that you have a form with checkboxes.
mattys
Posts: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

Re: Multiple Checkbox use

Post by mattys »

Good day Jvierra.

If both checkbox options are selected, I don't get all the results?. Is this If, elseif, else the correct method for adding to the array?
mattys
Posts: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

Re: Multiple Checkbox use

Post by mattys »

This is my pff if anybody has time to look at it. I get correct file count/size if one or none checkboxes are selected. But if both checkboxes are selected- I get incorrect results? Also when I added the checkboxs to this project my display of filepaths are no longer showing up in richtextbox?

This is my first project with using Jobs...

Thanks for your time.
Attachments
SCPurge_w_CheckBoxes.psf
(103.3 KiB) Downloaded 102 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multiple Checkbox use

Post by jvierra »

It would help if you actually explained what the purpose of all of this is.

If you can provide a clear description of what you are trying to accomplish and why you need to do this. I will look at the issue later if I have your description and if I can understand it.
mattys
Posts: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

Re: Multiple Checkbox use

Post by mattys »

The purpose is to Delete files. Using the Checkboxes, the user can specify which file types to be located, updated on screen(Richtextbox), and then prompted by a message box to confirm delete.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multiple Checkbox use

Post by jvierra »

How can checkboxes delete files?

Your description is far too vague to be useful. Are you say8ing that the user is typing files into a RichTextBox and that that some determines how the checkboxes work?
You have to think about what steps a user would take to delete files. A user would just select a file and delete. A checkbox knows nothing about files. How does a checkbox relate to a RichTextBox.

The best quick guess I can make is that the checkbox event deletes a file specified by something that is not clear. How does the checkbox event know which file to delete?
mattys
Posts: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

Re: Multiple Checkbox use

Post by mattys »

QwEL9FtSrV.gif
QwEL9FtSrV.gif (235.07 KiB) Viewed 7576 times
Here is a demo. I check the first box (.depth file types) then click auto detect. This starts a search on the computer to find file types with .depth extensions (which in this demo results to 30 files/7.03gb). The user also has a 2nd checkbox option to also search for .Scid file types (which in this demo resulted to 17 files/2.64gb).

My problem lies if the User checks both file types. Why in this demo it doesn't total 47 files/9.67gb). Which had me asking if my method to use the if,elseif,else method in the script is appropriate to use in this case.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multiple Checkbox use

Post by jvierra »

So you question is "how do I search for multiple file types?" Is this correct?
mattys
Posts: 62
Last visit: Wed Dec 27, 2023 8:28 am
Has voted: 3 times

Re: Multiple Checkbox use

Post by mattys »

Yes, Jvierra. Thank you
This topic is 3 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked