Coding Problem
BlitzPlus Forums/BlitzPlus Beginners Area/Coding Problem
| ||
| I have been screwing around with this function far too long, I've used it in other programs and in this one the problem is that it says "End Select without Select". Here's my code
Function StartEruP()
MainMenu=CreateWindow("Main Menu",300,300,400,500,main,15)
Ev=WaitEvent()
Es=EventSource()
Repeat
Select Es
Case MainMenu
If Ev=$803 Then
Blah=Proceed("Do you really want to quit?")
If Blah=1 Then
End
Else
If Blah<>1 Then
Notify("Find out what you want next time")
EndIf
EndIf
End Select
Until KeyDown(1)
End
End Function
StartERuP()
End
On the other program it works, but when ever I attempt to move the window it moves, but the program starts to go on strike. |
| ||
| Arf, my eyes :S .. first indent your code, then ask. Chances are that once you've indented it you'll see it yourself already. |
| ||
| I mean, I took 1 minute to indent your code, and the mistake became as clear as the night. Now it's your turn.. :P |
| ||
Function StartEruP()
MainMenu=CreateWindow("Main Menu,300,300,400,500,main,15)
Ev=WaitEvent()
Es=EventSource()
Repeat
Select Es
Case MainMenu
If Ev=$803 Then
Blah=Proceed("Do you really want to quit?")
If Blah=1 Then
End
Else
If Blah<>1 Then
Notify("Find out what you want next time")
EndIf
EndIf
End Select
Until KeyDown(1)
End
End Function
StartERuP()
End
You mean something like this? I seriously have no idea not even an inkling to what you speak of. Oh, and by the way my other program uses the same function-and it works, like I said before. |
| ||
| I would suggest you take a look at the code posted in the code archives. Most entries (not all) are properly indented for clarity. Not only for the person who posted the code but for anyone else that looks at that code. Code readability is of utmost importance when communicating via code snippets as you have done to start this thread. Don't take this as a rant or flame, just letting you know that others will expect you to present code in a readable form before they will be willing to help you. |
| ||
| It needs an extra End If after the line: Notify("find out what you want next time"). |
| ||
| Ok, crashcourse on indenting: In Blitz there are single commands, and commands that define a scope. Examples of a single command are Print, End, Plot, Rect, Line, LoadImage etc. Examples of scope commands are: For-Next If(-Else)-Endif Select-End Select Function-End Function etc. Key rule: you should indent the scope/area of each scope-command. As an extra bonus you might want to have an empty line around scopes. Based on personal taste: I also indent drawing/actions on a canvas or image between changing the drawing buffer and the flipping, but that's personal. One might even indent creating menuitems in a menu. As long as things belong together for a limited area in your code, you may indent them. So, to apply this on your function:
Function StartEruP()
MainMenu=CreateWindow("Main Menu",300,300,400,500,main,15)
Ev=WaitEvent()
Es=EventSource()
Repeat
Select Es
Case MainMenu
If Ev=$803 Then
Blah=Proceed("Do you really want to quit?")
If Blah=1 Then
End
Else
If Blah<>1 Then
Notify("Find out what you want next time")
(EndIf ; according to b32)
EndIf
EndIf
End Select
Until KeyDown(1)
End
End Function
StartERuP()
End
and with dots to show how an end-scope matches a begin-scope:
Function StartEruP()
.
. MainMenu=CreateWindow("Main Menu",300,300,400,500,main,15)
.
. Ev=WaitEvent()
. Es=EventSource()
.
. Repeat
. :
. : Select Es
. : .
. : . Case MainMenu
. : .
. : . If Ev=$803 Then
. : . :
. : . : Blah=Proceed("Do you really want to quit?")
. : . :
. : . : If Blah=1 Then
. : . : . End
. : . : Else
. : . : . If Blah<>1 Then
. : . : . : Notify("Find out what you want next time")
. : . : . (EndIf ; according to b32)
. : . : EndIf
. : . :
. : . EndIf
. : .
. : End Select
. :
. Until KeyDown(1)
.
. End
.
End Function
StartERuP()
End
Note that the Case command defines a scope, but since it doesn't have an 'End Case' command, I couldn't really draw dots here, or at least: it would look a bit weird compared to the rest. btw, while we're checking code anyway:
Function StartEruP()
MainMenu=CreateWindow("Main Menu",300,300,400,500,main,15)
Ev=WaitEvent()
Es=EventSource()
Repeat
Select Es
Case MainMenu
If Ev=$803 Then
If Proceed("Do you really want to quit?") Then End
Notify("Find out what you want next time")
EndIf
End Select
Until KeyDown(1)
End
End Function
Wiped a few lines. If your blah would've been 1 then it would've ended, if not it would notify, and you wouldn't need an 'Else' nor would you need to check on blah<>1 because it HAS to be <>1 in order to get at the line in the first place. (if it was 1, then the program would've ended!) It's like a factory where they make blue and red paint. At one point/junction one sends blue paint to hall 1 and red paint to hall 2, would it be practical to have other employees standing in halls 1 & 2 to check whether the colors are correctly chosen, after it was already correctly re-routed at that first junction? |
| ||
| I think I did that so it would be more readable and understandable for me; or some other reason. Anyway, thanks for the help guy's. Now I'm back to were I started the window will move but the function will not work. Test it out yourselves. Also, when I do all these ridiculous dot formations it says I need an 'End Function'. Here's my code, it doesn't work and it looks absurd.
Function StartEruP()
. MainMenu=CreateWindow("Main Menu",300,300,400,500,main,15)
. Ev=WaitEvent()
. Es=EventSource()
. Repeat
. . Select Es
. . . Case MainMenu
. . . If Ev=$803 Then
. . . . Blah=Proceed("Do you really want to quit?")
. . . . If Blah=1 Then
. . . . . End
. . . . . Else
. . . . . If Blah<>1 Then
. . . . . . Notify("Find out what you want next time")
. . . EndIf . .
. . . EndIf..... .
. . . EndIf............
. . End Select
. Until KeyDown(1)
End Function
StartERuP()
End
This only happened when I used indenting. |
| ||
| Of course those dots aren't meant for the actual source eh.., they're purely to visualize the idea of scopes here on the forum. |
| ||
| Oh... oops sorry take a look though, test it it doesn't work correctly- the function I mean. |
| ||
| Dunno, I dunno what your intentions are for this code, but I'd flush it. I'm also not much of a fan of using KeyDown(). Do you want one application window, or do you want a popup window within another application? For mainloops, why not use this:
window=CreateWindow("..",0,0,640,480)
Repeat
WaitEvent()
If EventID()=$803 And EventSource()=window ; if you only have one window in total, this eventsource check is not required
If Proceed("sure?") quit=1 Else Notify "oO"
EndIf
Until quit
End
|
| ||
| Shouldn't you be checking for events within the loop? |
| ||
| I'm trying to make a main menu for a program I'm making. The main menu will have buttons to press to acess the program. Once a button is pressed the main menu will disapear and the program will come up to show what ever the user wanted. For example, if the user pressed the 'create' button then it would loop to the create part of the application. I'm just not sure how to loop it. |
| ||
| well, as tonyg mentioned: you need to include the Waitevent within the loop in which you check for events. Your idea sounds like a popup btw. In your main source it would look like:
choice=RequestMenu()
Select choice
Case 0
DoThis
Case 1
DoThat
Case 2
DoM33p
Case 3
DoM00p
Case 4
GoGetAMacBurger
Case 5 ' quit
End
End Select
Function DoThis()
End Function
..etc.
This RequestMenu() function could even be a function with one arguement: a string containing all menu items, semi-colon seperated. |
| ||
Function StartEruP()
. MainMenu=CreateWindow("Main Menu",300,300,400,500,main,15)
. Ev=WaitEvent()
. Es=EventSource()
. Repeat
. . Select Es
. . . Case MainMenu
. . . If Ev=$803 Then
. . . . Blah=Proceed("Do you really want to quit?")
. . . . If Blah=1 Then
. . . . . End
. . . . . Else
. . . . . If Blah<>1 Then
. . . . . . Notify("Find out what you want next time")
. . . EndIf . .
. . . EndIf..... .
. . . EndIf............
. . End Select
. Until KeyDown(1)
End Function
StartERuP()
End
"EndIf" of "End If" (the same) closes only the last If block, so the lines you were drawing here aren't correct. If (test1) Then If (test2) Then If (test3) Then End If ;closes If (test3) End If ;closes If (test2) End If ;closes If (test1) Indention is only handy to remind yourself what If block the EndIf is closing. The PC doesn't respond to indention. |
| ||
| Thanks for all the help |