Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

beginner

Status
Not open for further replies.

xoymas

Technical User
Jun 6, 2001
34
0
0
US
Hi guys I am just a beginner and am trying to do a small program to calculate the new hourly pay but I'm stcuk I can't get the valuse entered on the first input form to be passed to the second main form as a constant so that I don't type it again. I can't get it to do the calculation wither. Here is the code.Your help will be apreciated

Option Explicit
Dim strRaise As String


Private Sub cmdClear_Click()
'clear the screen
txtRaise.Text = ""
txtCode1.Text = ""
txtCode2.Text = ""
txtCode3.Text = ""
txtCurrent.Text = ""
lblNpay.Caption = ""
lblMsg.Caption = ""

End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdNpay_Click()
Const conMsg As String = "Raise percentage: "
Dim intCode1 As Integer, intcode2 As Integer, intCode3 As Integer
Dim sngCurrent As Single, sngRaise As Single, sngNpay As Single, sngRate As Single
Const conRaise = Val(lblMsg.Caption)

'assign values to variables
intCode1 = Val(txtCode1.Text)
intcode2 = Val(txtCode2.Text)
intCode3 = Val(txtCode3.Text)
sngCurrent = Val(txtCurrent.Text)
sngRaise = Val(txtRaise.Text)
sngNpay = Val(lblNpay.Caption)
lblMsg.Caption = Val(txtRaise.Text)

'perform calculations
sngNpay = intCode1 * sngCurrent * sngRaise
sngNpay = intcode2 * sngCurrent * sngRaise
sngNpay = intCode3 * sngCurrent * sngRaise

'display variables
lblNpay.Caption = sngNpay
lblNpay.Caption = Format(sngNpay, "currency")
lblCode1a = sngNpay
lblCode2a = sngNpay
lblCode3a = sngNpay
sngRaise = lblMsg.Caption
lblMsg.Caption = conMsg & "" & FormatPercent(sngRaise)
cmdPrint.SetFocus


End Sub

Private Sub cmdPrint_Click()
'hide comand buttons before printing the forms
cmdNpay.Visible = False
cmdClear.Visible = False
cmdPrint.Visible = False
cmdExit.Visible = False
'display command buttons after the forms is printed
cmdNpay.Visible = True
cmdClear.Visible = True
cmdPrint.Visible = True
cmdExit.Visible = True
cmdClear.SetFocus
End Sub

Private Sub Form_Load()
Const conPrompt As String = "Enter the raise percentage"
strRaise = InputBox(conPrompt)

End Sub

 
You can't make a variable a "Constant" on another form, but You CAN declare the variable as PUBLIC.

Add this to the General Declarations area of Form2:
Public MyVariable as Int

Then to set that variable from form1 say:
Form2.MyVariable = 5

Kevin
 
Thanks for responding and I did change the code as sugested and I did get the value from the first form to show on the second but I get zeros after I push calculate.
Here is what changes I did:
Maybe you can paste it to a form so that you know what I mean.Thanks
Public Raise As Integer

Private Sub cmdClear_Click()
'clear the screen
txtRaise.Text = ""
txtCode1.Text = ""
txtCode2.Text = ""
txtCode3.Text = ""
txtCurrent.Text = ""
lblNpay.Caption = ""
lblMsg.Caption = ""

End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdNpay_Click()
Const conMsg As String = "Raise percentage: "

Dim intCode1 As Integer, intcode2 As Integer, intCode3 As Integer
Dim sngCurrent As Single, sngNpay As Single, sngRate As Single, sngRaise As Single
txtRaise.Text = Val(lblMsg.Caption)

'assign values to variables
intCode1 = Val(txtCode1.Text)
intcode2 = Val(txtCode2.Text)
intCode3 = Val(txtCode3.Text)
sngCurrent = Val(txtCurrent.Text)
sngNpay = Val(lblNpay.Caption)
lblMsg.Caption = Val(txtRaise.Text)

'perform calculations
sngNpay = intCode1 * sngCurrent * sngRaise
sngNpay = intcode2 * sngCurrent * sngRaise
sngNpay = intCode3 * sngCurrent * sngRaise

'display variables
lblNpay.Caption = sngNpay
lblNpay.Caption = Format(sngNpay, "currency")
lblCode1a = sngNpay
lblCode2a = sngNpay
lblCode3a = sngNpay
sngRaise = lblMsg.Caption
lblMsg.Caption = conMsg & "" & FormatPercent(sngRaise)
cmdPrint.SetFocus


End Sub

Private Sub cmdPrint_Click()
'hide comand buttons before printing the forms
cmdNpay.Visible = False
cmdClear.Visible = False
cmdPrint.Visible = False
cmdExit.Visible = False
'display command buttons after the forms is printed
cmdNpay.Visible = True
cmdClear.Visible = True
cmdPrint.Visible = True
cmdExit.Visible = True
cmdClear.SetFocus
End Sub

Private Sub Form_Load()
Const conPrompt As String = "Enter the raise percentage"
txtRaise.Text = InputBox(conPrompt)

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top