开发者

How make use of a coded Access database once

开发者 https://www.devze.com 2023-02-16 02:31 出处:网络
how can I improve coding structure, when there are a number of subs, functions using the same number of lines each time to make,open and close a connection to an Access database?

how can I improve coding structure, when there are a number of subs, functions using the same number of lines each time to make,open and close a connection to an Access database?

Can the lines of code to make and add a connection to the Access database be enclosed in one function and then called through function x () each time it needs to be used?

Any advice on this would be greatly appreciated, thank you

can anyone also advise on other good coding structures or websites/tutorials that I could开发者_StackOverflow社区 use? thank you


Sure you can and I actually advise you to do it.

Some simple yet powerfull advice on coding

  • If you reuse the same lines of code at multiple places, then do put them in a sub(or function) and call the sub when needed.

  • If some lines of codes are really similar in a lot of places and differs by small things (a number for example), then do put them in a sub(or function) with arguments and call the sub when needed.

  • A sub(or function) should never have more than a few lines of codes. There are no real limit, but if you can't see the whole function in one page, then it is most likely too long.

  • A sub (or function) should usually do only one thing. If your sub perform multiple tasks, it will be hard to reuse and will most likely span on more than one page.

  • You might have heard this a lot before, but use meaningfull variable and function names! var1,i,x,textbox1 and the others are only goods for iterating (for i = 0 to 10).

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消