1,105,214 Community Members

problem with data type definition

Member Avatar
Nebil
Junior Poster in Training
62 posts since Apr 2013
Reputation Points: 5 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi guys,

I'm a little bit confused to declare a certain variable.
I defined it under a button.It's in a do-while loop and it stores calculated values while other this are being executed.

And i wanted to extract that value using another button.I know i can use a function but is there a way that i can define the variable using a certain data type that stores the current value of that variable?

Here's the code anyway

cmd = New OleDbCommand("SELECT [sub_pay_item_quantity].[quantity],[sub_pay_item_unit_rate].[rate] FROM " &
                                   "[sub_pay_item_quantity],[sub_pay_item_unit_rate] WHERE [sub_pay_item_quantity].[sub item]=[sub_pay_item_unit_rate].[sub item] AND " &
                                   "[sub_pay_item_quantity].[sub item]='" & subItem & "' AND [sub_pay_item_quantity].[bridge type]='" & bridgeType & "' " &
                                   "AND [sub_pay_item_quantity].[span]='" & span & "'", conn)

            cmd1 = New OleDbCommand("SELECT * FROM sub_pay_item_quantity WHERE [sub item]='" & subItem & "' AND [bridge type]='" & bridgeType & "'" & _
                                    "AND [span]='" & span & "'", conn)

            data_reader = cmd.ExecuteReader()
            data_reader1 = cmd1.ExecuteReader()

            If data_reader.HasRows = True Then
                Do While data_reader.Read()
                    quantity = CDbl(data_reader.Item("quantity"))
                    rate = CDbl(data_reader.Item("rate"))
                    amount = (quantity * rate)
                    result += amount
                Loop
                total = result
            Else
                MsgBox("Unit rate does not exist", vbCritical, "Bridge Construction Cost Estimate")
                Exit Sub
            End If
            If data_reader1.HasRows = True Then
                Do While data_reader1.Read()
                    payItem = CDbl(data_reader1.Item("pay item"))
                    subpayItem = CDbl(data_reader1.Item("sub pay item"))
                    unit = data_reader1.Item("unit")
                Loop
            End If

:"total" is the name of the variable.

Member Avatar
tinstaafl
Postaholic
2,012 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 401 [?]
Skill Endorsements: 35 [?]
 
0
 

If you declare it at class level(outside any subs or functions), then any routine can access it.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article