Function action
Dim Conn, sql
Dim PCName
Dim RecordSet
Dim CurrentHour
Dim T1
Dim CumulativeYield
PCName = HMIRuntime.Tags("@LocalMachineName").Read
T1 = HMIRuntime.Tags("产量").Read
' 获取当前小时
CurrentHour = Hour(Now())
Set Conn = CreateObject("ADODB.Connection")
' 数据库连接字符串
Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & HMIRuntime.ActiveProject.Path & "\report\Yield_data.accdb;Persist Security Info=False;"
Conn.Open
' SQL查询语句,假设CurDateTime是记录时间字段
sql = "SELECT SUM(产量) AS CumulativeYield FROM Yield WHERE Hour(CurDateTime) <= " & CurrentHour
Set RecordSet = Conn.Execute(sql)
' 获取累积产量
CumulativeYield = RecordSet.Fields("CumulativeYield").Value + T1
' SQL插入语句
sql = "INSERT INTO Yield(CurDateTime, 产量, CumulativeYield) VALUES (Now(), " & T1 & ", " & CumulativeYield & ")"
Conn.Execute sql
Conn.Close
Set Conn = Nothing
这是全局脚本,我用按钮触发,

记录值会有好多小数位,我明明加的是一位小数,有点不明白那里的问题,求解答