-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetFuncNe.cls
346 lines (327 loc) · 13.7 KB
/
GetFuncNe.cls
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "GetFuncNe"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Dim strFn() As String
Dim X As Double
Dim intCount As Integer
Dim intKor As Long
Dim strPromKor As String
Dim strFKor As String
Dim strSKor As String
Dim intPosKor As Long
Dim dblKor As Double
Dim FFunc As Double
Dim SFunc As Double
Dim FFuncSt As Double
Dim SFuncSt As Double
Dim dblStop As Double
Dim dblExct As Double
Dim dblMax As Double
Dim dblMin As Double
Dim dblWork As Double
Dim GetF As New GetFunc
Public Function GetFun(strFunc As String, _
Min As Double, _
Max As Double, _
Optional Step = 0.1, _
Optional Exact = 8) As String
Dim dblWork As Double
dblExct = Exact
intKor = 0
dblStop = Min
dblMax = Max
dblMin = Min
frmWork.Show
'>=
If InStr(strFunc, ">=") <> 0 Then
Fdr:
dblWork = Step
dblKor = GetFunMaxBR(strFunc, ">=", dblStop, Max, dblWork)
If dblKor <> 1000000.3 Then intKor = intKor + 1: GetFun = GetFun & dblKor & " "
If frmWork.blnWork = False Then GetFun = "Ïðåðâàíî_" & frmWork.lblPer & "(" & dblStop & ")_:" & GetFun: GoTo EndFn
If dblStop < Max + 0.001 Then GoTo Fdr
GoTo EndFn
End If
'<=
If InStr(strFunc, "<=") <> 0 Then
Fmr:
dblWork = Step
dblKor = GetFunMaxMR(strFunc, "<=", dblStop, Max, dblWork)
If dblKor <> 1000000.3 Then intKor = intKor + 1: GetFun = GetFun & dblKor & " "
If frmWork.blnWork = False Then GetFun = "Ïðåðâàíî_" & frmWork.lblPer & "(" & dblStop & ")_:" & GetFun: GoTo EndFn
If dblStop < Max + 0.001 Then GoTo Fmr
GoTo EndFn
End If
'<>
If InStr(strFunc, "<>") <> 0 Then
Fnr:
dblWork = Step
dblKor = GetFunMaxNR(strFunc, "<>", dblStop, Max, dblWork)
If dblKor <> 1000000.3 Then intKor = intKor + 1: GetFun = GetFun & dblKor & " "
If frmWork.blnWork = False Then GetFun = "Ïðåðâàíî_" & frmWork.lblPer & "(" & dblStop & ")_:" & GetFun: GoTo EndFn
If dblStop < Max + 0.001 Then GoTo Fnr
GoTo EndFn
End If
'>
If InStr(strFunc, ">") <> 0 Then
Fb:
dblWork = Step
dblKor = GetFunMaxB(strFunc, ">", dblStop, Max, dblWork)
If dblKor <> 1000000.3 Then intKor = intKor + 1: GetFun = GetFun & dblKor & " "
If frmWork.blnWork = False Then GetFun = "Ïðåðâàíî_" & frmWork.lblPer & "(" & dblStop & ")_:" & GetFun: GoTo EndFn
If dblStop < Max + 0.001 Then GoTo Fb
GoTo EndFn
End If
'<
If InStr(strFunc, "<") <> 0 Then
Fm:
dblWork = Step
dblKor = GetFunMaxM(strFunc, "<", dblStop, Max, dblWork)
If dblKor <> 1000000.3 Then intKor = intKor + 1: GetFun = GetFun & dblKor & " "
If frmWork.blnWork = False Then GetFun = "Ïðåðâàíî_" & frmWork.lblPer & "(" & dblStop & ")_:" & GetFun: GoTo EndFn
If dblStop < Max + 0.001 Then GoTo Fm
GoTo EndFn
End If
'óðàâíåíèÿ
If InStr(strFunc, "=") <> 0 Then
Fu:
dblWork = Step
dblKor = GetFunMax(strFunc, "=", dblStop, Max, dblWork)
If dblKor <> 1000000.3 Then intKor = intKor + 1: GetFun = GetFun & dblKor & " "
If frmWork.blnWork = False Then GetFun = "Ïðåðâàíî_" & frmWork.lblPer & "(" & dblStop & ")_:" & GetFun: GoTo EndFn
If dblStop < Max + 0.001 Then GoTo Fu
End If
EndFn:
'ñîçäàíèå ïðîìåæóòêîâ
If GetFun = "" Then GoTo Fo
Dim strWork() As String
GetFun = Replace(GetFun, ",", ".")
GetFun = Left(GetFun, Len(GetFun) - 1)
If InStr(GetFun, " ") = 0 Then GoTo Fo
strWork = Split(GetFun, " ")
GetFun = ""
SFunc = Val(strWork(0))
For intCount = 1 To UBound(strWork)
FFunc = SFunc
SFunc = Val(strWork(intCount))
If Abs(FFunc - SFunc) <= 0.0011 Then
If intPosKor = 0 Then strFKor = FFunc
intPosKor = intPosKor + 1
If intPosKor < 3 Then
strPromKor = strPromKor & SFunc
Else
strPromKor = "[" & strFKor & ";" & SFunc & "]"
End If
Else
If intPosKor > 0 Then GetFun = GetFun & strPromKor & " "
If intPosKor = 0 Then GetFun = GetFun & SFunc & " "
If intCount = 1 Then GetFun = FFunc & " " & SFunc & " "
strFKor = ""
strPromKor = ""
intPosKor = 0
End If
Next intCount
If intPosKor > 0 Then GetFun = GetFun & strPromKor
Fo:
'âûâîä ðåçóëüòàòà
If GetFun = "" Then GetFun = "íåò êîðíåé"
GetFun = strFunc & vbCrLf & "íà_ïðîìåæóòêå_[" & Str(Min) & ";" & Str(Max) & "]_ñ_øàãîì_" & Str(Step) & "_ñ_òî÷íîñòüþ_" & Exact & "_íàéäåíî_" & Str(intKor) & "_êîðíåé:" & vbCrLf & GetFun
Unload frmWork
End Function
Public Function GetFunCheck(strFun As String) As Boolean
Dim intOper As Integer
If UBound(Split(strFun, ">=")) = 1 Then intOper = intOper + 1: strFun = Replace(strFun, ">=", "")
If UBound(Split(strFun, "<=")) = 1 Then intOper = intOper + 1: strFun = Replace(strFun, "<=", "")
If UBound(Split(strFun, "<>")) = 1 Then intOper = intOper + 1: strFun = Replace(strFun, "<>", "")
If UBound(Split(strFun, "<")) = 1 Then intOper = intOper + 1: strFun = Replace(strFun, "<", "")
If UBound(Split(strFun, ">")) = 1 Then intOper = intOper + 1: strFun = Replace(strFun, ">", "")
If UBound(Split(strFun, "=")) = 1 Then intOper = intOper + 1: strFun = Replace(strFun, "=", "")
If Not (GetF.GetFunCheck(strFun)) Then GetFunCheck = False: Exit Function
If intOper > 1 Or intOper = 0 Then GetFunCheck = False: Exit Function
GetFunCheck = True
End Function
Private Function GetFunMaxBR(strFunc As String, Splt As String, Min As Double, Max As Double, StepM As Double) As Double
strFn = Split(strFunc, Splt)
FFuncSt = GetF.GetFun(strFn(0), Min)
SFuncSt = GetF.GetFun(strFn(1), Min)
If StepM > Max - Min Then StepM = Max - Min
For X = Min To Max Step StepM
dblWork = Round((X - dblMin) / (dblMax - dblMin) * 100, 2)
If dblWork >= 100 Then Unload frmWork
dblWork = Len(Str(StepM)) - 2
If dblWork < 3 Then dblWork = 3
X = Round(X, dblWork)
frmWork.lblPer = dblWork & "%"
frmWork.prbPer.Value = dblWork: DoEvents
strFn = Split(strFunc, Splt)
FFunc = FFuncSt
FFuncSt = Round(GetF.GetFun(strFn(0), X + StepM), dblExct)
SFunc = SFuncSt
SFuncSt = Round(GetF.GetFun(strFn(1), X + StepM), dblExct)
If FFunc >= SFunc And FFunc <> 1000000.3 And SFunc <> 1000000.3 Then GetFunMaxBR = X: dblStop = X + 0.001: Exit Function
If FFunc > SFunc And FFuncSt < SFuncSt Or FFunc < SFunc And FFuncSt > SFuncSt Then
If SFuncSt = 1000000.3 Or FFuncSt = 1000000.3 Or SFunc = 1000000.3 Or FFunc = 1000000.3 Or dblWork > dblExct Then GoTo 1
dblKor = GetFunMaxBR(strFunc, Splt, X, X + StepM, StepM / 10)
If dblKor <> 1000000.3 Then GetFunMaxBR = dblKor: dblStop = X + 0.001: Exit Function
1:
End If
Next X
dblStop = X + 0.001
GetFunMaxBR = 1000000.3
End Function
Private Function GetFunMaxMR(strFunc As String, Splt As String, Min As Double, Max As Double, StepM As Double) As Double
strFn = Split(strFunc, Splt)
FFuncSt = GetF.GetFun(strFn(0), Min)
SFuncSt = GetF.GetFun(strFn(1), Min)
If StepM > Max - Min Then StepM = Max - Min
For X = Min To Max Step StepM
dblWork = Round((X - dblMin) / (dblMax - dblMin) * 100, 2)
If dblWork >= 100 Then Unload frmWork
dblWork = Len(Str(StepM)) - 2
If dblWork < 3 Then dblWork = 3
X = Round(X, dblWork)
frmWork.lblPer = dblWork & "%"
frmWork.prbPer.Value = dblWork: DoEvents
strFn = Split(strFunc, Splt)
FFunc = FFuncSt
FFuncSt = Round(GetF.GetFun(strFn(0), X + StepM), dblExct)
SFunc = SFuncSt
SFuncSt = Round(GetF.GetFun(strFn(1), X + StepM), dblExct)
If FFunc <= SFunc And FFunc <> 1000000.3 And SFunc <> 1000000.3 Then GetFunMaxMR = X: dblStop = X + 0.001: Exit Function
If FFunc > SFunc And FFuncSt < SFuncSt Or FFunc < SFunc And FFuncSt > SFuncSt Then
If SFuncSt = 1000000.3 Or FFuncSt = 1000000.3 Or SFunc = 1000000.3 Or FFunc = 1000000.3 Or dblWork > dblExct Then GoTo 1
dblKor = GetFunMaxMR(strFunc, Splt, X, X + StepM, StepM / 10)
If dblKor <> 1000000.3 Then GetFunMaxMR = dblKor: dblStop = X + 0.001: Exit Function
1:
End If
Next X
dblStop = X + 0.001
GetFunMaxMR = 1000000.3
End Function
Private Function GetFunMaxNR(strFunc As String, Splt As String, Min As Double, Max As Double, StepM As Double) As Double
strFn = Split(strFunc, Splt)
FFuncSt = GetF.GetFun(strFn(0), Min)
SFuncSt = GetF.GetFun(strFn(1), Min)
If StepM > Max - Min Then StepM = Max - Min
For X = Min To Max Step StepM
dblWork = Round((X - dblMin) / (dblMax - dblMin) * 100, 2)
If dblWork >= 100 Then Unload frmWork
dblWork = Len(Str(StepM)) - 2
If dblWork < 3 Then dblWork = 3
X = Round(X, dblWork)
frmWork.lblPer = dblWork & "%"
frmWork.prbPer.Value = dblWork: DoEvents
strFn = Split(strFunc, Splt)
FFunc = FFuncSt
FFuncSt = Round(GetF.GetFun(strFn(0), X + StepM), dblExct)
SFunc = SFuncSt
SFuncSt = Round(GetF.GetFun(strFn(1), X + StepM), dblExct)
If FFunc <> SFunc And FFunc <> 1000000.3 And SFunc <> 1000000.3 Then GetFunMaxNR = X: dblStop = X + 0.001: Exit Function
If FFunc > SFunc And FFuncSt < SFuncSt Or FFunc < SFunc And FFuncSt > SFuncSt Then
If SFuncSt = 1000000.3 Or FFuncSt = 1000000.3 Or SFunc = 1000000.3 Or FFunc = 1000000.3 Or dblWork > dblExct Then GoTo 1
dblKor = GetFunMaxNR(strFunc, Splt, X, X + StepM, StepM / 10)
If dblKor <> 1000000.3 Then GetFunMaxNR = dblKor: dblStop = X + 0.001: Exit Function
1:
End If
Next X
dblStop = X + 0.001
GetFunMaxNR = 1000000.3
End Function
Private Function GetFunMaxB(strFunc As String, Splt As String, Min As Double, Max As Double, StepM As Double) As Double
strFn = Split(strFunc, Splt)
FFuncSt = GetF.GetFun(strFn(0), Min)
SFuncSt = GetF.GetFun(strFn(1), Min)
If StepM > Max - Min Then StepM = Max - Min
For X = Min To Max Step StepM
dblWork = Round((X - dblMin) / (dblMax - dblMin) * 100, 2)
If dblWork >= 100 Then Unload frmWork
dblWork = Len(Str(StepM)) - 2
If dblWork < 3 Then dblWork = 3
X = Round(X, dblWork)
frmWork.lblPer = dblWork & "%"
frmWork.prbPer.Value = dblWork: DoEvents
strFn = Split(strFunc, Splt)
FFunc = FFuncSt
FFuncSt = Round(GetF.GetFun(strFn(0), X + StepM), dblExct)
SFunc = SFuncSt
SFuncSt = Round(GetF.GetFun(strFn(1), X + StepM), dblExct)
If FFunc > SFunc And FFunc <> 1000000.3 And SFunc <> 1000000.3 Then GetFunMaxB = X: dblStop = X + 0.001: Exit Function
If FFunc > SFunc And FFuncSt < SFuncSt Or FFunc < SFunc And FFuncSt > SFuncSt Then
If SFuncSt = 1000000.3 Or FFuncSt = 1000000.3 Or SFunc = 1000000.3 Or FFunc = 1000000.3 Or dblWork > dblExct Then GoTo 1
dblKor = GetFunMaxB(strFunc, Splt, X, X + StepM, StepM / 10)
If dblKor <> 1000000.3 Then GetFunMaxB = dblKor: dblStop = X + 0.001: Exit Function
1:
End If
Next X
dblStop = X + 0.001
GetFunMaxB = 1000000.3
End Function
Private Function GetFunMaxM(strFunc As String, Splt As String, Min As Double, Max As Double, StepM As Double) As Double
strFn = Split(strFunc, Splt)
FFuncSt = GetF.GetFun(strFn(0), Min)
SFuncSt = GetF.GetFun(strFn(1), Min)
If StepM > Max - Min Then StepM = Max - Min
For X = Min To Max Step StepM
dblWork = Round((X - dblMin) / (dblMax - dblMin) * 100, 2)
If dblWork >= 100 Then Unload frmWork
frmWork.lblPer = dblWork & "%"
frmWork.prbPer.Value = dblWork: DoEvents
dblWork = Len(Str(StepM)) - 2
If dblWork < 3 Then dblWork = 3
X = Round(X, dblWork)
strFn = Split(strFunc, Splt)
FFunc = FFuncSt
FFuncSt = Round(GetF.GetFun(strFn(0), X + StepM), dblExct)
SFunc = SFuncSt
SFuncSt = Round(GetF.GetFun(strFn(1), X + StepM), dblExct)
If FFunc < SFunc And FFunc <> 1000000.3 And SFunc <> 1000000.3 Then GetFunMaxM = X: dblStop = X + 0.001: Exit Function
If FFunc > SFunc And FFuncSt < SFuncSt Or FFunc < SFunc And FFuncSt > SFuncSt Then
If SFuncSt = 1000000.3 Or FFuncSt = 1000000.3 Or SFunc = 1000000.3 Or FFunc = 1000000.3 Or dblWork > dblExct Then GoTo 1
dblKor = GetFunMaxM(strFunc, Splt, X, X + StepM, StepM / 10)
If dblKor <> 1000000.3 Then GetFunMaxM = dblKor: dblStop = X + 0.001: Exit Function
1:
End If
Next X
dblStop = X + 0.001
GetFunMaxM = 1000000.3
End Function
Private Function GetFunMax(strFunc As String, Splt As String, Min As Double, Max As Double, StepM As Double) As Double
strFn = Split(strFunc, Splt)
FFuncSt = GetF.GetFun(strFn(0), Min)
SFuncSt = GetF.GetFun(strFn(1), Min)
If StepM > Max - Min Then StepM = Max - Min
For X = Min To Max Step StepM
dblWork = Round((X - dblMin) / (dblMax - dblMin) * 100, 2)
If dblWork >= 100 Then Unload frmWork
frmWork.lblPer = dblWork & "%"
frmWork.prbPer.Value = dblWork: DoEvents
dblWork = Len(Str(StepM)) - 2
If dblWork < 3 Then dblWork = 3
X = Round(X, dblWork)
strFn = Split(strFunc, Splt)
FFunc = FFuncSt
FFuncSt = GetF.GetFun(strFn(0), X + StepM)
SFunc = SFuncSt
SFuncSt = GetF.GetFun(strFn(1), X + StepM)
If Abs(FFunc - SFunc) <= 10 ^ (-dblExct) And FFunc <> 1000000.3 Then GetFunMax = X: dblStop = X + 0.001: Exit Function
If FFunc > SFunc And FFuncSt < SFuncSt Or FFunc < SFunc And FFuncSt > SFuncSt Then
If SFuncSt = 1000000.3 Or FFuncSt = 1000000.3 Or SFunc = 1000000.3 Or FFunc = 1000000.3 Or dblWork > dblExct Then GoTo 1
dblKor = GetFunMax(strFunc, Splt, X, X + StepM, StepM / 10)
If dblKor <> 1000000.3 Then GetFunMax = dblKor: dblStop = X + 0.001: Exit Function
1:
End If
Next X
dblStop = X + 0.001
GetFunMax = 1000000.3
End Function