Android Question if then else question

Yves Mazzon

Member
Licensed User
Longtime User
If you have many conditions to check can you put them all in a single if?
For example if label1.text ="" and label2.text="" and lable3.text = "" then
Msgbox("Missing data", "Please fill all the boxes").
Maybe the way I show it is not right. What I wanted to do is when the operator click ok and the program start calculating the various entries you get a warning that some entries are missing. Many thanks
Yves
 
Yes this is fine. It is also useful in some instances because the If condition will stop at the first false condition, this can have nice speed benifits.
 
Upvote 0
For example if label1.text ="" and label2.text="" and lable3.text = "" then
I am not sure if you are aware that the way yo have it, the message appears only when all labels are empty. But if you want the message to appear if any of them is blank, you need to do this:
Code: Copy
if label1.text ="" or label2.text="" or lable3.text = "" then
 
Upvote 0
So, from a performance point of view, is it better to have very long IF's instead of chained IF's?
Code: Copy
If a and b and c and d and e and f and g and h then ...

'vs.

If a then
  if b then
    if c then
      if d then
        ...
      end if
    end if
  end if
end if
 
Upvote 0
Usually ONE condition is enough to push a message and stop the action. What I do (to keep my code readable and my old head in line) is:

If (Edittext1 is empty/wrong/too long) then
...
RETURN -> Leaves the Sub
End If

If (Edittext2 is empty/wrong/too long) then
...
RETURN ->Leaves the Sub
End If

Do the main thing here = It only will be executed if everything is OK
 
Upvote 0

Similar Threads

Replies
9
Views
5K
Replies
36
Views
137K
  • Locked
  • Article Article
Android Tutorial Google Maps
Replies
192
Views
208K
Back
Top