May 31, 2024, 10:50:18 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Labels in IW2

Started by Andy, April 27, 2011, 12:42:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

Just downloaded IW2, impressed with the changes :) BUT I need help with LABELS  :'(

I understand a label is now local to a sub routine but I do need sometimes to jump out of a sub routine or jump to a label inside a sub routine.

I know it's not classed a 'good' programming but it is handy at times.

can anyone give me a simple example (including any defines etc) of how to jump out / to a label inside / out of a sub routine

e.g.

OPENCONSOLE
LABEL homepage
GOTO nextpage
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END

SUB something
GOTO homepage
LABEL nextpage
RETURN
ENDSUB

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

you can't.
since LABELS are local to a subroutine they don't exist outside the subroutine
and, if you can use the same label in multiple subroutines how would you know which label you were jumping to.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Hi Larry,

OK, you could in EB but i will just have to try and re-work one of my programs.

But thanks for the reply,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Quote from: andy1966 on April 27, 2011, 06:29:48 AM
Hi Larry,

OK, you could in EB but i will just have to try and re-work one of my programs.

But thanks for the reply,
Andy.

Yes you could in EB because labels were global.
You can't in IWB2 because they are local.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

It is still possible to do from assembly level.
Create a label: $emit labelName:
Jump to it: goto labelName, or $emit jmp labelName.

Use "jmp near" modifier if you get distance errors - short jump out of range.

billhsln

I would think that for quick and dirty, instead of a call to sub xxxx, just make the xxxx a label and go to it when you need to start at the beginning.  Then it is no longer a subroutine, just bad code.  If you need to return to multiple places, keep track of where you want to go back to in a variable and then use that variable to determine where to return to.

Bill
When all else fails, get a bigger hammer.

Ficko

April 27, 2011, 09:47:38 AM #6 Last Edit: April 27, 2011, 09:51:22 AM by Ficko
Quotenot classed a 'good' programming

It is not just bad programming produces technically incorrect code.
This is the main reason not good to have such thing in a high level compiled language.

If a sub look like this:

push ebp
mov ebp,esp
push esi,edi,….
.
Jmp somewhereOut
…
pop …,edi,esi
leave
ret


you can see if you "jmp somewhereOut" the stack will be screwed "ebp" have to be set back to the value before the call and any register saved have to be restored.



Andy

Hi guys,

Yes I completely agree, it was just a question that had me curious - but can you tell me why (on a different subject) why

                        fvurl = GETCONTROLTEXT (urldlg,2) is ok in EB

                        But

                        fvurl = GETCONTROLTEXT (.urldlg,2) in IW is not ( returns an error )

where fvurl is a string

Was trying to pass the current url to a string but I get a compile error.

Sorry if this should have been a new question.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

sapero

.urldlg must be inside WITH block, and urldlg must be a member of a structure or class:

TYPE MYWINDOW
WINDOW urldlg
ENDTYPE

...

MYWINDOW w

' usage: w.urldlg

WITH w
' usage: w.urldlg  or  .urldlg
fvurl = GETCONTROLTEXT(.urldlg,2) ' notice: "w" is missing
...
ENDWITH

LarryMc

In the line that generates the error you have this:
Quote(.urldlg,2)
Your dialog name is starting with a '.'which is an illegal variable.
You didn't say but that line should generate an 'undefined variable' error.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Sapero,

Where did the WITH/ENDWITH come from?

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

From VB ;D This is an undocumented feature for the next major release.

Andy

Thanks Larry / sapero,

Larry, I was looking at the browser_test2 example, in there the window names seemed to be prefixed with the "." so I assumed all I had to do was to add the "." to the example I quoted (seemed logical to me).

Anyway, will try the code in a block as sapero mentioned.

Thanks to you both again,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Quote from: andy1966 on April 28, 2011, 09:41:17 PM
Larry, I was looking at the browser_test2 example, in there the window names seemed to be prefixed with the "." so I assumed all I had to do was to add the "." to the example I quoted (seemed logical to me).

You ran in to an example of what can happen when stuff is added randomly without any version control and documentation.  But that is my personal opinion.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library