realbasic-nug
[Top] [All Lists]

Re: Elseif problem?

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Elseif problem?
From: Arnaud Nicolet <anic297@mac.com>
Date: Tue, 30 Jun 2009 22:50:35 +0200
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <C670434D.57979%markus_winter@online.de>
References: <C670434D.57979%markus_winter@online.de>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
Le 30 juin 09 à 22:33, Markus Winter a écrit:

Hi,

I have the following code which jumps over the elseif statement straight into the second loop but does not execute it - with CB_Numeric checked,
StartValue = 10, EndValue = 5, and StepValue = -1 :


  // initialize

  EditField1.text = ""
  dim i as Double = 0

  dim StartValue as Double = Val(EF_Start.text)
  dim EndValue as Double = Val(EF_End.text)
  dim StepValue as Double = Val(EF_Step.text)

  if  EF_Step.text = "" or StepValue = 0 then
    StepValue = 1
    EF_Step.text = "1"
  else
    StepValue = Val(EF_Step.text)
  end if


  if CB_Numeric.value then // if numeric


    if  StartValue <= EndValue  And  StepValue >0 then  // count up

      for i = StartValue to EndValue step StepValue
        EditField1.AppendText Str(i) + EndOfLine
      next


elseif StartValue >= EndValue And StepValue <0 then // count down

      for i = StartValue DownTo EndValue step StepValue
        EditField1.AppendText Str(i) + EndOfLine
      next

    else
MsgBox "The numeric values would result in an endless loop - please
correct them"
      exit
    end if


  else  // not numeric then use the EF_Cases

    MsgBox "not numeric"

  end if



I can follow in the debugger that code execution is

  if CB_Numeric.value then // if numeric

    if  StartValue <= EndValue  And  StepValue >0 then
  // jumps over the elseif statement
      for i = StartValue DownTo EndValue step StepValue

but does not execute the second loop, it just continues after the last end
if


I made a small demo at
http://ahatfullofsky.comuv.com/files/bugs/Elseif_bug.rbp.zip


Anyone can tell me where I muck this up?

I just tried it.
It appears that either:

for i = StartValue To EndValue step StepValue

or

for i = StartValue DownTo EndValue step abs(StepValue)

work (ie: the negative condition should be used only once. If you have both a negative step and a downto, the result is an incrementing loop (minus by minus), and the loop exits of course.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>