|
楼主 |
发表于 2018-11-12 19:56
|
显示全部楼层
精简实例
Sub 按钮5_Click()
Dim arr, k0, k2, i, j As Integer
With Worksheets("sheet2")
k0 = .[a1].End(4).Row - 1
arr = .[a2].Resize(k0, 6)
End With
k2 = arr(1, 3)
For i = 2 To k0
If arr(i, 3) > k2 Then k2 = arr(i, 3)
Next
Dim hdc As Long, hDCmem As Long, hBitmap As Long
hdc = GetDC(0)
hDCmem = CreateCompatibleDC(hdc) '创建一个与窗体相兼容的设备场景
hBitmap = CreateCompatibleBitmap(hdc, k0, 400) '创建一个与屏幕兼容的位图,得到它的句柄
If hBitmap <> 0 Then
Dim junk As Long, avg5, avg30, avg60
junk = SelectObject(hDCmem, hBitmap)
For i = 1 To k0
avg5 = 0
For j = 0 To 4
If i - j = 0 Then Exit For
avg5 = avg5 + arr(i - j, 6)
Next
avg5 = avg5 / (j + 1)
junk = SetPixel(hDCmem, i, 400 - avg5 * 400 / k2, RGB(0, 0, 255))
'''''''''''''''''''''
avg30 = 0
For j = 0 To 29
If i - j = 0 Then Exit For
avg30 = avg30 + arr(i - j, 6)
Next
avg30 = avg30 / (j + 1)
junk = SetPixel(hDCmem, i, 400 - avg30 * 400 / k2, RGB(255, 0, 0))
'''''''''''''''''''
avg60 = 0
For j = 0 To 59
If i - j = 0 Then Exit For
avg60 = avg60 + arr(i - j, 6)
Next
avg60 = avg60 / (j + 1)
junk = SetPixel(hDCmem, i, 400 - avg60 * 400 / k2, RGB(0, 255, 0))
Next
junk = OpenClipboard(0)
junk = EmptyClipboard()
junk = SetClipboardData(CF_BITMAP, hBitmap)
junk = CloseClipboard()
End If
junk = DeleteDC(hDCmem)
junk = ReleaseDC(0, hdc)
ActiveSheet.Paste
End Sub
ff6.rar
(105.56 KB, 下载次数: 262)
|
|