Few questions

Snippets, Projects and Assistance

Moderators: Moderator, Global Moderator

Post Reply
Scott
Administrator
Administrator
Posts: 0
Joined: Sun Apr 25, 2004 1:08 pm

Few questions

Post 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.
Josh
Newbie
Newbie
Posts: 0
Joined: Fri Jun 04, 2004 2:54 pm

Few questions

Post by Josh »

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

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
Scott
Administrator
Administrator
Posts: 0
Joined: Sun Apr 25, 2004 1:08 pm

Few questions

Post 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=\':)\' />
Alexander
Newbie
Newbie
Posts: 0
Joined: Wed Jul 07, 2004 8:33 am

Few questions

Post 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
Josh
Newbie
Newbie
Posts: 0
Joined: Fri Jun 04, 2004 2:54 pm

Few questions

Post by Josh »

No problemo Vulture <img src=\'http://www.killanet.net/forum3/public/s ... iggrin.gif\' class=\'bbc_emoticon\' alt=\':D\' />
[align=center]

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
Kobra
Newbie
Newbie
Posts: 0
Joined: Mon May 31, 2004 4:46 pm

Few questions

Post by Kobra »

mid() vs mid&#036;()? i think you put the &#036; 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\' />
Image
Josh
Newbie
Newbie
Posts: 0
Joined: Fri Jun 04, 2004 2:54 pm

Few questions

Post 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\' />
[align=center]

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
Post Reply

Return to “Visual Basic”