Running New-Item in a form vs. running it in global area

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 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
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

Running New-Item in a form vs. running it in global area

Post by jsira2003@yahoo.com »

Product, version and build:
(*** Please do not write "latest" as a version, specify a version number ***)
32 or 64 bit version of product:
Operating system:
32 or 64 bit OS: windows 10 pro 64-bit
PowerShell Version: 17

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

I tried to use the new-item to create a directory in a form. The new-item worked fine with a directory path but not with a unc. My issue is not with share permissions or file permissions.

Then I did the same command successfully where you define globals. My command worked correctly. Is there any reason why a new-item command that creates a unc directory would not work in a form yet work in the area you define globals? I tried it without variables and put my actual path in between double quotes. It didn't work. The error I got was invalid path. However looking at the path on the screen, it was correct. I resolved my issue by creating a function in the globals area and calling this from the form and passing the arguments I needed to create the directory. I had the function return the err variable and all ends well.

This was perplexing! As I work in a forms environment I suspect there is an explanation for what occurred.

Any explanation would be helpful and appreciated!

thanks,
John
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Running New-Item in a form vs. running it in global area

Post by davidc »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]

I'm not sure the exact cause without looking at the script, but often times it can be attributed to a scoping issue.
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Running New-Item in a form vs. running it in global area

Post by jvierra »

There is no reason for this except for a coding error. I suspect your code is not being executed or you would get an error.
User avatar
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

Re: Running New-Item in a form vs. running it in global area

Post by jsira2003@yahoo.com »

As a new users of the forms product it appears that I am constantly running into this issue. I am attempting to resolve these issues by putting more functions/variables in global and then when a form needs to do something I call the function. I also noticed a form didn't work right with out-file but worked fine with add-content. Is there certain commands to avoid while working with forms? I suspect there are limitations since I have been having repeating problems.

For my first project I have a huge challenge I am trying to learn your powershell 2017 product, use an sql database backed working exclusively with forms! I did remember when I have the sqlps loaded any files references are prefixed with FileSystem::

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

Re: Running New-Item in a form vs. running it in global area

Post by jvierra »

Again - this is not something that I have ever experienced with PSS and I suggest it is a coding issue. Without a exact example of what you are saying it is not possible to understand what you are seeing.
This topic is 6 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