Why not use the "IIF" statement:

Dim x as integer
Dim y as integer
Dim z as Object

iif(x=5,y=10,z=whatever)

The following explanation was lifted verbatim from: 
http://kandkconsulting.tripod.com/VB/VBword_of_the_month.htm##July2000

 
The IIF() Function is a clean, "Code Neat", mini If statement. It will Return one of 
two parts, depending on the evaluation of an expression.  The prototype is as follows:

IIf(expr, truepart, falsepart)

The IIf function syntax has these named arguments:

      Part Description 
      expr Required. Expression you want to evaluate. 
      truepart Required. Value or expression returned if expr is True. 
      falsepart Required. Value or expression returned if expr is False. 

Remarks
IIf always evaluates both truepart and falsepart, even though it returns only one of 
them. Because of this, you should watch for undesirable side effects. For example, if 
evaluating falsepart results in a division by zero error, an error occurs even if expr 
is True. 


HTH
Dave

  ----- Original Message ----- 
  From: Tim Rupp 
  To: [EMAIL PROTECTED] 
  Sent: Wednesday, August 18, 2004 9:19 PM
  Subject: RE: [vbhelp] Logical Expressions


  In the first case you have a boolean expression...in your second case,
  you have no boolean just two integer values...thus you're attempting to
  compare apples to oranges in the two example cases.

  dim y as boolean 

  Case: y = (x =4), since x<>5, then y (boolean) is False

  Case: y = (x=5), since x=5, then y (boolean) is True          

  in your second example y is most probably dimensioned as an integer or
  some other numeric value that is NOT boolean and you have two arithmetic
  variable expressions with the independent expression being x=5, and the
  dependent expression y=10. (y=10 if x=5). As you should see, there isn't
  a boolean value (true or false) here to evaluate.

  Another way to handle this would be 

  Dim y as Integer, x as Integer

  Select Case y
      Case 5
          x =10
      Case Else
          ' whatever
  End Select



  -----Original Message-----
  From: four_blades [mailto:[EMAIL PROTECTED] 
  Sent: Wednesday, August 18, 2004 9:31 PM
  To: [EMAIL PROTECTED]
  Subject: [vbhelp] Logical Expressions


  I was reading that you can simplify an If Then Else Statement such 
  as:

  If x = 5 then
      y = True   'y is boolean
  else
      whatever
  end if

  by re-writing as

  y = (x = 5)  
  Because if (x = 5) is evaluated to "True" then
  y is initialized to "True" also.

  That's all well enough, but I'm having trouble seeing how to use 
  this eye pleasing space saver to handle something like this:

  If x = 5 then
      y = 10
  else
      whatever
  end if

  Can anyone explain this to me?





  '// =======================================================
      Rules : http://ReliableAnswers.com/List/Rules.asp
      Home  : http://groups.yahoo.com/group/vbHelp/
      =======================================================
      Post  : [EMAIL PROTECTED]
      Join  : [EMAIL PROTECTED]
      Leave : [EMAIL PROTECTED]
  '// =======================================================




  Yahoo! Groups Sponsor      

  ADVERTISEMENT

  <http://us.ard.yahoo.com/SIG=12935sd4f/M=298184.5285298.6392945.3001176/
  D=groups/S=1705115364:HM/EXP=1092966106/A=2319501/R=0/SIG=11tq0u909/*htt
  p://www.netflix.com/Default?mqso=60185353&partid=5285298> click here      

  <http://us.adserver.yahoo.com/l?M=298184.5285298.6392945.3001176/D=group
  s/S=:HM/A=2319501/rand=845401596>       


    _____  

  Yahoo! Groups Links


  *      To visit your group on the web, go to:
  http://groups.yahoo.com/group/vbhelp/
    

  *      To unsubscribe from this group, send an email to:
  [EMAIL PROTECTED]
  <mailto:[EMAIL PROTECTED]> 
    

  *      Your use of Yahoo! Groups is subject to the Yahoo! Terms of
  Service <http://docs.yahoo.com/info/terms/> . 




  [Non-text portions of this message have been removed]




  '// =======================================================
      Rules : http://ReliableAnswers.com/List/Rules.asp
      Home  : http://groups.yahoo.com/group/vbHelp/
      =======================================================
      Post  : [EMAIL PROTECTED]
      Join  : [EMAIL PROTECTED]
      Leave : [EMAIL PROTECTED]
  '// =======================================================



        Yahoo! Groups Sponsor 
              ADVERTISEMENT
             
       
       


------------------------------------------------------------------------------
  Yahoo! Groups Links

    a.. To visit your group on the web, go to:
    http://groups.yahoo.com/group/vbhelp/
      
    b.. To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]
      
    c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 



[Non-text portions of this message have been removed]




------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/k7folB/TM
--------------------------------------------------------------------~-> 


'// =======================================================
    Rules : http://ReliableAnswers.com/List/Rules.asp
    Home  : http://groups.yahoo.com/group/vbHelp/
    =======================================================
    Post  : [EMAIL PROTECTED]
    Join  : [EMAIL PROTECTED]
    Leave : [EMAIL PROTECTED]
'// =======================================================
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/vbhelp/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to