Problems with If statement

# Thread: Problems with If statement

1. Job
Junior Member
Join Date
Dec 1969
Posts
17

## Problems with If statement

Could anyone plz help.<BR><BR>Why won&#039;t this statement show right when TWO of the colums are empty like the statement on Omrade AND Kategori? It wil only show the first Omrade statement!<BR><BR>IF IsNull(Omrade) THEN<BR> Response.Write ("Omrade er tomt")<BR>ElseIF IsNull(Kategori) THEN<BR> Response.Write ("Kategori er tomt")<BR>ElseIF IsNull(Fylke) THEN<BR> Response.Write ("Fylke er tomt")<BR>ElseIF IsNull(Omrade) AND IsNull(Kategori) THEN<BR> Response.Write ("Område og Kategori er tomt")<BR>ElseIF IsNull(Omrade) AND IsNull(Fylke) THEN<BR> Response.Write ("Omrade og Fylke er tomt") <BR>ElseIF IsNull(Kategori) AND IsNull(Fylke) THEN<BR> Response.Write ("Kategori og Fylke er tomt")<BR>End If

2. sb
Senior Member
Join Date
Dec 1969
Posts
238

## RE: Problems with If statement

Because the the first if condition becomes true and it just displays the output and then gets out of the entire if-then loop. <BR>what you can easily do is first check for the two conditions and then go on to the single ones.<BR>Like:<BR>if IsNull(Omrade) AND IsNull(Kategori) THEN<BR>Response.Write ("Område og Kategori er tomt")<BR>elseif IsNull(Omrade) THEN<BR>Response.Write ("Omrade er tomt")<BR><BR>and so on... this way, if both the conditions are not true, then only it&#039;ll check for singular ones.<BR>

3. Senior Member
Join Date
Dec 1969
Posts
474

## RE: Problems with If statement

Because if IsNull(Omrade) is true, the code does a response.write and then jumps to the end if statement.<BR><BR>You could try something like this:<BR><BR>ErrorText = ""<BR>IF IsNull(Omrade) THEN<BR> ErrorText = "Omrade"<BR>End if<BR>IF IsNull(Kategori) THEN<BR> If Len(ErrorText) = 0 then<BR> ErrorText = "Kategori"<BR> Else<BR> ErrorText = " og Kategori"<BR> End If<BR>End If<BR>IF IsNull(Fylke) THEN<BR> If Len(ErrorText) = 0 then<BR> ErrorText = "Fylke"<BR> Else<BR> ErrorText = " og Fylke"<BR> End If<BR>End If<BR>If Len(ErrorText) &#062; 0 then<BR> Response.Write ErrorText & " er tomt"<BR>End If

4. Senior Member
Join Date
Dec 1969
Posts
202

## RE: Problems with If statement

Because of the logic of your code... if one of the values is null, it executes the "then" part for that value, and skips the rest. Sounds like you just need several if statements in a row, like this:<BR><BR>IF IsNull(value1) THEN<BR>Response.Write ("...")<BR>END IF<BR>IF IsNull(value2) THEN<BR>Response.write ("...")<BR>END IF<BR>etc...<BR><BR>Each value will be checked, and that is what you want.

5. Job
Junior Member
Join Date
Dec 1969
Posts
17

## RE: Problems with If statement

Thx everyone:o) Now it works!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•