Advertisement
veronikaaa86

VBA

Dec 23rd, 2021
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. Sub Demo()
  2. Dim grade As Integer
  3. grade = 4
  4.  
  5. If grade >= 5 Then
  6. Debug.Print "Excellent"
  7. End If
  8.  
  9. End Sub
  10.  
  11. =====================================
  12.  
  13. Sub Demo()
  14. Dim greater As Integer
  15.  
  16. greater = GreaterNum(2, 2)
  17.  
  18. Debug.Print greater
  19.  
  20. End Sub
  21.  
  22. Function GreaterNum(firstNum, secondNum As Integer)
  23. If firstNum >= secondNum Then
  24. 'GreaterNum = firstNum
  25. MsgBox firstNum
  26. Else
  27. MsgBox secondNum
  28. 'GreaterNum = secondNum
  29. End If
  30. End Function
  31. =====================================
  32. Sub Demo()
  33. Dim result As String
  34.  
  35. result = EvenOrOdd(2)
  36.  
  37. Debug.Print result
  38.  
  39. End Sub
  40.  
  41. Function EvenOrOdd(num As Integer)
  42. If num Mod 2 = 0 Then
  43. EvenOrOdd = "even"
  44. 'MsgBox "even"
  45. Else
  46. EvenOrOdd = "odd"
  47. 'MsgBox "odd"
  48. End If
  49. End Function
  50. =====================================
  51. Sub Demo()
  52. Dim num As Integer
  53. num = 13
  54.  
  55. Dim digitAsText As String
  56. If num = 1 Then
  57. digitAsText = "one"
  58. ElseIf num = 2 Then
  59. digitAsText = "two"
  60. ElseIf num = 3 Then
  61. digitAsText = "three"
  62. ElseIf num = 4 Then
  63. digitAsText = "four"
  64. ElseIf num = 5 Then
  65. digitAsText = "five"
  66. ElseIf num = 6 Then
  67. digitAsText = "six"
  68. ElseIf num = 7 Then
  69. digitAsText = "seven"
  70. ElseIf num = 8 Then
  71. digitAsText = "eight"
  72. ElseIf num = 9 Then
  73. digitAsText = "nine"
  74. Else
  75. digitAsText = "not a digit"
  76. End If
  77.  
  78. Debug.Print digitAsText
  79.  
  80. End Sub
  81.  
  82. =====================================
  83. Sub Demo()
  84. Dim num As Integer
  85. num = 20000
  86.  
  87. Dim result As String
  88. If num < 100 Then
  89. result = "Less than 100"
  90. ElseIf num <= 200 Then
  91. result = "Between 100 and 200"
  92. Else
  93. result = "Greater than 200"
  94. End If
  95.  
  96. Debug.Print result
  97. End Sub
  98. =====================================
  99. Sub Demo()
  100. Dim inputText As String
  101. inputText = "s3cr3t!P@ssw0rd"
  102.  
  103. Dim result As String
  104. If inputText = "s3cr3t!P@ssw0rd" Then
  105. result = "Welcome"
  106. Else
  107. result = "Wrong password!"
  108. End If
  109.  
  110. Debug.Print result
  111. End Sub
  112. =====================================
  113. Sub Demo()
  114. Dim result As Double
  115. result = ReturnArea("circle", 10)
  116.  
  117. Debug.Print result
  118. End Sub
  119.  
  120. Function ReturnArea(typeFigure As String, param As Double)
  121. Select Case (typeFigure)
  122. Case "square"
  123. ReturnArea = param * param
  124. Case "circle"
  125. ReturnArea = WorksheetFunction.Pi * param * param
  126. End Select
  127.  
  128. End Function
  129. =====================================
  130. Sub Demo()
  131. Dim tripPrice, countPuzzle, countDolls, countTeddy, countMinions, countTrucks As Double
  132. tripPrice = 320
  133. countPuzzle = 8
  134. countDolls = 2
  135. countTeddy = 5
  136. countMinions = 5
  137. countTrucks = 1
  138.  
  139. Dim allToysPrice As Double
  140. allToysPrice = (countPuzzle * 2.6) + (countDolls * 3) + (countTeddy * 4.1) + (countMinions * 8.2) + (countTrucks * 2)
  141.  
  142. Dim countAllToys As Double
  143. countAllToys = countPuzzle + countDolls + countTeddy + countMinions + countTrucks
  144.  
  145. If countAllToys > 50 Then
  146. allToysPrice = allToysPrice * 0.75
  147. End If
  148.  
  149. allToysPrice = allToysPrice * 0.9
  150.  
  151. Dim diff As Double
  152. diff = Abs(allToysPrice - tripPrice)
  153. If allToysPrice >= tripPrice Then
  154. Debug.Print "Yes! " & diff & " lv left."
  155. Else
  156. Debug.Print "Not enough money! " & diff & " lv needed."
  157. End If
  158.  
  159. End Sub
  160. =====================================
  161.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement