Page 1 of 1
Few questions
Posted: Thu Sep 08, 2005 7:18 am
by Scott
Alright, so I got handed a visual basic program which I was meant to retune and basically make it a better program.
The problem is, there are some things about vb I don\'t understand.
Firstly, when should you use a Sub and when should you use a Function?
Oh, what does the $ do after a function such as Mid$?
And what does the % do when placed after a variable?
These are probably really simple, but google has failed me <img src=\'
http://www.killanet.net/forum3/public/s ... #>/cry.gif\' class=\'bbc_emoticon\' alt=\':(\' /> so any help would be appreciated.
Few questions
Posted: Thu Sep 08, 2005 8:44 pm
by Josh
[quote name=\'Vulture\']Firstly, when should you use a Sub and when should you use a Function?[/quote]Sub is like for built in things for controls and the form... You really don\'t have to worry about these because VB will put them in for you automatically
[quote name=\'Vulture\']Oh, what does the $ do after a function such as Mid$?[/quote]
Hmmm, I don\'t think it does anything. I know Chr(x) and Chr$(x) are exactly the same... So I guess it\'s just a programmers preferance.
[quote name=\'Vulture\']And what does the % do when placed after a variable?[/quote]
*hands this question to someone else* I don\'t know either, sorry.
Few questions
Posted: Thu Sep 08, 2005 8:53 pm
by Scott
Found out the answer to the last one: Its a type declaration, the % is specifically for integer, $ is string, & long...etc
For the first question, I\'ve heard that a Function should be used when a return value is needed. If not, use a Sub.
None the wiser about 2, but thanks for the help Dren <img src=\'
http://www.killanet.net/forum3/public/s ... /smile.gif\' class=\'bbc_emoticon\' alt=\':)\' />
Few questions
Posted: Thu Sep 08, 2005 10:37 pm
by Alexander
Firstly, when should you use a Sub and when should you use a Function?
A sub should be used when you want to declare changes to the environment, like form changes etc, basically on event stuff mainly.
subs are not always declared though, you can setup public subs of your own to run a series of functions within forms or modules eg...
Public Sub DoThisNow() would create a sub avaliable to ALL forms you can call using Call DoThisNow, its useful to stop having to repeat yourself all the time for multiple subs, lol
a function is indeed when you want to have something returned, a function has certain elements like (Text as string, Text2 as string)
then when you call the function it asks for the two variables and it uses those variables or settings to return the code or result.
Oh, what does the $ do after a function such as Mid$?
it doesnt do much but ive been told that it does speed up the process, not entirely sure how it works but if it makes it faster i say go with it, lol
Few questions
Posted: Thu Sep 08, 2005 11:05 pm
by Josh
No problemo Vulture <img src=\'
http://www.killanet.net/forum3/public/s ... iggrin.gif\' class=\'bbc_emoticon\' alt=\':D\' />
Few questions
Posted: Tue Aug 29, 2006 3:22 am
by Kobra
mid() vs mid$()? i think you put the $ in so vb knows it should return a string.. it would be faster because vb wouldnt have to check to see if its an integer, string, etc. then again, im not very smart and 90% of the things i say are wrong <img src=\'
http://www.killanet.net/forum3/public/s ... iggrin.gif\' class=\'bbc_emoticon\' alt=\':D\' />
Few questions
Posted: Tue Aug 29, 2006 11:27 am
by Josh
Bumping a year old thread, kobra? *slaps you* <img src=\'
http://www.killanet.net/forum3/public/s ... >/blum.gif\' class=\'bbc_emoticon\' alt=\':P\' />