Multiple IF's and matching

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Mark Prior Mark Prior 3 months ago.

  • Author
    Posts
  • #69649
    Profile photo of Mark Prior
    Mark Prior
    Participant

    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
    
    
  • #69667
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    >>'$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)

  • #69670
    Profile photo of Mark Prior
    Mark Prior
    Participant

    ahhh thanks max will give this a go

You must be logged in to reply to this topic.