Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

VisualBasic InputBox Problem

$
0
0

Hello All,

For my first post ever on the TechNet forums, I wanted to thank you all in advance.

My issue is quite odd. The script I created to show an inputbox works fine when ran from the command prompt. However, the people that need to use it will right click the script and hit run in powershell. 

This leads me to the problem. When doing this it errors out because of the [Microsoft.VisualBasic.Interaction] line. Is there anyway to keep my inputbox and run it by right-clicking the script and using Run with Powershell?

Here is the script:

Function MSG_BOX() {
    $USER_SELECTION = [System.Windows.Forms.MessageBox]::Show("You have entered $NUM_OF_CHARS characters, phone number should have ten" , "ERROR" , 0)
    INPUT_BOX
}

Function INPUT_BOX() {
    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
    $GET_NUMBER = [Microsoft.VisualBasic.Interaction]::InputBox("Please enter phone # to parse:", "Phone #", "1234567891")
    $NUM_OF_CHARS = $GET_NUMBER | Measure-Object -Character | Select -ExpandProperty characters
    if($NUM_OF_CHARS -eq 0) { exit 0 }
    if($NUM_OF_CHARS -eq 10) { "Continue" }
        else { MSG_BOX }
}

INPUT_BOX


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>