Export Multiple Textboxes to CSV

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 6 years and 9 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Export Multiple Textboxes to CSV

Post by jvierra »

"foreach" does not output to the pipeline. "ForEach-Object" outputs to the pipeline.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Export Multiple Textboxes to CSV

Post by localpct »

It worked exactly as I wanted it to. I'll look into the differences this weekend.

Thanks

So how would you have worded my question so this doesn't happen again?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Export Multiple Textboxes to CSV

Post by jvierra »

I cannot help with the wording as it was mostly because you lacked the PS skills that would have helped you to describe the issue the first time. Note that all early examples you posted failed to isolate accurately what you were trying to do. You would be able to ask a better question if you leaned basic PowerShell beyond just typing commands.

While your loop will work it is still better and faster to use the pipeline.
  1. $assets |
  2.     ForEach-Object{
  3.         [PSCustomObject]@{
  4.             Date        = [datetime]::Now
  5.             Tech        = $textbox1.Text
  6.             BadgeNumber = $textbox2.Text
  7.             Asset       = $_
  8.             LastScan    = $textbox3.text
  9.            
  10.         }
  11.     }|
  12.     Export-Csv  $csvfile -NoTypeInformation -Append
You will find this use of the pipeline more efficient and much more useful in the future,
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Export Multiple Textboxes to CSV

Post by localpct »

I'll be quick and say that was a jerk comment. Instead of answering the question you chose to assume I don't know basic commands.

I explained it several different ways and provided two different examples yet I'm the one lacking skills. You need a long look in the mirror.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Export Multiple Textboxes to CSV

Post by jvierra »

I am not saying you didn't try however, your explanation always pointed at an ambiguity that I couldn't resolve. You didn't say you wanted to enumerate a set of textboxes and output each one to a line in a CSV. The words you used, in retrospect, meant that to you but not to me. After you posted the last example I started to understand what you were trying to ask but had to make two guesses to get what you wanted.

Remember. I do not have your system and I do not know what you are seeing as an end result. You have to make this clear. Your first examples only further confused the request which is why I posted that you cannot get items from the parent form. Once you added the correct items to the form the guess was closer but it took an example of how you wanted the records to look before I understood that you wanted to enumerate certain textboxes and generate one record for each.

If you were better skilled in coding and PowerShell you would have known this up front. Windows Forms skills would have told you that the parent forms controls are no available in a child form.

I am not criticizing you, I am suggesting that a more technical study of programming, PowerShell and forms would help you understand how to design and code better.

Well - you have the answer so I guess you are set for now. Good luck and have fun.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Export Multiple Textboxes to CSV

Post by localpct »

Remember earlier when I asked "how would you have worded the question?"?

You want to numerate a set of textboxes and output each one to a line in a CSV.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Export Multiple Textboxes to CSV

Post by jvierra »

localpct wrote:Remember earlier when I asked "how would you have worded the question?"?

You want to numerate a set of textboxes and output each one to a line in a CSV.

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

Re: Export Multiple Textboxes to CSV

Post by jvierra »

localpct wrote:Remember earlier when I asked "how would you have worded the question?"?

You want to numerate a set of textboxes and output each one to a line in a CSV.
Typo. Should be enumerate.
This topic is 6 years and 9 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