Author Topic: IF/END IF string problem  (Read 5024 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
IF/END IF string problem
« on: November 26, 2012, 01:34:55 PM »
Charles..
I think that something is wrong with IF/END IF block inside FOR/NEXT loop.
In my case i test string
FOR...

IF c$ = "one"
doOne()
END IF

IF c$ = "two"
doTwo()
END IF

IF c$ = "three"
doThree()
END IF

'this IF block refuse to work ???
IF c$ = "Four"
doFour()
END IF

NEXT

If i use IF/ELSEIF/END IF  then work properly... ::)
So fourth IF block don't couse error but create invalid executable  ???

Is this some kind of bug ,if is it- this is really weird...
Do you know for that?


Charles Pegge

  • Guest
Re: IF/END IF string problem
« Reply #1 on: November 26, 2012, 07:08:53 PM »
Hi Aurel, I think the problem may be elsewhere. It is too fundamental to have escaped detection so far

Can you demonstrate the problem with a small program?

my test code:

Code: OxygenBasic
  1. function f1() as sys
  2. return 1
  3. end function
  4.  
  5. function f2() as sys
  6. return 2
  7. end function
  8.  
  9. function f3() as sys
  10. return 3
  11. end function
  12.  
  13. function f4() as sys
  14. return 4
  15. end function
  16.  
  17. sys a,i
  18. string one="one"
  19. string two="two"
  20. string three="three"
  21. string four="four"
  22.  
  23. string s="four"
  24.  
  25. for i=1 to 100
  26.   if s="one"
  27.     a+=f1
  28.   end if
  29.   if s="two"
  30.     a+=f2
  31.   end if
  32.   if s="three"
  33.     a+=f3
  34.   end if
  35.   if s="four"
  36.     a+=f4
  37.   end if
  38. next
  39.  
  40. print a '400
  41.  
  42.  

Charles
« Last Edit: November 27, 2012, 03:26:25 AM by Charles Pegge »

Peter

  • Guest
Re: IF/END IF string problem
« Reply #2 on: November 27, 2012, 03:06:22 AM »
Hi Charles,

X

Charles Pegge

  • Guest
Re: IF/END IF string problem
« Reply #3 on: November 27, 2012, 03:27:51 AM »
Clipped the top of the program, now repaired. Sorry :)

Peter

  • Guest
Re: IF/END IF string problem
« Reply #4 on: November 27, 2012, 03:56:07 AM »
No panic, ( IF/ELESIF/ELSE/ENDIF) works well with OxygenBasic!
« Last Edit: November 27, 2012, 04:12:50 AM by peter »

Aurel

  • Guest
Re: IF/END IF string problem
« Reply #5 on: November 27, 2012, 04:33:15 AM »
No panic but in another computer don't respond.
Now work... ???
Is this problem maybe connected with manifast file?
When i compile program who already have manifest file then this
program in another folder(without manifest) not work...what is strange to me .. ::)
« Last Edit: December 04, 2012, 08:08:12 AM by Aurel »

Peter

  • Guest
Re: IF/END IF string problem
« Reply #6 on: November 27, 2012, 04:42:16 AM »
Hi Aurel,

I solved your problem.

Code: [Select]
sys a,m, string c1="one",c2="two",c3="three",c4="four"

Sub DoFour()
    m +=1
End Sub

Sub DoThree()
    m +=1
End Sub

Sub DoTwo()
    m +=1
End Sub

Sub DoOne()
    m +=1
End Sub

for a=1 to 10

IF c1 = "one" then
   doOne()
END IF

IF c2 = "two"
   doTwo()
END IF

IF c3 = "three"
   doThree()
END IF

IF c4 = "Four"  '<- make "four" and  m will be 40!
   doFour()
END IF

next

print "Aurel programming is weird  " + m

Strings in capitals gives a wrong result!   Help, Help, Help
« Last Edit: November 27, 2012, 04:52:00 AM by peter »

Aurel

  • Guest
Re: IF/END IF string problem
« Reply #7 on: November 27, 2012, 05:27:55 AM »
Gee yes Peter you right literal (quoted)strings in upper case
gives a error- invalid final executable like this :
Code: [Select]
string s="FOUR"

for i=1 to 5

  if s="ONE"
    doOne()
  end if

  if s="TWO"
    doTwo()
  end if

  if s="THREE"
    doThree()
  end if

  if s="FOUR"
    doFour()
  end if
next

but when i change string s to lower case there is no error, like this ..
Code: [Select]
string s="four"

for i=1 to 5

  if s="ONE"
    doOne()
  end if

  if s="TWO"
    doTwo()
  end if

  if s="THREE"
    doThree()
  end if

  if s="FOUR"
    doFour()
  end if
next

So..this looks like a bug,right?
Another thing which i have found is under select/end select ...
instead of :
CASE "A"
i must write
CASE strPtr "A"
why is that ?

Peter

  • Guest
Re: IF/END IF string problem
« Reply #8 on: November 27, 2012, 05:52:32 AM »
Hi Aurel,
Code: [Select]
sys a, m string c="AUREL", c1

for a=1 to 5
    c1= asc(c,a)
    select c1
        case "A"
     m +=1
        case "U"
     m +=1
        case "R"
     m +=1
        case "E"
     m +=1
        case "L"
     m +=1
     end select
next

print "The Name has " + m + " Letters"

Nothing wrong here!

Peter

  • Guest
Re: IF/END IF string problem
« Reply #9 on: November 27, 2012, 06:27:35 AM »
more complicated.
Code: [Select]
sys a,b,ma,mb,mc,md,me, string c="AAUUURELLL", c1

for b=1 to 1
  for a=1 to 10
    c1= asc(c,a)
    select c1
        case "A"
     ma +=1
        case "U"
     mb +=1
        case "R"
     mc +=1
        case "E"
     md +=1
        case "L"
     me +=1
    end select
  next
next

print "Found " + ma + "x  A" 
print "Found " + mb + "x  U" 
print "Found " + mc + "x  R" 
print "Found " + md + "x  E" 
print "Found " + me + "x  L" 

Aurel

  • Guest
Re: IF/END IF string problem
« Reply #10 on: November 27, 2012, 07:01:15 AM »
I dont say that nothing is wrong.
I tell you that compiler don't say it is error because is not  BUT
produced executable is not valid...that is a main problem...

Peter

  • Guest
Re: IF/END IF string problem
« Reply #11 on: November 27, 2012, 09:13:12 AM »
You have got the wrong  OXYGEN.DLL  :D
Amen

Aurel

  • Guest
Re: IF/END IF string problem
« Reply #12 on: November 27, 2012, 10:12:26 AM »
Is not wrong oxygen.dll.... >:(
There is still one old problem connected with transformation from string
to strPtr - which solve problem in half but it is strange that program
when is used bstring  - not crush without manifest
but using strptr() crush without manifest...geee ::)
so i must use bstring for - for example fill listbox control...grrr
I am not sure is this problem somehow connected with FB  ???
All in all some things with strings simply don't work properly in usual way( in GUI programming).

Charles Pegge

  • Guest
Re: IF/END IF string problem
« Reply #13 on: November 28, 2012, 10:23:58 AM »
Quote
produced executable is not valid...that is a main problem...

Try this one.

Charles
« Last Edit: November 29, 2012, 03:37:02 AM by Charles Pegge »

Aurel

  • Guest
Re: IF/END IF string problem
« Reply #14 on: November 28, 2012, 11:27:07 AM »
Hi Charles...
It looks that both examples 'compile and run' fine  ;)
with or without manifest.

Hmm what is this;
#file "t2.exe"
I never see this before  ???
is this something new ?
Do you have made changes in oxygen.dll & rtl32.inc ?

I will try do this directly in my program...
I don't wanna bothering you with strPtr or bstring but sometimes really drive me crazy ::)