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
Moderators: Moderator, Global Moderator
Few questions
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 automaticallyFirstly, when should you use a Sub and when should you use a Function?
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.Oh, what does the $ do after a function such as Mid$?
*hands this question to someone else* I don\'t know either, sorry.And what does the % do when placed after a variable?
[align=center]

“If you stop learning, you stop living.” ~Tami Quiring
“It's the rare man who understands the value of a single perfect rose.”
[/align]

“If you stop learning, you stop living.” ~Tami Quiring
“It's the rare man who understands the value of a single perfect rose.”
[/align]
Few questions
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=\':)\' />
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
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
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
No problemo Vulture <img src=\'http://www.killanet.net/forum3/public/s ... iggrin.gif\' class=\'bbc_emoticon\' alt=\':D\' />
[align=center]

“If you stop learning, you stop living.” ~Tami Quiring
“It's the rare man who understands the value of a single perfect rose.”
[/align]

“If you stop learning, you stop living.” ~Tami Quiring
“It's the rare man who understands the value of a single perfect rose.”
[/align]
Few questions
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
Bumping a year old thread, kobra? *slaps you* <img src=\'http://www.killanet.net/forum3/public/s ... >/blum.gif\' class=\'bbc_emoticon\' alt=\':P\' />
[align=center]

“If you stop learning, you stop living.” ~Tami Quiring
“It's the rare man who understands the value of a single perfect rose.”
[/align]

“If you stop learning, you stop living.” ~Tami Quiring
“It's the rare man who understands the value of a single perfect rose.”
[/align]

