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.
Locked
mattys
Posts: 36
Joined: Mon Dec 30, 2019 10:58 am

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.  
  3.     $filetypes = @()
  4.  
  5.     if ($checkboxpdf.Checked)
  6.  
  7.     { $filetypes += '*.pdf'}
  8.  
  9.     elseif ($checkboxtxt.Checked)
  10.  
  11.     { $filetypes += '*.txt'}
  12.  
  13.     ELSE { $filetypes = '*.asdfasdfasdf'}
  14.  
  15.    
  16.  
  17.     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: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: Multiple Checkbox use

Post by jvierra »

What is you question? YOu have only stated that you have a form with checkboxes.

mattys
Posts: 36
Joined: Mon Dec 30, 2019 10:58 am

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: 36
Joined: Mon Dec 30, 2019 10:58 am

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 18 times

jvierra
Posts: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

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: 36
Joined: Mon Dec 30, 2019 10:58 am

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: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

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: 36
Joined: Mon Dec 30, 2019 10:58 am

Re: Multiple Checkbox use

Post by mattys »

QwEL9FtSrV.gif
QwEL9FtSrV.gif (235.07 KiB) Viewed 678 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: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: Multiple Checkbox use

Post by jvierra »

So you question is "how do I search for multiple file types?" Is this correct?

mattys
Posts: 36
Joined: Mon Dec 30, 2019 10:58 am

Re: Multiple Checkbox use

Post by mattys »

Yes, Jvierra. Thank you

Locked