📄 frmdata.frm
字号:
Left = 150
TabIndex = 22
Top = 1314
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "五 月:"
Height = 180
Index = 4
Left = 150
TabIndex = 21
Top = 1632
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "六 月:"
Height = 180
Index = 5
Left = 150
TabIndex = 20
Top = 1950
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "七 月:"
Height = 180
Index = 6
Left = 1935
TabIndex = 19
Top = 390
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "八 月:"
Height = 180
Index = 7
Left = 1935
TabIndex = 18
Top = 720
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "九 月:"
Height = 180
Index = 8
Left = 1935
TabIndex = 17
Top = 1020
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "十 月:"
Height = 180
Index = 9
Left = 1935
TabIndex = 16
Top = 1335
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "十一月:"
Height = 180
Index = 10
Left = 1935
TabIndex = 15
Top = 1665
Width = 720
End
Begin VB.Label lbl
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "十二月:"
Height = 180
Index = 11
Left = 1935
TabIndex = 14
Top = 1980
Width = 720
End
End
End
Attribute VB_Name = "frmData"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim iOpt As Integer
Dim fChanged As Boolean
Dim fUnitChanged As Boolean
'******************************************************
'*自定义函数
'******************************************************
'初始化文本框
Sub InitTextBox()
Dim l As Long, s As String
For l = 0 To 11
s = Trim(CStr(pbasngDataOperating(l, iOpt)))
txtMonthlyData(l).Text = IIf(Left(s, 1) = ".", "0" & s, s)
txtMonthlyData(l).Enabled = frmMain.lvData.ListItems(l + 1).Checked
Next
End Sub
Sub InitTmpArray()
Dim i As Long, l As Long
If pbfEditMode = True Then
For i = 0 To 11
For l = 0 To 2
pbasngDataOperating(i, l) = CSng(frmMain.lvData.ListItems(i + 1).SubItems(l + 1))
Next
Next
End If
InitTextBox
End Sub
'根据不同的操作修改本窗体标题
Sub OptionSelecting()
On Error Resume Next
Dim spre As String, l As Long, i As Long
If pbfEditMode = True Then
spre = "修改"
Else
spre = "添加"
End If
frmData.Caption = spre + pbasDataType(iOpt + 1)
InitTextBox
End Sub
'******************************************************
'*窗体函数
'******************************************************
Private Sub cmdCancel_Click()
Me.Hide
End Sub
Private Sub cmdOK_Click()
On Error GoTo staErr
Dim l As Long, i As Long, v As Variant, a(2) As Single, sTmp As String
If fChanged Then
If MsgBox("您真的想更改数据么?", vbYesNo + vbQuestion + vbDefaultButton2) = vbYes Then
Set pbcolMonthlyData = New Collection
For i = 0 To 11
For l = 0 To 2
a(l) = pbasngDataOperating(i, l)
With frmMain.lvData.ListItems(i + 1)
If .Checked Then
.SubItems(l + 1) = Trim((a(l)))
End If
End With
Next
pbcolMonthlyData.Add a, pbasMonth(i)
Next
Else
Exit Sub
End If
End If
pbfEditMode = True
pbfInit = False
Me.Hide
Exit Sub
staErr:
If Err.Number = 5 Then Resume Next
pbfEditMode = False
End Sub
Private Sub Form_Activate()
optModify(0).Value = True
InitTmpArray
fChanged = False
fUnitChanged = False
End Sub
Private Sub optModify_Click(Index As Integer)
iOpt = Index
OptionSelecting
End Sub
Private Sub txtMonthlyData_Change(Index As Integer)
fChanged = True
End Sub
Private Sub txtMonthlyData_KeyPress(Index As Integer, KeyAscii As Integer)
'文本框除数字、负号、小数点外其他一概不收
Dim i As Integer
i = KeyAscii
If (i >= 32 And i <= 44) Or i = 47 Or i >= 58 Then
KeyAscii = 0
End If
Select Case i
Case Asc("-")
If InStr(txtMonthlyData(Index).Text, "-") <> 0 Then KeyAscii = 0
Case Asc(".")
If InStr(txtMonthlyData(Index).Text, ".") <> 0 Then KeyAscii = 0
End Select
End Sub
Private Sub txtMonthlyData_LostFocus(Index As Integer)
Call txtMonthlyData_Validate(Index, True)
End Sub
Private Sub txtMonthlyData_Validate(Index As Integer, Cancel As Boolean)
On Error Resume Next
Dim sTmp As String, lDotPos As Long, lMinusPos As Long, lLen As Long
sTmp = Trim(txtMonthlyData(Index).Text)
lLen = Len(sTmp)
lDotPos = InStr(sTmp, ".")
lMinusPos = InStr(sTmp, "-")
'.- , -. Abs(lDotPos - lMinusPos) = 1
'0-,0. Not IsFigure(Right(sTmp, 1))
'.0 Left(sTmp, 1) = "."
'0-0 left()
'
If (lDotPos <> 0 And lMinusPos <> 0 And Abs(lDotPos - lMinusPos) = 1) Then GoTo staAssert
If Not IsFigure(Right(sTmp, 1)) Then GoTo staAssert
If Left(sTmp, 1) = "." Then GoTo staAssert
If lMinusPos <> 0 And lMinusPos <> 1 Then GoTo staAssert
pbasngDataOperating(Index, iOpt) = CSng(txtMonthlyData(Index).Text)
Exit Sub
staAssert:
MsgBox "您输入的数字有误,请检查一下。", vbExclamation
Cancel = True
End Sub
Private Sub txtUnit_Change()
fUnitChanged = True
End Sub
Private Sub txtUnit_LostFocus()
If fUnitChanged = False Then Exit Sub
If MsgBox("将数据单位从" + pbsDataUnit + "改为" + txtUnit.Text + "吗?", vbYesNo + vbQuestion + vbDefaultButton2) = vbYes Then
pbsDataUnit = Trim(txtUnit.Text)
Else
txtUnit.Text = pbsDataUnit
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -