Function Button_Click()
{
Param([Parameter(Mandatory=$True)]
$telephone,
$calledtoSee,
$wantstoSeeyou,
$pleaseCall,
$willcallAgain,
$returningYourCall,
$ToSelection,
$from,
$telephoneNumber,
$message)
[boolean]$okayContinue=$true
[string]$radioSelectedText
[string]$comboBoxSectionText
[string]$persontoEmail
$callType
$messageCount
$comboBoxSectionText = $ToSelection.GetItemText($ToSelection.SelectedItem)
if($okayContinue){
if($comboBoxSectionText -eq "Please Select Contact"){
[System.Windows.Forms.MessageBox]::Show("Please Select Recipient")
$okayContinue=$false
}
}
if($okayContinue){
if([string]::IsNullOrWhiteSpace($from.Text)){
[System.Windows.Forms.MessageBox]::Show("Please Enter Who The Message is From")
$from.focus()
$okayContinue=$false
}
}
if($okayContinue){
if([string]::IsNullOrWhiteSpace($telephoneNumber.Text)){
[System.Windows.Forms.MessageBox]::Show("Please Enter Telephone Number")
$telephoneNumber.focus()
$okayContinue=$false
}
}
#######################################################################################################################################################
if($okayContinue){
if($telephone.Checked){
$callType = $telephone.Text
}
elseif($calledtoSee.Checked){
$callType = $calledtoSee.Text
}
elseif($wantstoSeeyou.Checked){
$callType = $wantstoSeeyou.Text
}
elseif($pleaseCall.Checked){
$callType= $pleaseCall.Text
}
elseif($willcallAgain.Checked){
$callType = $willcallAgain.Text
}
elseif($returningYourCall.Checked){
$callType = $returningYourCall.Text
}
else{
[System.Windows.Forms.MessageBox]::Show("Please Select Call Type")
$okayContinue=$false
}
}
if($okayContinue){
if([string]::IsNullOrWhiteSpace($message.Text)){
[System.Windows.Forms.MessageBox]::Show("Please Enter Message")
$okayContinue=$false
}
}
if($okayContinue){
$buildPerson=$comboBoxSectionText.Split(',')
$personObject = [pscustomobject]@{
FirstName = $buildPerson[0]
LastName = $buildPerson[1]
Email = $buildPerson[2]
}
$messageObject = [pscustomobject]@{
Message = $message.Text
MessageFor = $personObject
From = $from.Text
CallType = $callType
Telephone = $telephoneNumber.Text
}
}
I've got a form with 6 radio buttons, and 2 text boxes, and a combobox. Now, in terms of error validation, I decided to use a boolean value and check to see that the textboxes are properly filled and that a recipient has been selected. After everything has been filled in, then an object is created.
Am I on the right track when it comes to error validation? Could I be handling it better?