If..ElseIf..Else problem 
Author Message
 If..ElseIf..Else problem



Quote:
> The problem is that the addition of this extra 4 lines stops the earlier
> conditions - the Val(DetSec$) = 0 and DetSec$=LastDetSec$ - from
> evaluating correctly.

I suspect that the problem lies somewhere else.  

Can you try:

If Trim$(DetSec$) = Trim$(LastDetSec$) then ...

--
Mike Coleman              "The secret of success in business is
Allegheny R&D, Inc.       sincerity.  As soon as I learn to fake
Pittsburgh, PA            sincerity, I'll have it made."



Mon, 30 Jun 1997 22:39:49 GMT  
 If..ElseIf..Else problem
Can anyone help with what seems a simple problem?

I have the following structure to decode what value to assign to the
string Fresh$:

        If Val (DetSec$) = 0 Then
                Fresh$ = "OLD"
        ElseIf DetSec$ = LastDetSec$ Then
                Fresh$ = "OLD"
        'New ElseIf to be inserted here
        Else
                Fresh$ = "NEW"
        End If

This code works exactly as I expected. Now I add the following, inserted
at the point shown by the comment:

        ElseIf MonType$ = "Acc4" Or MonType$ = "K7137" Then
                If Val (PeakPress$) < Val(TestSys$) Then
                        Fresh$ = "OLD"
                End If

and then there's the

        Else
                Fresh$ = "NEW"
        EndIf

part.

The problem is that the addition of this extra 4 lines stops the earlier
conditions - the Val(DetSec$) = 0 and DetSec$=LastDetSec$ - from
evaluating correctly.

I suspected that a problem might be caused if the If...EndIf block in
the new ElseIf was not being handled properly, so I tried removing this,
leaving just ElseIf [condition] Then with no statements to execute if
the condition evaluates true. This did not solve the problem.

It seems that just adding a second ElseIf to the structure has messed it
up. This is not what I expected from the Help.

Anyone know why, or seen this themselves?

Thanks in advance,

Bill.



Mon, 30 Jun 1997 18:21:36 GMT  
 If..ElseIf..Else problem

Quote:



>> The problem is that the addition of this extra 4 lines stops the earlier
>> conditions - the Val(DetSec$) = 0 and DetSec$=LastDetSec$ - from
>> evaluating correctly.

>I suspect that the problem lies somewhere else.  
>Can you try:
>If Trim$(DetSec$) = Trim$(LastDetSec$) then ...

I can try this - though I have now rewritten the thing anyway, rather
less elegantly than before. But why should this work? Clearly if astring
=bstring then Trim$(astring)=Trim$(bstring), but why should the latter
test help? The problem only arose when I added the extra ElseIf so
surely that will be the cause?

Thanks for your assistance,

Bill.



Sat, 05 Jul 1997 00:53:38 GMT  
 If..ElseIf..Else problem

Quote:
> Can anyone help with what seems a simple problem?
> ......

>    ElseIf MonType$ = "Acc4" Or MonType$ = "K7137" Then
>            If Val (PeakPress$) < Val(TestSys$) Then
>                    Fresh$ = "OLD"
>            End If

> and then there's the

>    Else
>            Fresh$ = "NEW"
>    EndIf

> part.

> The problem is that the addition of this extra 4 lines stops the earlier
> conditions - the Val(DetSec$) = 0 and DetSec$=LastDetSec$ - from
> evaluating correctly.

Hi Bill, have you tried adding some parenthesis to the condition?

Ex: ElseIf (MonType$ = "Acc4") Or (MonType$ = "K7137") Then

I have had some similar problems, all because VB considers it differently
that C does...
Good luck,

                Rafel



Sat, 05 Jul 1997 22:58:19 GMT  
 If..ElseIf..Else problem

Quote:


>> Can anyone help with what seems a simple problem?
>> ......

>>        ElseIf MonType$ = "Acc4" Or MonType$ = "K7137" Then
>>                If Val (PeakPress$) < Val(TestSys$) Then
>>                        Fresh$ = "OLD"
>>                End If

>> and then there's the

>>        Else
>>                Fresh$ = "NEW"
>>        EndIf

>> part.

>> The problem is that the addition of this extra 4 lines stops the earlier
>> conditions - the Val(DetSec$) = 0 and DetSec$=LastDetSec$ - from
>> evaluating correctly.

>Hi Bill, have you tried adding some parenthesis to the condition?
>Ex: ElseIf (MonType$ = "Acc4") Or (MonType$ = "K7137") Then

First thing I went for, unfortunately. Made no difference - I'm starting
to think this is a bug. Luckily my rewrite, which does not use ElseIf
but multiple Ifs and sets flags, works ok. I don't know if this is
wasteful of speed or memory or exe file size, but none of these is
critical despite the program running in real time controlling machines.

Thanks for the idea,

Bill.  



Mon, 07 Jul 1997 17:55:06 GMT  
 If..ElseIf..Else problem


Quote:
> Can anyone help with what seems a simple problem?

> I have the following structure to decode what value to assign to the
> string Fresh$:

>         If Val (DetSec$) = 0 Then
>                 Fresh$ = "OLD"
>         ElseIf DetSec$ = LastDetSec$ Then

I would avoid elseif like the plague--even if you can get it right, it
will be hard for people to read.  

I would use either:

select case true
  case ...
  case ...
  case else
end select

or this:

if .... then
  ...
else
  ...
  if .... then  
    ...
  else
    ...
  end if
  ...
end if

(etc.)

DISCLAIMER:  MY OPINIONS ARE PURELY MY OWN.

+-----------------------+-------------------------------------------+

+-----------------------+-------------------------------------------+



Sun, 13 Jul 1997 08:04:53 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. if then elseif problem

2. Problems with a simple if-elseif

3. nested if/elseif statements

4. If Then ElseIf Statements

5. Select case/if then elseif

6. Elseif Statements

7. Need confirmation about ElseIf statement

8. Select Case Vs If - ElseIf

9. If Then ElseIf the solution to this bug?

10. Elseif Condition in Crystal Reports 4.6

11. If-Then-Elseif

12. If..Elseif vs. Select case

 

 
Powered by phpBB® Forum Software