Normal Topic Combo Box Programming (Read 719 times)
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Combo Box Programming
Jan 28th, 2007 at 8:59pm
Print Post Print Post  
Hi -

I created a combo box with 4 values.  I do not want to allow data entry if the combo box is EMPTY or if DOES NOT contain one of the 4 approved values.  

I tried the following code:

Code
Select All
	If @IsBlank(Status)
		or not status = "deceased"
		or not status = "incomplete"
		or not status = "info only"
		or not status = "reunion"
		{
		NotifyForm(1) // Prevent save
		@MsgBox("You must enter one of the following values!","","Deceased or Incomplete or Info Only or Reunion")
		Goto Status
		}
	Else
		{
		NotifyForm(0) // Allow Save
		} 




If the combo box is empty, I get the desired results; however if I enter ANY VALUE in the combo box field, I do not get an error message.

Since ANY of the 4 values would be acceptable, I first tried using "and not" instead of "or not"; however, I do not get an error message in that case either (unless the status box is empty).

What am I doing wrong?
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Combo Box Programming
Reply #1 - Jan 28th, 2007 at 9:52pm
Print Post Print Post  
Won't a simpler case do? Since you are checking to make sure that it is one of the 4 values, there is no need to check for blank - because that it not one of the four values. Also, since it must be one of the four values, there is no need to check whether it is not any of the four values:
Code
Select All
	If((status = "deceased")
	or (status = "incomplete")
	or (status = "info only")
	or (status = "reunion"))
	{
		NotifyForm(0) // Allow Save
	}
	Else
	{
		NotifyForm(1) // Prevent save
		@MsgBox("You must enter one of the following values!","","Deceased or Incomplete or Info Only or Reunion")
	}
 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Combo Box Programming
Reply #2 - Jan 28th, 2007 at 10:34pm
Print Post Print Post  
Mark -

To be perfectly truthful, even though my programing was far more "clutzier," I still do not understand why it wouldn't work.  But I am not even going to worry about that, because your suggestion was right on! ... and why "argue" with success?!

It works like a charm and you saved me a lot of grief.

Also, I remembered that I'm not supposed to use "goto" so I changed it to "throwfocus" and that too works just like I want.

Thanks very much!!!
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Ben
Lantica Support
*****
Offline



Posts: 218
Joined: Apr 7th, 2005
Re: Combo Box Programming
Reply #3 - Jan 29th, 2007 at 6:48pm
Print Post Print Post  
Two things caused the programming trouble that you were running into.
In your programming, the if statement contains four spots where you check if a value is "Not = 'A choice'". Without parenthesis around the "not=" statements, the not(s) were affecting each other, but with parenthesis around the statements, the logic would still be incorrect.

Your If Statement with Parenthesis Added:
Code
Select All
	If @IsBlank(Status) or (not status = "deceased") or (not status = "incomplete") or (not status = "info only") or (not status = "reunion") 



What the statement is saying is:
Do this if Status is blank, or if Status is not deceased, or if Status is not incomplete, or if Status is not info only, or if Status is not reunion.

What happens if you make a selection?
Let's say that you select "deceased" from the status combo box:

Status is not blank, Status is deceased, but Status is not incomplete, not info only, and not reunion
The if statement simplifies to False, False, True, True, True, which resolves to a true condition, and triggers your if statement.

One way to rewrite your statement would be:

Code
Select All
If @IsBlank(Status) or ((status <> "deceased") and (status <> "incomplete") and (status <> "info only") and (status <> "reunion")) 



-Ben
  
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Combo Box Programming
Reply #4 - Jan 29th, 2007 at 9:10pm
Print Post Print Post  
Ben -

Thank you so much for addressing my first code.  I really appreciate it.

I knew the logic was incorrect with regard to the possibility of it meeting one condition (of the four possible choices .... which would then automatically mean it didn't meet the othere three) but just wasn't hitting on the right approach.

Your explanation is crystal clear and a very big help.
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged