Working with calendar in PowerShellStudio

Ask your PowerShell-related questions, including questions on cmdlet development!
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 7 years and 10 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
User avatar
nikolay
Posts: 9
Last visit: Sun Nov 17, 2019 10:50 pm

Re: Working with calendar in PowerShellStudio

Post by nikolay »

OOOO!!! It work! THANK YOU!!!!You help me!!!
User avatar
nikolay
Posts: 9
Last visit: Sun Nov 17, 2019 10:50 pm

Re: Working with calendar in PowerShellStudio

Post by nikolay »

Can I ask another question? I also need this date to do a search in the databases.I can use the variable $this SQL query? Or maybe assign it a different type?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Working with calendar in PowerShellStudio

Post by jvierra »

nikolay wrote:Thank you for your help!!! But it difficult for me.And it is not work.
What is this variable $this?
This variable needs to be stored a date which choosed on calendar?
Windows is based on an event driven model or what we can call a state machine.. Windows always send at least one object with an event. That object is internally assigned t the $this variable and is formally known as the "sender". The variable life expectancy is the lifetime of the event. There is an optional second parameter which is known as the event parameter and it is assigned to the $_ internal variable when needed. PowerShell Studio always (I think) posts the class of the event object so we know what it can do. Here is an example:
  1. #Event Argument: $_ = [System.ComponentModel.CancelEventArgs]
The value changed event for most controls does not use an optional event argument but the $this (sender) is available.
Here is what it looks like from the SDK point of reference.

Here is a control click event:
private void button1_Click(object sender, System.EventArgs e)

Here is the value changed event handler:
private void DateTimePicker1_ValueChanged(Object sender, EventArgs e)

Notice that they are generically the same. The e in the DTP event is just not very useful so we ususally ignore it.

Most controls have a "Spotlight article" available via a right click on the control in the toolbox. Unfortunately no one has written an article for the DTP so we cannot review it. We can look it up in the SDK at Microsoft.

For any control use this template: https://msdn.microsoft.com/en-us/librar ... dows.forms

We then add the control class name and we can find the documentation:

https://msdn.microsoft.com/en-us/librar ... timepicker

It is critical that you learn to use the documentation when learning PowerShell and Forms. It will help you to ask better questions when posting for help.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Working with calendar in PowerShellStudio

Post by jvierra »

nikolay wrote:Can I ask another question? I also need this date to do a search in the databases.I can use the variable $this SQL query? Or maybe assign it a different type?
Before going any further you need to learn PowerShell. Until then you will be totally lost and we cannot incrementally teach you how to use PowerShell.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Working with calendar in PowerShellStudio

Post by jvierra »

Here is a research starter for how to use SQL with PowerShell:
https://www.google.com/?gws_rd=ssl#neww ... ql+example
User avatar
nikolay
Posts: 9
Last visit: Sun Nov 17, 2019 10:50 pm

Re: Working with calendar in PowerShellStudio

Post by nikolay »

OK! THANKS!
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Working with calendar in PowerShellStudio

Post by dan.potter »

nikolay wrote:Can I ask another question? I also need this date to do a search in the databases.I can use the variable $this SQL query? Or maybe assign it a different type?
As long as the sql query is within the event block. Otherwise you'll have to declare another variable which may require scoping( I always use the datetimepicker in it's own child form). As JVierra pointed out $this is only available within the event.

Depending on the size of your table you might choose to write your sql select statement to return rows of $this greater than datetime column or return all rows then let powershell do that work with | ? {$_.datetimecolumn -gt $this}.
This topic is 7 years and 10 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