Repository navigation
Expand file tree
/
Copy pathAutoSensorMenu.vba
More file actions
126 lines (108 loc) · 3.6 KB
/
Copy pathAutoSensorMenu.vba
File metadata and controls
126 lines (108 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Option Explicit
' Merge declarations into the top of the target UserForm code module.
Private pMRObserver As Object
Private pMRToken As String
Private mProcessing As Boolean
Private Const SENSOR_DEFAULT_SIZE As String = "7"
Private Const SENSOR_SIZE_HINT As String = "7 mm"
Private mHintReady As Boolean
Private mUpdatingHint As Boolean
Private mSensorHintActive As Boolean
Private mSensorSizeFocused As Boolean
Private mSensorInputColor As Long
Private Sub UserForm_Initialize()
mSensorInputColor = txbSensorSize.ForeColor
mHintReady = True
If Not optSensor.Value And Not optWhiteSpace.Value Then optSensor.Value = True
UpdateSizeInput
End Sub
Private Sub cmdClose_Click()
If Not mProcessing Then Unload Me
End Sub
Private Sub cmdProcess_Click()
If mProcessing Then Exit Sub
If optSensor.Value = optWhiteSpace.Value Then
MsgBox "Pilih salah satu mode: Sensor atau WhiteSpace.", vbExclamation, "AutoSensor"
Exit Sub
End If
On Error GoTo ProcessFailed
mProcessing = True
cmdProcess.Enabled = False
ASGenerate optWhiteSpace.Value, SensorSizeInput()
ProcessFinished:
mProcessing = False
cmdProcess.Enabled = True
UpdateSizeInput
Unload Me
Exit Sub
ProcessFailed:
MsgBox "AutoSensor gagal: " & Err.Description, vbExclamation, "AutoSensor"
Resume ProcessFinished
End Sub
Private Sub optSensor_Click()
UpdateSizeInput
End Sub
Private Sub optWhiteSpace_Click()
UpdateSizeInput
End Sub
Private Sub txbSensorSize_Change()
If Not mHintReady Or mUpdatingHint Then Exit Sub
mSensorHintActive = False
txbSensorSize.ForeColor = mSensorInputColor
ShowSensorSizeHint
End Sub
Private Sub txbSensorSize_Enter()
If Not mHintReady Then Exit Sub
mSensorSizeFocused = True
mUpdatingHint = True
If mSensorHintActive Then txbSensorSize.Value = vbNullString
mSensorHintActive = False
txbSensorSize.ForeColor = mSensorInputColor
mUpdatingHint = False
End Sub
Private Sub txbSensorSize_Exit(ByVal Cancel As MSForms.ReturnBoolean)
mSensorSizeFocused = False
ShowSensorSizeHint
End Sub
Private Sub UpdateSizeInput()
txbSensorSize.Enabled = optSensor.Value And Not optWhiteSpace.Value
If Not txbSensorSize.Enabled Then mSensorSizeFocused = False
ShowSensorSizeHint
End Sub
Private Sub ShowSensorSizeHint()
If Not mHintReady Or mUpdatingHint Or mSensorSizeFocused Then Exit Sub
If Len(Trim$(CStr(txbSensorSize.Value))) > 0 Then Exit Sub
mUpdatingHint = True
mSensorHintActive = True
txbSensorSize.ForeColor = RGB(128, 128, 128)
txbSensorSize.Value = SENSOR_SIZE_HINT
mUpdatingHint = False
End Sub
Private Function SensorSizeInput() As String
If mSensorHintActive Or Len(Trim$(CStr(txbSensorSize.Value))) = 0 Then
SensorSizeInput = SENSOR_DEFAULT_SIZE
Else
SensorSizeInput = CStr(txbSensorSize.Value)
End If
End Function
' Called only by MRTargetBridge; normal menu entry points remain unchanged.
Public Sub MRBindRunner(ByVal observer As Object, ByVal token As String)
Set pMRObserver = observer
pMRToken = token
End Sub
Public Sub MRDetachRunner()
Set pMRObserver = Nothing
pMRToken = vbNullString
End Sub
Private Sub UserForm_Terminate()
Dim observer As Object, token As String
On Error GoTo NotifyFailed
Set observer = pMRObserver
token = pMRToken
MRDetachRunner
If Not observer Is Nothing Then CallByName observer, "MacroUnloaded", VbMethod, token
Exit Sub
NotifyFailed:
MsgBox "Gagal memberitahu Macro Runner bahwa form sudah ditutup (" & CStr(Err.Number) & "): " & _
Err.Description, vbExclamation, "Macro Runner"
End Sub