home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2002 #3 / K-CD-3-2002.ISO / OpenOffice / f_0046 / sbasic.jar / text / sbasic / common / 03090410.xml < prev    next >
Encoding:
Extensible Markup Language  |  2001-09-07  |  2.2 KB  |  34 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <html><head><title>Switch Function [Runtime]</title><meta name="filename" content="text/sbasic/common/03090410"/><help:css-file-link xmlns:help="http://openoffice.org/2000/help"/><!--The CSS style header method for setting styles--><style type="text/css">
  3.  
  4.         p.P1{
  5.                 }
  6.         span.T1{
  7.                 font-weight:bold;}
  8.         </style></head><body>
  9.   
  10.   
  11.   <help:to-be-embedded Eid="switch" xmlns:help="http://openoffice.org/2000/help">
  12.   <p class="Head1"><help:link Id="66497">Switch Function [Runtime]</help:link></p>
  13.   <p class="Paragraph">Evaluates a list of arguments, consisting of an expression followed by a value. The Switch function returns a value associated with the expression passed with this function.</p>
  14.   </help:to-be-embedded>
  15.   <p class="Paragraph"><span class="T1">Syntax</span>:</p>
  16.   <p class="Paragraph">Switch (Expression1, Value1[, Expression2, Value2[..., Expression_n, Value_n]]) <help:key-word value="Switch" tag="kw66497_1" xmlns:help="http://openoffice.org/2000/help"/></p>
  17.   <p class="Paragraph"><span class="T1">Parameter</span>:</p>
  18.   <p class="Paragraph">The <span class="T1">Switch</span> function evaluates the expressions from left to right, and returns the value assigned to the function expression. If expression and value are not given as a pair, a runtime error will occur.</p>
  19.   <p class="Paragraph">Expression: The expression to be evaluated.</p>
  20.   <p class="Paragraph">Value: The value to be returned if the expression is True.</p>
  21.   <p class="Paragraph">In the following example the <span class="T1">Switch</span> function is used to assign the appropriate gender to the name given to the function:</p>
  22.   <p class="Paragraph"><span class="T1">Example:</span></p>
  23.   <p class="PropText">Sub ExampleSwitch</p>
  24.   <p class="PropText">Dim sGender As String</p>
  25.   <p class="PropText">sGender = GetGenderIndex( "John" )</p>
  26.   <p class="PropText">MsgBox sGender</p>
  27.   <p class="PropText">End Sub</p>
  28.   <p class="PropText"/>
  29.   <p class="PropText">Function GetGenderIndex (sName As String) As String</p>
  30.   <p class="PropText">GetGenderIndex = Switch(sName = "Jane", "female", sName = "John", "male")</p>
  31.   <p class="PropText">End Function</p>
  32.   <p class="PropText"/>
  33.   <p class="PropText"/>
  34.  </body></html>