locked
IIF Function RRS feed

  • Question

  • Hi Expert,

    Wat wrong with below formula? i want put it in control source.

    =IIf(([txtULt]=" ",[txtULd]),IIf([txtULt]<>" ",[txtULd]-[txtULt]))

    Thanks.

    Danny

    Thursday, July 14, 2011 3:20 AM

Answers

  • Are you working with Microsoft Access?

    In any event, the second IIf statement is not required:

    IIf([txtULt]=" ",[txtULd],[txtULd]-[txtULt])
    
    
    

     


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by Danny Gan Wednesday, July 20, 2011 8:32 AM
    Thursday, July 14, 2011 12:48 PM

All replies

  • Hi Danny,

    I guess that

    txtULt

    and

    txtULd

    are TextBoxes?

    In which case try this please:>>

     

     = Convert.ToString(IIf(txtULt.Text = " ", txtULd.Text, (Val(txtULd.Text) - Val(txtULt.Text)).ToString))
    


    Are you using this in some version of VB.Net either the EXPRESS EDITION or VISUAL STUDIO?

    Where are you trying to use this code exactly please?

     



    Regards,

    John

    Click this link to see how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    XNA is coming to VB.Net

    App Hub forums



    • Proposed as answer by Mike Feng Monday, July 18, 2011 9:05 AM
    Thursday, July 14, 2011 3:59 AM
  • Danny,

    Try to avoid the IIF function in Visual Basic, it goes always different than you expect 

    (it evaluates always the first and the second one)


    Success
    Cor
    Thursday, July 14, 2011 5:56 AM
  • Danny,

    Try to avoid the IIF function in Visual Basic, it goes always different than you expect 

    (it evaluates always the first and the second one)


    Use If (,,) for the short circuit equivalent.
    Thursday, July 14, 2011 8:08 AM
  • Danny,

    Try to avoid the IIF function in Visual Basic, it goes always different than you expect 

    (it evaluates always the first and the second one)


    Use If (,,) for the short circuit equivalent.

    Hi John,

    I can't use 'IF' it is err.

    Thursday, July 14, 2011 9:13 AM
  • Be aware it is only in framework 3.0 and newer (visual basic 2008 and 10)

    http://msdn.microsoft.com/en-us/library/bb513985.aspx

     


    Success
    Cor
    Thursday, July 14, 2011 10:17 AM
  • That's probably good.  If ... Then ...  Else is usually best for readability and maintainability.  Your code should error with either IIF or IF.
    Thursday, July 14, 2011 11:59 AM
  • Are you working with Microsoft Access?

    In any event, the second IIf statement is not required:

    IIf([txtULt]=" ",[txtULd],[txtULd]-[txtULt])
    
    
    

     


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by Danny Gan Wednesday, July 20, 2011 8:32 AM
    Thursday, July 14, 2011 12:48 PM