-
Notifications
You must be signed in to change notification settings - Fork 0
/
macro_2.bas
100 lines (80 loc) · 2.28 KB
/
macro_2.bas
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
REM ***** BASIC *****
Global currDoc as Object
Global currSheet as Object
Global currCell as Object
Sub Main
currDoc = ThisComponent
currSheet = currDoc.sheets(0)
Dim price as Long
Dim priceA as Integer
Dim priceB as Integer
Dim temp as Integer
Dim itemsA() as Variant
Dim itemsB() as Variant
Dim Ai as Integer
Dim Bi as Integer
Const casePrice as Integer = 2000
price = 0
temp = 0
Ai = 0
Bi = 0
For i = 0 To GetRange("F1") Step 1
currCell = currSheet.getCellByPosition(5, i)
If currCell.String <> "" Then
priceA = currSheet.getCellByPosition(1, i).Value
priceB = currSheet.getCellByPosition(2, i).Value
temp = ReturnLesser(priceA, priceB)
If temp = priceA Then
ReDim Preserve itemsA(Ai)
itemsA(Ai) = currSheet.getCellByPosition(0, i).String
Ai = Ai + 1
Else
ReDim Preserve itemsB(Bi)
itemsB(Bi) = currSheet.getCellByPosition(0, i).String
Bi = Bi + 1
End If
price = price + temp
End If
Next
price = price + casePrice
Call WriteArray(itemsA, itemsB)
Call SetPrice(price)
End Sub
Function GetRange(cellName as Variant) as Integer
Dim Cur as Object
Dim Range as Object
Cur = currSheet.createCursorByRange(currSheet.getCellRangeByName(cellName))
Cur.gotoEndOfUsedArea(True)
Range = currSheet.getCellRangeByName(Cur.AbsoluteName)
GetRange = Range.RangeAddress.EndRow
End Function
Function ReturnLesser(num1 as Integer, num2 as Integer) as Integer
If num1 = 0 Then
ReturnLesser = num2
ElseIf num2 = 0 Then
ReturnLesser = num1
ElseIf num1 < num2 Then
ReturnLesser = num1
Else
ReturnLesser = num2
End If
End Function
Sub SetPrice(price)
currCell = currSheet.getCellByPosition(6, 1)
currCell.Value = price
currCell = currSheet.getCellByPosition(7, 1)
currCell.Value = price \ 61
End Sub
Sub WriteArray(itemsA as Variant, itemsB as Variant)
For i = 0 To ArrayLen(itemsA) - 1 Step 1
currCell = currSheet.getCellByPosition(8, i + 1)
currCell.String = itemsA(i)
Next
For i = 0 To ArrayLen(itemsB) - 1 Step 1
currCell = currSheet.getCellByPosition(9, i + 1)
currCell.String = itemsB(i)
Next
End Sub
Function ArrayLen(arr as Variant) as Integer
ArrayLen = UBound(arr) - LBound(arr) + 1
End Function