Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Goto: String

Author
Message
RoyalBlood
15
Years of Service
User Offline
Joined: 8th Apr 2009
Location: Stuck in this box!
Posted: 16th May 2009 05:46
What would the command be to make the program skip to whatever a string says. For example, if InputString$ was "13", I would want the program to jump to the label "13".

AMPConcepts.webs.com
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 16th May 2009 10:39
As far as I know, that's simply impossible. Programs aren't dynamic in nature and every response they can yield would have to be properly defined (a label once compiled points to a position in the memory used to store the program and most likely has no idea what text the compiler translated into that position).

So the only way to achieve this would be to have a switch statement (select in DBPro) (or multiple if's, but that just looks horrendous). And this is actually pretty good too; you can't have more labels entered than you have actual labels in your source code.

So, something like this:


Twisted Steel Software
17
Years of Service
User Offline
Joined: 21st May 2007
Location: Teh Interwebs
Posted: 10th Jun 2009 03:04
Please use gosub or functions...

Spaghetti belongs on your plate, not in your code.

Thanks,
Jim

Your signature has been erased by a mod - Please change your "moddy freak out" size to 600x240px. Thanks
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Jun 2009 06:29
Quote: "Spaghetti belongs on your plate, not in your code."


Amen!

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Jun 2009 20:32
Use of goto does not equate to spaghetti code - take a look at the Linux Kernel code sometime for examples of good goto use, and at various places in these forums for non-goto-spaghetti.

Spaghetti is produced by inexperienced or bad coders, not by the presence of goto statements.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Jun 2009 01:43
Quote: "Use of goto does not equate to spaghetti code - take a look at the Linux Kernel code sometime for examples of good goto use, and at various places in these forums for non-goto-spaghetti. Spaghetti is produced by inexperienced or bad coders, not by the presence of goto statements."


I agree but if there are too many GOTO's it's Spaghetti Code. I won't go nuts if I see in somebody's code a few GOTO statements. I just personally don't use GOTO or even GOSUB anymore.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Jun 2009 19:42
The only way to do what you want is to use functions and one of the lua plugins. This would allow you to specify a function name and call it. Having said that, if this is what you need to do I think you might need to look at your design again.

AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 13th Jun 2009 20:20 Edited at: 13th Jun 2009 20:20
Quote: "The only way to do what you want is to use functions and one of the lua plugins. This would allow you to specify a function name and call it."


Calling a function by using a string containing its name is also possible using IanM's function pointers, btw.

i like orange
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 14th Jun 2009 03:01 Edited at: 14th Jun 2009 03:04
Regarding goto and gosub statements, I wouldn't recommend instructing newcomers to NEVER use them. Newcomers can reduce the instances in which they use them in appropriate places as they develop their skills, but still get something done in the meantime by using them in the meantime, which keeps the interest alive.

Regarding the supposed orthodoxy of NEVER using these commands, I note that the FPSC engine which Lee (the author of DBP) recently released contains at least one GOTO and several hundred GOSUBS. Like it or not, that is far and away the most commercially successful DBP program whose sourcecode has been posted as yet.
Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 14th Jun 2009 07:54
subroutines are basically functions that neither take arguments nor return values. muscle memory tells me to type () when i want to access a subroutine so i use functions (plus it eliminates the need to type the "gosub" keyword at the beginning of the line rather than just mySubroutine() ). goto and gosub are completely different.

as for spaghetti code, even using functions you can get into that. have one function call another and have that one call many more, then you've got to trace the trail of instructions to find a bug. it's still a lot of work and it doesn't completely eliminate spaghetti code. personally i have no use for goto but it isn't magically evil. proper understanding of how program flow works and the guts to go about setting up bug-catching nets and error handling will result in a greater reduction in bugs and even in spaghetti code than the eradication of the goto keyword will ever yield.


Remember those old guys? They made epic renders, I think one of them was called DaVinci, and all they used was MS Paint. Sometimes it's just skill....
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 14th Jun 2009 08:11
Quote: "Regarding goto and gosub statements, I wouldn't recommend instructing newcomers to NEVER use them. Newcomers can reduce the instances in which they use them in appropriate places as they develop their skills, but still get something done in the meantime by using them in the meantime, which keeps the interest alive."


I think newbies should use every command at least once. For me it's a transition... use GOTO for a while when you're first learning programming, then use GOSUB when you're a little better, and finally graduate to functions only.

I have a lot of fond memories programming using GOTO but I think it should be left in the past once we discover better means. That's why in my signature the light blue colored letters spell AGO. It does stand for Anti-Goto Order but as a word AGO means in the past... where GOTO should be for all non-newbies.

Login to post a reply

Server time is: 2024-09-28 08:30:22
Your offset time is: 2024-09-28 08:30:22