vba - Enum condition behavior : enum_Var = str1 Or str2 -


(i use simple example , not original code, not relevant)

i wanted make if statement on enum, or. excel vba editor suggested use kind of syntax : if current = apple or peach then(dropdown choice, see below)

screenshot

well, curious why not. figured out while testing behavior wasn't 1 expect :

public enum fruit     apple     peach     banana end enum  public sub pick()      dim current fruit     current = banana      if current = apple or peach         '//the condition true         msgbox "toc"     end if  end sub 

indeed, in code, if true. not don't know why : think peach evaluated integer or so, beeing different 0, it's true. proof, if in enum fruit declaration, peach forced 0, it's false.

public enum fruit     apple     peach = 0     banana end enum  public sub pick()      dim current fruit     current = banana      if current = apple or peach         '//the condition false time         msgbox "toc"     end if  end sub 

my question (yeah, not vital, understanding) : why hell editor suggest me drop down list in above screenshot ? feel there hidden there...

thank feedback, valentin.

edit not looking way write condition (as quiet obvious if current = apple or current = peach then). question relates drop down list suggestion.

maybe because enum representation of integer constants , used masking.

so in example apple = 0, peach = 1, banana = 2

with or , and can combine values, used bit masking. ur example values wouldn't make sense. use bit values 1, 2, 4, 8, 16.

and if want set option can 1 or 2, mask first 2 bits (=3) represent both options should used.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -