PDA

View Full Version : VBA select case HELP



HelloWorld
02-26-2012, 11:12 AM
I have 5 text boxes. There names are:
DiagnosisFee
XRayFee
LabTestFee
IndoorInjectionFee
Bedcharge

I needed to add the values in these text boxes by clicking on a button called Calculate and display it in a textbox called FTotalFees. This part works well. Here is my code:
Private Sub Calculate_Click()
Dim IntNum1 As Integer
Dim IntNum2 As Integer
Dim IntNum3 As Integer
Dim IntNum4 As Integer
Dim IntNum5 As Integer
Dim Total As Integer

IntNum1 = DiagnosisFee
IntNum2 = XRayFee
IntNum3 = LabTestFee
IntNum4 = IndoorInjectionFee
IntNum5 = Bedcharge

Total = IntNum1 + IntNum2 + IntNum3 + IntNum4 + IntNum5

FTotalFees = Total

End Sub

Now i need to convert the value displayed in the textbox called FTotalFees to words. for example 1000 = thousand or 100 = hundred. I know what the totals will because the user can select the numbers to add through a combo box. They cannot add any value they want.
So i made another textbox called WTotalFees and a button called ConvertWord. When i click on it i should be able to get the number in words. Here is my coding but i do not know if i have written it properly:
Private Sub ConvertWord_Click()
Dim Word As String
Dim Total As Integer

FTotalFees = Total
WTotalFees = Word

Select Case Word

Case Total = 5000
WTotalFees = "Five Thousand"

Case Total = 10000
WTotalFees = "Ten Thousand"

Case Total = 15000
WTotalFees = "Fifteen Thousand"

End Select

End Sub

Please try to elaborate your answer because i'm only a beginner.
Thanks a lot!!!

HiTechCoach
02-27-2012, 07:41 AM
Welcome to the forum!

See: Convert Currency ($500) into words (Five Hundred Dollars) (http://www.hitechcoach.com/index.php?view=weblink&catid=28%3Aaccess-programming&id=537%3Aconvert-currency-500-into-words-five-hundred-dollars&option=com_weblinks&Itemid=23)

HiTechCoach
02-27-2012, 07:48 AM
I have 5 text boxes. There names are:
DiagnosisFee
XRayFee
LabTestFee
IndoorInjectionFee
Bedcharge

...

Please try to elaborate your answer because i'm only a beginner.


Having five text boxes like this is a red flag to normalization issues with your database table design. What you have is known as repeating fields (fees). A much better design would be to have each fess on a separate record in a sub/child tables for fees. This also makes getting the total very simple becuse you can use Sum().

See: Database Normalization Resources (http://www.hitechcoach.com/index.php?option=com_content&view=article&id=34:database-normalization-resources&catid=53:designing)