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 / My First (Completed) Program

Author
Message
Dexter_
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location:
Posted: 15th Jan 2007 04:13
Thx to everyone who helped me with this calculator
I don't suck anymore



Please, tips/comments?
Mr X
19
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 15th Jan 2007 10:11
Shouldn't this be in the program announsements board? Anyway, I'll take a look at it later.
Dexter_
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location:
Posted: 15th Jan 2007 10:56
whats the announcement board lol ^^

sorry i just posted it here cuz i asked my questions here too
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Jan 2007 11:31
You really shouldn't use "goto" to exit the functions. When the function ends it goes to the line after the function was called.

Notice how the functions still work without "goto" in them:
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 15th Jan 2007 12:44 Edited at: 15th Jan 2007 12:52
Quote: "You really shouldn't use "goto" to exit the functions."


Agreed. In fact ... Never use goto to move to a place outside of the current function, gosub, or any type of loop you are in. It will overload the stack eventually and lock something up.

[edit] You also shouldn't be using it to exit the loop for the clear button. Do something with the exit command and a flag to be set like this



[edit2] And always put an end command between your functions and your main loop so the functions don't run when you press the escape key.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Jan 2007 14:02
Quote: "I don't suck anymore"


Lol! You can only say that when you can write programs which don't use Goto at all!

TDK_Man

Dexter_
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location:
Posted: 15th Jan 2007 20:51
thx guys!!!!!!!!!
im gonna change all those gotos and exits in the functions now
thanks for reviewing it

tdk man, you should have seen what ive done before, its garbage lol
Mr X
19
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 15th Jan 2007 20:54
Besides the coding misstakes, I like the look of it. Nice.
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 15th Jan 2007 21:05
Quote: "Lol! You can only say that when you can write programs which don't use Goto at all!
"

That's rubbish! There are times when it is perfectly acceptable to use gotos nowadays.

@Dexter_ - That is not bad at all! I'm really quite impressed. It is a very good start to your programming life!

Dexter_
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location:
Posted: 15th Jan 2007 21:13
ok, sorry for double posting, if i could see my last post i'd just edit this into it.... heres the new code:



A Few Questions:

1.Whats a flag?

2.TDK_Man said I shouldn't use 'goto' but your version still uses it. Is it ok there? How else would I go back to Start?

3.What's the point of the 'end' command in there, wont it never happen/get executed??

4.I made the function resturn a value so you could set it = to 1...is this right?

5.Did I use arrays right...how else could I change the variables globally in functions...should I have used gosubs?
jasonhtml
20
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 15th Jan 2007 23:24
1. a flag is basically just a variable that tells the program to do something. for example: if the flag = 1 then execute code X, if the flag = 0, dont execute code X

2.goto is fine in that instance. at least in my opinion...

3. you dont really need the end command at the end of the loop because it never will get executed. ive never done that before, and probably never will unless there is some code that causes the loop to exit.

4. im not sure what ur asking

5. by just glancing at ur code, it looks like u used them right... but i did notice that u aren't using numbers#(3) through numbers#(6), so why dont u just dim numbers#(2) instead? also, keep in mind, that when you dim an array, you can also use numbers#(0) if you want


forum.thegamecreators.com/?m=forum_view&t=78971&b=8&p=0
forum.thegamecreators.com/?m=forum_view&t=91115&b=32
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 16th Jan 2007 01:17 Edited at: 16th Jan 2007 01:21
Oops... I should of paid more attention.

Quote: "1.Whats a flag?"


I call them switches but it's basically the same thing as Jasonhtml explained.

Quote: "2.TDK_Man said I shouldn't use 'goto' but your version still uses it. Is it ok there? How else would I go back to Start?"


You don't have to have "Start" at all. All you need to do is reset the arrays. And there's no need to redraw the whole screen just the answer box.

Quote: "3.What's the point of the 'end' command in there, wont it never happen/get executed??"


In Pro if you don't have "end" before any functions it'll show an error if it hits a function without calling the function. In Classic it will error out but not show anything. "End" just assures that the user won't see an error regardless and is a proper way to end the program (rather than producing an error). Adding "end" after a loop without an "exit" although not needed is a "just in case something horrible happens" situation.

Quote: "4.I made the function resturn a value so you could set it = to 1...is this right?"


Yes. It works great.

Quote: "5.Did I use arrays right...how else could I change the variables globally in functions...should I have used gosubs?"


If your using Pro you don't have to make that first array since you only use one element you can just make a variable global by using "global TextSpacing". "Gosub" wouldn't work too well in there. "Gosubs" are used like functions... they run then "return" back to the line under the "gosub".

It's best to just remove the last "goto":

Dexter_
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location:
Posted: 16th Jan 2007 02:00
whoa that helps a TON thx jason and thx grog!!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 16th Jan 2007 15:19
Quote: "That's rubbish! There are times when it is perfectly acceptable to use gotos nowadays."


Such as?...

The use of Goto totally invalidates the use of a procedural programming language. If you don't know how to write a program that avoids the Goto command then you don't really know what you are doing!

TDK_Man

Soroki
18
Years of Service
User Offline
Joined: 26th Jan 2006
Location: United States
Posted: 16th Jan 2007 19:54
What about a using function instead of a goto? Just wondering. If I am wrong don't call me a noob. It is only a suggestion. Functions combined with flags would probably work. I prefer to use gosub instead of goto, but usually that's because my codes don't need to jump to a line and stay there.

Dexter_
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location:
Posted: 17th Jan 2007 05:53
ok, sounds like tdk is right, but what do you think of gosubs? :p

<img src='http://www.geocities.com/doodledexterbob/MasterofMedit.jpg' border='0' alt='user posted image'>
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 17th Jan 2007 06:00
When starting out you will explore goto and gosub, they are ok for very small programs but can lead into headaches with larger projects.

When you want to create a lot more efficient methods to achieve a result you will create functions.
When you start to create functions as well there is a benefit to all programs you create afterwards.

Imagine I wrote a function that displays the score in a neat bubble with shiny bits and animated stuff etc.. I just copy those functions to my next project and tweak them accordingly to suit the next project.

Functions as you know is like grouping commands into another command while having the option of returning a result or not.

It saves a lot of repetitive coding and opens doors not available to using goto or gosub.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 17th Jan 2007 18:46
Quote: "what do you think of gosubs"


Functions and Procedures (Gosubs) are essentially the same thing, with subtle differences. There are plenty of tutorials which go into depth on what they are, so it's pointless doing so here.

In a nutshell, functions and procedures get you away from linear programming that you get if you only use Goto.

Using Funcs and procs is like a dog when you throw a stick - your program toddles off and executes your code, then like the dog fetching a stick, comes back and says 'right - now what'? This makes finding bugs so much easier as you can trace the program.

You can call subroutines from within subroutines and DB keeps track of where each jump should return to by using something called the 'stack'. That's why it's vitally important to not use Goto to exit from a function or procedure or the return data isn't taken off the stack and it can get corrupted.

With the Gosub or Function debate, there are pros and cons to using both so in my opinion, neither is better than the other - just use which is best for you.

I would say that functions are the more advanced of the two, but off the top of my head I can't think of any task you could achieve with a function that you couldn't with a Gosub.

TDK_Man

Dexter_
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location:
Posted: 18th Jan 2007 05:50
thx all

<img src='http://www.geocities.com/doodledexterbob/MasterofMedit.jpg' border='0' alt='user posted image'>
Firewood
19
Years of Service
User Offline
Joined: 24th Jul 2005
Location:
Posted: 22nd Jan 2007 22:46
I hope i dont swing up this disccusion to mutch. But i am a PLC programmer. And DBPro programming is a hobby for me. What i did learn about programmaning is: avoid using GOTO in your program. Its not forbidden but like TDK says "If your project gets to big. You are almost not be able to find a bug in your program."

To use Gosub is to execute a piece of program thats runs more than ones. But stil use a lot of data from the main program to proces it. And yes you can make a gosub doing the same thing as a function.

A function is creating a total new command in you program. Therefor all the variables who a not made global and reuse in the function get his own local variables. A function is not working with all the data that the main program use.
So when you use a function the change to have a unwanted crossing of variables is small. To go from here a function is mutch more liking for reusing it in another program.

So on the other hand a gosub reusing is more of a danger. Crossing variables is greater. But this does not means that using of gosub is forbidden. Gosub is very good for making repetetive lines of code in the main program.

e.g. on a rubroutine:
passing a string and telling it to extract a number of letters from a position in the string. When you want to reuse this subroutine you have to make your main program to reconize the string sending the string and to receving the string.

In a function. The passing of a string is not set to a special string. The string wil be recieved by the function and in the function it have his own string. And because of the function is being able to returning something, you can make u your own string variable in the main program to recieving the string.

Like i said it befor. A function is more like a extra command in you program. you can use it again and again.

Never say a question is stupid. Questions not ask are stupid.

Login to post a reply

Server time is: 2024-11-26 21:39:04
Your offset time is: 2024-11-26 21:39:04