if and else without braces

If your definition of EOK is as follows: #define EOK 0; then it would cause this type of error, because it forcibly terminates the if-statement before the else is reached, making it an else without a matching if. The compiler sees this code after macro replacement: if(GetSomething()) error = 0;; else

SQL Server : check if variable is Empty or NULL for WHERE clause

Just use If @searchType is null means ‘return the whole table’ then use WHERE p.[Type] = @SearchType OR @SearchType is NULL If @searchType is an empty string means ‘return the whole table’ then use WHERE p.[Type] = @SearchType OR @SearchType=”” If @searchType is null or an empty string means ‘return the whole table’ then use … Read more

How to do a single line If statement in VBScript for Classic-ASP?

The conditional ternary operator doesn’t exist out of the box, but it’s pretty easy to create your own version in VBScript: Function IIf(bClause, sTrue, sFalse) If CBool(bClause) Then IIf = sTrue Else IIf = sFalse End If End Function You can then use this, as per your example: lunchLocation = IIf(dayOfTheWeek = “Tuesday”, “Fuddruckers”, “Food … Read more

Design Pattern to implement Business Rules with hundreds of if else in java

You should check out the Rules Design Pattern http://www.michael-whelan.net/rules-design-pattern/. It looks very similar to the example code you gave and consists of a base interface that defines a method for determining if a rule is satisfied and then various concrete implementations per different rules. As I understand it, your switch statement would turn into some … Read more