Log in

View Full Version : Visual Basics



nikomou
12-05-2007, 06:00 PM
Hey

I'm trying to reduce the amount of duplicate code in my program. I have a global module with the code:
Public Sub workDiscount()
'Discounts
If Form1.radStu.Checked = True Then
dblDiscount = ((screencost / 100) * 15)
End If

If Form1.radOAP.Checked = True Then
dblDiscount = ((screencost / 100) * 20)
End If

If Form1.radNoDiscount.Checked = True Then
dblDiscount = 0
End If

and to call it in the main form, i just put use
workDiscount(). this works great if i only call it once! put i would need to use it a few times within the program!

THanks for your help/

Twey
12-05-2007, 10:26 PM
I'm trying to reduce the amount of duplicate code in my program.Trying to refactor VB is like trying to fit a truck in a trash can, to use a rather American analogy. It just won't work, the language is too inflexible to allow itself to be refactored into a sensible shape.

djr33
12-05-2007, 10:52 PM
Trying to refactor VB is like trying to fit a truck in a trash can,You mean pickup truck under a table? :p
Sorry, couldn't resist. And, hey, it's a better visual.

Twey
12-05-2007, 11:58 PM
Doesn't have quite the same ring to it :p Interesting that we both used truck analogies at more-or-less the same time though :)

djr33
12-06-2007, 02:08 AM
Oh, but you can visualize trying to place trucks under a table (complete with place settings and candles is most fun). The truck into a trash can just is a dead end thought :p