ENDIF without IF

Previous topic - Next topic

ckrum

Feeling like a newb
Here is the code..
IT PRODUCES AN ERROR - ENDIF without IF
THE 'IF' STATEMENT IS CLEARLY PRESENT SO IS THIS A BUG?
// --------------------------------- //
// Project: omgbug
// Start: Saturday, September 28, 2013
// IDE Version: 10.202
// SETCURRENTDIR("Media") // go to media files

DIM mynumber%[6]
//create an array of numbers for sort
mynumber%[1] = 5
mynumber%[2] = 3
mynumber%[3] = 1
mynumber%[4] = 2
mynumber%[5] = 6
mynumber%[6] = 4

//bubblesort the array
FOR a% = 1 TO 5
   FOR b% = a%+1 TO 6
       IF a%<>B% AND mynumber[a%] > mynumber[b%] THEN   
           memory%=mynumber%[b%]
          mynumber%[b%]=mynumber%[a%]
          mynumber%[a%]=memory%       
      ENDIF   
   NEXT
NEXT

FOR i%= 1 TO 6
PRINT i% + " " + mynumber%[i%], 100 + (i%*20),100
NEXT

erico

Welcome.

It looks fine to me,
I think you don´t need that "THEN" on the IF line, only when you single line stuff.
For example:

If erico=coolguy then world=better

In your case, you have multiple results so:

If erico=coolguy
    world=better
    life=good
    ckrum=welcome
endif

I think that might be the answer.
You should also use the # up there the post window when posting code, makes it easier to test.
Like this:
Code (glbasic) Select
if codetag=1
forum=clean
check=1
endif


Welcome again! :)

ckrum

You are Genius!
Thank you very much.
I just found and bought the GLBasic today.
Thanks to you my program runs correctly.
It is a simulation of the lottery drawing to help the user generate a unique set of numbers.
It simulates an actual drawing by mixing virtual lottery balls rather than generating random numbers.
Not like that is going to help me win the lottery but the concept provided some enthusiasm on my part to fight the syntax.

Thank you again.

erico

hehe nice idea! I did a random number generator a couple years ago on the purpose that my my machine+GLB would make it an easy win...well, I didn´t win, probably cause my machine was angry. ;/

You will see GLB is a fine tool, check the online manual or press F1 in program and you pretty much get all you need to start up good.
This forum is also gold stuffed with examples and solutions beyond belief. Some questions can be answered with a simple search.

Enjoy!

Ian Price

You might want to look at the SWAP command for your bubble-sorting function.

Welcome BTW. :)
I came. I saw. I played.

mentalthink

Hi crum Welcome to the Comunity...

About your program don't care I did the same when I bought GLbasic but I continue poor, I don't win the Lottey  :D :D

About your code the error it's like says Erico you forget put the Endif, my counsil it's aleways read what says  the compiler, the bottom part of your screen, I never read when I start to do code and it's a great error, you will learn a lot spend a bit of time reading what happends in your code...

Ah don't believe what's says erico about a good boy... he's a "cabroncete" JAJAJ  =D =D =D :good:

Regards, and any question here you can find very very clever people and perfect answers.
Willkomen   :booze:

erico

Quote from: ckrum on 2013-Sep-29
...
It simulates an actual drawing by mixing virtual lottery balls rather than generating random numbers.
Not like that is going to help me win the lottery but the concept provided some enthusiasm on my part to fight the syntax.
...

I´m pretty sure you will manage to resolve it.

Then, you could also take it a bit further and add visuals and sound.
That code could be a great playground to test and check out multimedia commands in GLB, specially if you already have the code (logic part) working perfectly beneath it.

Let us know the results! Say, I´m even willing to try out your soft´s numbers on the lottery here. :good:

Quote from: mentalthink on 2013-Sep-29
...
Ah don't believe what's says erico about a good boy... he's a "cabroncete" JAJAJ  =D =D =D :good:
...

What!!! Hehe, lots of clever people with a great sense of humor around here! :P ;)

MrTAToad

Don't forget that GLBasic has the very efficient Quicksort sorting routine in the name of SORTARRAY available...

Ian Price

SORTARRAY is indeed good, unless you need to swap more than one array at a time. In this case it would be OK, but for a high score table it's not so good (where you are changing scores, names and possibly level attained etc.)
I came. I saw. I played.

Ian Price

I was trying to explain the simplest way of doing the array sorting, rather than going into the nitty-gritty ;)

OP was using a bubble-sorting method and SWAP would reduce the amount of code without altering it considerably. It fitted in well with what he had - more so than SORTARRAY or datastructures.
I came. I saw. I played.

ckrum

thanks... I think I am gonna enjoy GLB esp when I get the freakin thing to build the apk files.. :rant: