Click to See Complete Forum and Search --> : Whats amt & temp


Juan Amore
October 19th, 2001, 11:02 AM
Does anyone know how to use these "amt" "temp"
commands.I have a program which calculates a salesman's commission + basepay.
After inputing several times I'm suppose use another Menu button;ie summary and get the totals
from these compounding inputs. Under my form section;I have these "amt" "temp" variables set as
Private Sub Form_Load()
'Set 3 temp files used for total summary
Static SalesNum As String
Static CommNum As String
Static TotalNum As String

Static AmtSalesTemp As Currency
Static AmtCommTemp As Currency
Static AmtTotalTemp As Currency

Static AmtSales As Currency
Static AmtComm As Currency
Static AmtTotal As Currency

'Set 3 constants

Const rate = 0.15
Const base = 250
Const quota = 999


End Sub
Then In my Menu Button section for me to display this information and for it to add up I have;
Private Sub mnuSummary_Click()
'Set 3 constants

Const rate = 0.15
Const base = 250
Const quota = 999

If IsNumeric(txt2.Text) Then

AmtSalesTemp = txt2.Text
Else
MsgBox "No Data to Summarize", vbOKOnly, "Commission"
End If


If AmtSalesTemp >= quota Then

AmtCommTemp = AmtSalesTemp * rate
AmtTotalTemp = AmtCommTemp + base

SalesNum = AmtSalesTemp + AmtSales
CommNum = AmtCommTemp + AmtComm
TotalNum = AmtTotalTemp + AmtTotal

MsgBox "Total Pay = $" & Format$(TotalNum, ".00") & vbCrLf & "Total Commission=$" & Format$(CommNum, ".00") & vbCrLf & "Total Sales=$" & Format$(SalesNum, ".00"), vbOKOnly, "Summary"

Else

MsgBox "Total Pay = $" & Format$(base, ".00") & vbCrLf & "Total Commission=$" & Format$(CommNum, ".00") & vbCrLf & "Total Sales=$" & Format$(SalesNum, ".00"), vbOKOnly, "Summary"

End If
End Sub
As you can see I trying to send these totals via
a Msg Box but I can't get these "amt" and "temp"
commands to cause the information to "store!"
I even used Static in place of Dim hopeing this would do the trick but no luck,,,,I just don't know what to do...Please anyone HELP!!!:)

Juan Amore

Cakkie
October 19th, 2001, 11:47 AM
You got the scope of you variables wrong. "Static" means that the variable will keep value within the routine. So if you have a variable X in routine Y, variable X will have the value that it had the last time you run Y. What you need to do is to place those Static declarations to the top of the code (in the general declaration section) of the form, and declare them "private", this way, you will be able to acces them from anywhere withing the form. Same goes for the constants

'set 3 temp files used for total summary
private SalesNum as string
private CommNum as string
private TotalNum as string

private AmtSalesTemp as Currency
private AmtCommTemp as Currency
private AmtTotalTemp as Currency

private AmtSales as Currency
private AmtComm as Currency
private AmtTotal as Currency

Const rate = 0.15
Const base = 250
Const quota = 999

private Sub mnuSummary_Click()

If IsNumeric(txt2.Text) then
AmtSalesTemp = txt2.Text
else
MsgBox "No Data to Summarize", vbOKOnly, "Commission"
End If

If AmtSalesTemp >= quota then

AmtCommTemp = AmtSalesTemp * rate
AmtTotalTemp = AmtCommTemp + base

SalesNum = AmtSalesTemp + AmtSales
CommNum = AmtCommTemp + AmtComm
TotalNum = AmtTotalTemp + AmtTotal

MsgBox "Total Pay = $" & Format$(TotalNum, ".00") & vbCrLf & "Total Commission=$" & Format$(CommNum, ".00") & vbCrLf & "Total Sales=$" & Format$(SalesNum, ".00"), vbOKOnly, "Summary"
else
MsgBox "Total Pay = $" & Format$(base, ".00") & vbCrLf & "Total Commission=$" & Format$(CommNum, ".00") & vbCrLf & "Total Sales=$" & Format$(SalesNum, ".00"), vbOKOnly, "Summary"
End If

End Sub




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Boumxyz2
October 19th, 2001, 12:56 PM
You can't access those variables because their scope is stuck within the Form_Load sub routine.

If you want to access them from other routine in the same form then you have to Dim them as general
which would mean


option explicit

Dim amt as integer
Dim temp as integer

Sub form_Load ()
Dim bob as integer
'Can access amt, temp and Bob but not mike
end sub

Sub command1_Click()
Dim mike as integer
'Can access mike, amt , temp but not bob
end sub





If you want to use those variables between forms there are many ways to do it.

Adding a module and putting those variables public is one way to do it.

I hope it helps

Nic