IonicWind Software

IWBasic => General Questions => Topic started by: Andy on April 27, 2011, 12:42:39 AM

Title: Labels in IW2
Post by: Andy on April 27, 2011, 12:42:39 AM
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.
Title: Re: Labels in IW2
Post by: LarryMc on April 27, 2011, 06:14:52 AM
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
Title: Re: Labels in IW2
Post by: Andy 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.
Title: Re: Labels in IW2
Post by: LarryMc on April 27, 2011, 06:52:03 AM
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
Title: Re: Labels in IW2
Post by: sapero on April 27, 2011, 07:05:17 AM
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.
Title: Re: Labels in IW2
Post by: billhsln on April 27, 2011, 08:12:08 AM
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
Title: Re: Labels in IW2
Post by: Ficko on April 27, 2011, 09:47:38 AM
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.


Title: Re: Labels in IW2
Post by: Andy on April 28, 2011, 05:24:15 AM
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.
Title: Re: Labels in IW2
Post by: sapero on April 28, 2011, 05:38:00 AM
.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
Title: Re: Labels in IW2
Post by: LarryMc on April 28, 2011, 05:40:05 AM
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
Title: Re: Labels in IW2
Post by: LarryMc on April 28, 2011, 05:41:59 AM
Sapero,

Where did the WITH/ENDWITH come from?

LarryMc
Title: Re: Labels in IW2
Post by: sapero on April 28, 2011, 05:58:37 AM
From VB ;D This is an undocumented feature for the next major release.
Title: Re: Labels in IW2
Post by: Andy on April 28, 2011, 09:41:17 PM
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.
Title: Re: Labels in IW2
Post by: LarryMc on April 28, 2011, 09:49:26 PM
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