Below is a snippet of some VB code:
'Begin Sandbags and Walls
Private Sub PictureBox130_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox130.MouseEnter, _
PictureBox81.MouseEnter, PictureBox114.MouseEnter, PictureBox82.MouseEnter, PictureBox113.MouseEnter, PictureBox83.MouseEnter, _
PictureBox110.MouseEnter, PictureBox111.MouseEnter, PictureBox109.MouseEnter, PictureBox80.MouseEnter, PictureBox120.MouseEnter, _
PictureBox67.MouseEnter, PictureBox68.MouseEnter, PictureBox66.MouseEnter, PictureBox76.MouseEnter, PictureBox99.MouseEnter, _
PictureBox79.MouseEnter, PictureBox112.MouseEnter, PictureBox84, PictureBox65.MouseEnter, PictureBox60.MouseEnter, PictureBox62.MouseEnter, _
PictureBox59.MouseEnter, PictureBox63.MouseEnter, PictureBox61.MouseEnter, PictureBox64.MouseEnter, PictureBox85.MouseEnter, _
PictureBox129.MouseEnter, PictureBox100.MouseEnter, PictureBox86.MouseEnter, PictureBox101.MouseEnter, PictureBox87.MouseEnter, _
PictureBox121.MouseEnter, PictureBox88.MouseEnter, PictureBox122.MouseEnter, PictureBox126.MouseEnter, PictureBox124.MouseEnter, _
PictureBox125, PictureBox123.MouseEnter, PictureBox131.MouseEnter, PictureBox98.MouseEnter, PictureBox78.MouseEnter, PictureBox128.MouseEnter, _
PictureBox77.MouseEnter, PictureBox54.MouseEnter, PictureBox57.MouseEnter, PictureBox55.MouseEnter, PictureBox56.MouseEnter, _
PictureBox51.MouseEnter, PictureBox52.MouseEnter, PictureBox50.MouseEnter, PictureBox58.MouseEnter, PictureBox49.MouseEnter, _
PictureBox107.MouseEnter, PictureBox108.MouseEnter, PictureBox105.MouseEnter, PictureBox106.MouseEnter, PictureBox104.MouseEnter, _
PictureBox70.MouseEnter, PictureBox103.MouseEnter, PictureBox102.MouseEnter, PictureBox72.MouseEnter, PictureBox75.MouseEnter, _
PictureBox73.MouseEnter, PictureBox127.MouseEnter, PictureBox96.MouseEnter, PictureBox74.MouseEnter, PictureBox71.MouseEnter, _
PictureBox69.MouseEnter, PictureBox53.MouseEnter, PictureBox91.MouseEnter, PictureBox115.MouseEnter, PictureBox90.MouseEnter, _
PictureBox116.MouseEnter, PictureBox92.MouseEnter, PictureBox117.MouseEnter, PictureBox93.MouseEnter, PictureBox94.MouseEnter, _
PictureBox95.MouseEnter, PictureBox97.MouseEnter, PictureBox28.MouseEnter
MsgBox("You left the safety of the trench and was shot in the head")
Me.Close()
Game_Over.Show()
End Sub
Now I know you guys likely use DB but it all simular to C and the C family so it should make sense. This orginaly was over 1,000 lines of code. so what does it look like un optimized? Well Im not going to post a thousand lines but here is what a single variable looks like:
Private Sub PictureBox130_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox130.MouseEnter
Imagine repeting this 1,000 plus times. Yeah that would suck not to mention it would slow down your performance. What I did above was simple. I took a collection of variables that all had the same outcome basicly and grouped them as one basicly. You should be able to apply this same concept to most if not all programming langs. This will optimize your code and give it a cleaner appearence.
Next thing to consider or question you may ask. Why do I need to clean it if Im the only one viewing the source? Good question, well at some point you may need to read over it for a refference. The best case is someone wants to buy the source code. If it looks like crap, may give a unprofesional appearence to you and your company. However, their is a except tion to this rule. It is more imporant for a code to work/function properly then just look pretty.
Do optimize were you can
Do clean your code were you can
Do comment your code correctly
Do not over comment your code
Do not optimize to the point the code no longer works
Do not make unused variables
These are some basic common sense Do's and Dont's to follow when cuting code or optimizing it. Remember a line of code can be written at lest three different ways in most cases. However, try to use to most trim and fit version when writting. If you do not know the best method, use the one you know. It may not be the best but if it works, thats all that counts. As you progress, you can go back and trim code. If your not "pro" yet its ok. Getting pratice in is far more important then worrying about making flawless code.
I hope this code tip helps.