Author Posts

April 27, 2017 at 7:42 am

Hi Guys working on a GUI, and taking in from that some text box'es to strings

my scenarios are

If ($from & $Subject is populated and $from does not contain the * character) do X
If (only $from is populated and it does not contain the * character) do Y
If (only $subject is populated and $from is null) do Z

However results are not what i would expect from below


    $from = "Text"
	$Subject = "text"

	#X
	if ($from -and $subject -and $from -notmatch "\*")
	{
		try
		{
			$listbox1 ="From Field & Subject Field"
			
			
		}
		
		catch
		{
			$test = "Something Went Wrong, Please Process Manually"
			 $listbox1 = $test
		}
		
	}
	
#Y
	if ($from -and $from -notmatch "\*" -and $Subject -match "$null")
	{
		try
		{
			 $listbox1 ="From Field Only"
			
			
		}
		
		catch
		{
			$test = "Something Went Wrong, Please Process Manually From Field Only"
			 $listbox1 = $test
		}
		
#Z
		if ($subject -notmatch "$null" -and $from -match "$null")
		{
			try
			{
				 $listbox1 ="Subject Field Only"
				
				
			}
			
			catch
			{
				$test = "Something Went Wrong, Please Process Manually"
				 $listbox1 = $test
			}
			
		}
		
	
		
	}
	
	Else
	{
		
		$test2 = "Wilcards (*) Cannot Be Used In From Field"
		$listbox1 = $test
		 $listbox1 = $test2
	}

cls
$listbox1

April 27, 2017 at 10:20 am

>>'$Subject -match "$null")'

-match parameter is a string and you want $null text in it 🙂 besides that '$' is a special regex symbol taht match end of a string

you can use (-not $Subject) like you use ($from)

April 27, 2017 at 10:42 am

ahhh thanks max will give this a go