Help Needed. When I click on button1, employee_id and P values need to be transferred from button1_click to Cal_Category13() and go through all the calculation. After the calculation, udtnew.X and udtnew.MTD values need to be transferred back to button1_Click

I've no problem to return multiple values Cal_Category13().MTD and Cal_Category13().X from Cal_Category13() to button1_Click but i've no idea how to transfer employee_id and p values from button1_click to Cal_Category13(). Do need your help to shed some lights.

Program Code

Public Structure PCB

Public Employee_ID As String
Public MTD As Decimal
Public X As Decimal

End Structure
______________________________________________________________________________________________________
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connetionString_Category As String
Dim sqlCnn_Category As SqlConnection
Dim sqlCmd_Category As SqlCommand
Dim sql_Category As String
Dim EmployeeID As String

connetionString_Category = "data source= PC; initial catalog=HRM;" & "integrated security=true"
sql_Category = "Select * from Employee"
sqlCnn_Category = New SqlConnection(connetionString_Category)
sqlCnn_Category.Open()
sqlCmd_Category = New SqlCommand(sql_Category, sqlCnn_Category)
Dim sqlReader_Category As SqlDataReader = sqlCmd_Category.ExecuteReader()
While sqlReader_Category.Read()
EmployeeID = sqlReader_Category(1)

'P and Employee ID need to be transferred from button1_Click to Cal_Category13()

P = ((sqlReader_Category(2) - sqlReader_Category(3)) + (sqlReader_Category(4) - sqlReader_Category(5))

Dim MTD_V As Decimal
Dim X As Decimal
MTD_V = Cal_Category13().MTD
X = Cal_Category13().X
End While
End Sub
______________________________________________________________________________________________________
Public Function Cal_Category13() As PCB

If P >= 5001 And P <= 20000 Then

M = 5000
R = 3 / 100
Category13 = -375

Dim connetionString As String
Dim sqlCnn As SqlConnection
Dim sqlCmd As SqlCommand
Dim sql As String

connetionString = "data source=PC; initial catalog=HRM;" & "integrated security=true"

sql = "Select * from PCB_Est where Employee_ID = '”& Employee_ID &”'"
sqlCnn = New SqlConnection(connetionString)
sqlCnn.Open()
sqlCmd = New SqlCommand(sql, sqlCnn)
Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader()

Dim udtnew As PCB
While sqlReader.Read()

Dim MTD_Total As Decimal = sqlReader.item(20)

udtnew.X += MTD_Total
End While

Response.Write("<br>")
Response.Write("Accumulated X value" & udtnew.X)

udtnew.MTD = (((P - M) * R + Category13) - (Z + udtnew.X))

If udtnew.MTD < 0 Then
udtnew.MTD = 0
Return udtnew
Else
Return udtnew

End If

End Function

Can you put your code in code-tags? It will make it WAY easier to read.

Generally, accepted OOP practice would be to return an object containing the two values you need. You can only return one object from a Function, but that object can have many properties, or it could even be an ArrayList containing your return values. I wouldn't recommend using an ArrayList, though, because you lose the advantages of type-checking as you develop/build.

You can also, create a structure and return an instance of that structure.
the structure can contain as many values as you want of any type

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.