# VBForums UtilityBank > UtilityBank - Tutorials >  Useful Beginner Tips

## BrendanDavis

I see a lot of beginners posting in these forums, or maybe even folks like me who are former programmers who are getting back into the swing of things after a long break and need some helpful reminders of the little, simple things. So I decided to create a short topic of helpful tips that you can use to make your life easier when creating an application, be it a small private app or a large, widely-used app. So here are some simple, basic timesavers:


*Using modules to make things easy!*
If you're ever going to use a simple proceedure or string/variable multiple times in your app, it's a good idea to declare it in a module. Things like a custom app name that is different from the app name you set in your app's properties, build number, app status(beta, alpha, etc.), app author, etc. I use some things that are easy for me to remember and easy to change if I need to. For example, in a module's declarations:


VB Code:
Public Const prjName = "My Custom Application Title"
Public Const prjBuild = 1.001
Public Const prjStatus = "Beta"
Public Const prjAuthor = "Brendan M. Davis"
Public Const prjCompany = "FireFly Media, LLC."

This makes it easy for you to change things quickly without having to go through your entire app looking for it. For example, if you used:


VB Code:
MsgBox "A message box message goes here", vbOkOnly, prjName

...you could have every message box display your application name the same way. Thus, if you wanted to change it sometime down the road, it would be as simple as changing the Public Const prjName = "Something Different"

This is also EXTREMELY useful for things that VB does not have a place for you to enter. For example, your form background colors. Want to change them without having to go through each one individually? Or, maybe you want to let the user change it themself and save it that way. Creating a function for it, and then using that in the Form_Load area will make it easy for you (and the user, if other people will be using your app) to change it with 1 function call. For example:


VB Code:
Public Function frmBGColor()
frmBGColor = 'Whatever color you choose, or create a LoadSetting to make it customized
End Function


*Some general rules of thumb..*

When you're using a custom set string, integer, label, etc., it's always good to declare it as such before proceeding with any code that uses it. For example, if you want to create a string and set a specific property to it, the WRONG way to use it would be:



VB Code:
Public Sub Form_Load
 myCustomString = "Hello, UserName!"
 Me.Caption = Mid$(myCustomString, 8, Len(myCustomString)) 'To get the username
 End Sub

You didn't declare the custom string as a string, which is bad practice. The best way to use it would be something like:



VB Code:
Public Sub Form_Load
 Dim myCustomString As String 'This set it to a string
 myCustomString = "Hello, UserName!"
 Me.Caption = Mid$(myCustomString, 8, Len(myCustomString)) 'To get the username
 End Sub

It's a small addition, but it will ensure your app runs the best that it can.


*Don't get module crazy!*
Modules are great timesavers, and they're key to making a great app if you know how to use them correctly. But using them TOO much is a bad thing. Creating a function that you're going to use in several different areas, that happens to display/not display MsgBox's is not good. Trust me, it is for some things... not for most. If you create a function that handles all the error messages and dialoge boxes for you, you may come accross some trouble later on when you want to use that function in a different way than what you coded it for. The result? You'll have to either 1) go back and change the fucntion, and thus change the original useage of the function(i.e. headache city), or 2) you'll have to write another similar function with/without the msg handling that you want/don't want. The way around that is to create a Boolean type for the function, something like:


VB Code:
Private Function CheckMyList(lItem as String, lList as ListBox, Optional showMsgs as Boolean = False)
 'Function code here
 End Function

This is ok sometimes, if you're crafty in how you use said function. But for something that is going to get a lot of diverse use, you'd want to keep it simple and leave the error/msgbox handling to the button/form you're implimenting it in.





Just some basic tips that I've picked up that I knew helped me out when I first started out, as well as now as I'm getting back into programming again. There are a lot of extremely smart, talented programmers on this site and I'm sure they have some even more helpful tips and suggestions (not to mention corrections to some of the things I may have goofed on in this topic). I would hope this topic would encourage some more helpful "getting started" tips for those who are struggling to get off the ground   :Wink:   :wave:

----------


## leinad31

Re: Some general rules of thumb..

Include using Option Explicit

----------


## dsuraj

Thanks dude . nice and useful info

----------


## kevin hash

This is really useful for me, I always make mistakes like that in my program and that takes a lot of time when I want to change a color or something like that.

----------


## Hlinzi

Very Nice.

----------

