Advertisement
Guest User

stuff

a guest
Jun 8th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.74 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Private STR_Names(1 To 10) As String
  4. Private STR_Passwords(1 To 10) As String
  5. Private Sub Form_Load()
  6.  
  7. Dim STR_UserName As String
  8. Dim STR_UserPassword As String
  9.  
  10. Dim INT_NumOfTriesPassword As Integer
  11. Dim INT_NumOfTriesUsername As Integer
  12.  
  13. Dim INT_NameFoundIndex As Integer
  14. Dim INT_PasswordFoundIndex As Integer
  15. Dim INT_LoopIndex As Integer
  16.  
  17. Dim BLN_Found As Boolean
  18. BLN_Found = False
  19.  
  20. STR_Names(1) = "Alice"
  21. STR_Names(2) = "Bill"
  22. STR_Names(3) = "Carol"
  23. STR_Names(4) = "Dave"
  24. STR_Names(5) = "Elizabeth"
  25. STR_Names(6) = "Fletcher"
  26. STR_Names(7) = "Gina"
  27. STR_Names(8) = "Henry"
  28. STR_Names(9) = "Isabelle"
  29. STR_Names(10) = "Jacob"
  30.  
  31. STR_Passwords(1) = "Apple"
  32. STR_Passwords(2) = "Blueberry"
  33. STR_Passwords(3) = "Cranberry"
  34. STR_Passwords(4) = "Durian"
  35. STR_Passwords(5) = "Elderberry"
  36. STR_Passwords(6) = "Fig"
  37. STR_Passwords(7) = "Grape"
  38. STR_Passwords(8) = "Huckleberry"
  39. STR_Passwords(9) = "Imbe"
  40. STR_Passwords(10) = "Jackfruit"
  41.  
  42. Do While BLN_Found = False And INT_NumOfTriesPassword < 3
  43.  
  44. STR_UserName = UCase(InputBox("Please enter your username", "Enter password"))
  45. INT_NumOfTriesUsername = INT_NumOfTriesUsername + 1
  46.  
  47. For INT_LoopIndex = 1 To UBound(STR_Names)
  48. If STR_UserName = UCase(STR_Names(INT_LoopIndex)) Then
  49. MsgBox "Username accepted.", vbOKOnly, "Correct username."
  50. INT_NameFoundIndex = INT_LoopIndex
  51. BLN_Found = True
  52. Exit For
  53. ElseIf INT_NumOfTriesUsername = 3 And INT_LoopIndex = UBound(STR_Names) Then
  54. MsgBox "Wrong username. You have made three unsuccessful attempts. The program will now close.", vbOKOnly, "Exit program"
  55. End
  56. ElseIf INT_LoopIndex = UBound(STR_Names) Then
  57. MsgBox "Wrong Username. Try again."
  58. End If
  59.  
  60. Next INT_LoopIndex
  61.  
  62. Loop
  63.  
  64. BLN_Found = False
  65.  
  66. Do While BLN_Found = False And INT_NumOfTriesPassword < 3
  67. STR_UserPassword = UCase(InputBox("Please enter your password", "Enter password"))
  68. INT_NumOfTriesPassword = INT_NumOfTriesPassword + 1
  69.  
  70. If STR_UserPassword = UCase(STR_Passwords(INT_NameFoundIndex)) Then
  71. MsgBox "Password Accepted.", vbOKOnly, "Correct password."
  72. Exit Do
  73. ElseIf INT_NumOfTriesPassword < 3 Then
  74. MsgBox "Wrong password. You have made three unsuccessful attempts. The program will now close."
  75. End
  76. End If
  77.  
  78. Loop
  79.  
  80. End Sub
  81.  
  82. ____________________________________________________________________________________________________
  83.  
  84. Option Explicit
  85. Dim INT_Numbers(1 To 10) As Integer
  86. Private Sub CMD_GenerateArray_Click()
  87.  
  88. Dim INT_Loop As Integer
  89. For INT_Loop = LBound(INT_Numbers) To UBound(INT_Numbers)
  90. INT_Numbers(INT_Loop) = RndInt(0, 99)
  91. Next INT_Loop
  92. For INT_Loop = LBound(INT_Numbers) To UBound(INT_Numbers)
  93. LST_Array.AddItem INT_Numbers(INT_Loop)
  94. Next INT_Loop
  95.  
  96. End Sub
  97. Private Sub CMD_Reset_Click()
  98.  
  99. Dim INT_LoopIndex As Integer
  100.  
  101. For INT_LoopIndex = LBound(INT_Numbers) To UBound(INT_Numbers)
  102. INT_Numbers(INT_LoopIndex) = vbEmpty
  103. Next INT_LoopIndex
  104. LST_Array.Clear
  105.  
  106. End Sub
  107. Private Sub Form_Load()
  108.  
  109. Randomize
  110.  
  111. End Sub
  112. Private Sub CMD_Max_Click()
  113.  
  114. Dim INT_Index As Integer
  115. Dim INT_MaxNumber As Integer
  116.  
  117. INT_Index = 1
  118. INT_MaxNumber = INT_Numbers(INT_Index)
  119.  
  120. Do While INT_Index <= UBound(INT_Numbers)
  121. If INT_MaxNumber < INT_Numbers(INT_Index) Then
  122. INT_MaxNumber = INT_Numbers(INT_Index)
  123. End If
  124. INT_Index = INT_Index + 1
  125. Loop
  126.  
  127. LBL_Answer.Caption = "Max Number = " & INT_MaxNumber
  128.  
  129. End Sub
  130. Private Sub CMD_Min_Click()
  131.  
  132. Dim INT_Index As Integer
  133. Dim INT_MinNumber As Integer
  134.  
  135. INT_Index = 1
  136. INT_MinNumber = INT_Numbers(INT_Index)
  137.  
  138. Do While INT_Index <= UBound(INT_Numbers)
  139. If INT_MinNumber > INT_Numbers(INT_Index) Then
  140. INT_MinNumber = INT_Numbers(INT_Index)
  141. End If
  142. INT_Index = INT_Index + 1
  143. Loop
  144.  
  145. LBL_Answer.Caption = "Min Number = " & INT_MinNumber
  146.  
  147. End Sub
  148. Function RndInt(ByVal INT_LowNum As Integer, ByVal INT_HighNum As Integer) As Integer
  149.  
  150. RndInt = Int((INT_HighNum - INT_LowNum + 1) * Rnd + INT_LowNum)
  151.  
  152. End Function
  153. Private Sub CMD_Done_Click()
  154.  
  155. Unload Me
  156.  
  157. End Sub
  158. ___________________________________________________________________________________________________________
  159.  
  160. Option Explicit
  161. Private Sub Form_Load()
  162.  
  163. Randomize
  164.  
  165. End Sub
  166. Private Sub CMD_CreateArray_Click()
  167.  
  168. Dim INT_Size As Integer
  169. Dim INT_Numbers() As Integer
  170.  
  171. INT_Size = TXT_Size.Text
  172.  
  173. Call CreateArray(INT_Numbers(), 1, INT_Size)
  174. Call DisplayArray(INT_Numbers(), LST_Array)
  175.  
  176. End Sub
  177. Sub CreateArray(ByRef INT_Array() As Integer, ByVal INT_LowerLimit As Integer, ByVal INT_UpperLimit As Integer)
  178.  
  179. Dim INT_Loop As Integer
  180.  
  181. ReDim INT_Array(INT_LowerLimit To INT_UpperLimit)
  182.  
  183. For INT_Loop = INT_LowerLimit To INT_UpperLimit
  184. INT_Array(INT_Loop) = RndInt(1, 99)
  185. Next INT_Loop
  186.  
  187. End Sub
  188. Sub DisplayArray(ByRef INT_Array() As Integer, ByRef LST_List As ListBox)
  189.  
  190. Dim INT_Loop As Integer
  191.  
  192. For INT_Loop = LBound(INT_Array) To UBound(INT_Array)
  193. LST_List.AddItem INT_Loop & vbTab & INT_Array(INT_Loop)
  194. Next INT_Loop
  195.  
  196. End Sub
  197. Function RndInt(ByVal INT_LowNum As Integer, ByVal int_highnum As Integer) As Integer
  198.  
  199. RndInt = Int((int_highnum - INT_LowNum + 1) * Rnd + INT_LowNum)
  200.  
  201. End Function
  202. Private Sub CMD_Exit_Click()
  203. Unload Me
  204. End Sub
  205.  
  206.  
  207. ________________________________________________________________________________________________________
  208.  
  209. Option Explicit
  210. Private Sub Form_Load()
  211.  
  212. Randomize
  213.  
  214. Dim INT_Numbers() As Integer
  215. Dim INT_EvenNumbers() As Integer
  216. Dim INT_OddNumbers() As Integer
  217.  
  218. Call FillArray(INT_Numbers(), 1, 10)
  219. Call DisplayArray(INT_Numbers(), LST_Array)
  220. Call EvenNumbers(INT_Numbers(), INT_EvenNumbers(), LST_Array)
  221. Call OddNumbers(INT_Numbers(), INT_OddNumbers(), LST_Array)
  222.  
  223. End Sub
  224. Sub FillArray(ByRef INT_Array() As Integer, ByVal INT_LowerLimit As Integer, ByVal INT_UpperLimit As Integer)
  225.  
  226. Dim INT_Loop As Integer
  227.  
  228. ReDim INT_Array(INT_LowerLimit To INT_UpperLimit)
  229.  
  230. For INT_Loop = INT_LowerLimit To INT_UpperLimit
  231. INT_Array(INT_Loop) = RndInt(1, 99)
  232. Next INT_Loop
  233.  
  234. End Sub
  235. Sub DisplayArray(ByRef INT_Array() As Integer, ByRef LST_List As ListBox)
  236.  
  237. Dim INT_Loop As Integer
  238.  
  239. For INT_Loop = LBound(INT_Array) To UBound(INT_Array)
  240. LST_List.AddItem INT_Loop & vbTab & INT_Array(INT_Loop)
  241. Next INT_Loop
  242.  
  243. End Sub
  244.  
  245. Sub EvenNumbers(ByRef INT_Array() As Integer, ByRef INT_EvenNumbers() As Integer, LST_List As ListBox)
  246.  
  247. Dim INT_ArrayIndex As Integer
  248. Dim INT_EvenArrayIndex As Integer
  249.  
  250. INT_EvenArrayIndex = 0
  251. INT_ArrayIndex = 1
  252.  
  253. Do While INT_ArrayIndex <= UBound(INT_Array)
  254. If INT_Array(INT_ArrayIndex) Mod 2 = 0 Then
  255. If INT_EvenArrayIndex = 0 Then
  256. ReDim INT_EvenNumbers(INT_EvenArrayIndex)
  257. Else
  258. ReDim Preserve INT_EvenNumbers(INT_EvenArrayIndex)
  259. End If
  260. INT_EvenNumbers(INT_EvenArrayIndex) = INT_Array(INT_ArrayIndex)
  261. INT_EvenArrayIndex = INT_EvenArrayIndex + 1
  262. End If
  263. INT_ArrayIndex = INT_ArrayIndex + 1
  264. Loop
  265.  
  266. LST_List.AddItem "Even numbers in the array"
  267. For INT_EvenArrayIndex = LBound(INT_EvenNumbers) To UBound(INT_EvenNumbers)
  268. LST_List.AddItem INT_EvenNumbers(INT_EvenArrayIndex)
  269. Next INT_EvenArrayIndex
  270.  
  271. End Sub
  272. Sub OddNumbers(ByRef INT_Array() As Integer, ByRef INT_OddNumbers() As Integer, LST_List As ListBox)
  273.  
  274. Dim INT_ArrayIndex As Integer
  275. Dim INT_OddArrayIndex As Integer
  276.  
  277. INT_OddArrayIndex = 0
  278. INT_ArrayIndex = 1
  279.  
  280. Do While INT_ArrayIndex <= UBound(INT_Array)
  281. If INT_Array(INT_ArrayIndex) Mod 2 = 0 Then
  282. If INT_OddArrayIndex = 0 Then
  283. ReDim INT_OddNumbers(INT_OddArrayIndex)
  284. Else
  285. ReDim Preserve INT_OddNumbers(INT_OddArrayIndex)
  286. End If
  287. INT_OddNumbers(INT_OddArrayIndex) = INT_Array(INT_ArrayIndex)
  288. INT_OddArrayIndex = INT_OddArrayIndex + 1
  289. End If
  290. INT_ArrayIndex = INT_ArrayIndex + 1
  291. Loop
  292.  
  293. LST_List.AddItem "Odd numbers in the array"
  294. For INT_OddArrayIndex = LBound(INT_OddNumbers) To UBound(INT_OddNumbers)
  295. LST_List.AddItem INT_OddNumbers(INT_OddArrayIndex)
  296. Next INT_OddArrayIndex
  297.  
  298. End Sub
  299. Function RndInt(ByVal INT_LowNum As Integer, ByVal INT_HighNum As Integer) As Integer
  300.  
  301. RndInt = Int((INT_HighNum - INT_LowNum + 1) * Rnd + INT_LowNum)
  302.  
  303. End Function
  304. Private Sub CMD_Done_Click()
  305.  
  306. Unload Me
  307.  
  308. End Sub
  309.  
  310.  
  311. ________________________________________________________________________________________________________
  312.  
  313.  
  314. Option Explicit
  315. Private Sub Form_Load()
  316.  
  317. Dim INT_ScoreCard(1 To 4, 1 To 18) As Integer
  318. Dim LNG_Row As Long
  319. Dim LNG_Col As Long
  320. Dim STR_RowScore As String
  321.  
  322. Randomize
  323.  
  324. Call Reset
  325.  
  326. For LNG_Col = LBound(INT_ScoreCard, 2) To UBound(INT_ScoreCard, 2)
  327. For LNG_Row = LBound(INT_ScoreCard, 1) To UBound(INT_ScoreCard, 1)
  328. INT_ScoreCard(LNG_Row, LNG_Col) = Int(9 * Rnd + 1)
  329. Next LNG_Row
  330. Next LNG_Col
  331.  
  332. Call DisplayScorecard(INT_ScoreCard())
  333. Call CalculateWinners(INT_ScoreCard())
  334.  
  335. End Sub
  336. Private Sub Reset()
  337.  
  338. Dim INT_Row As Integer
  339.  
  340. For INT_Row = 1 To 4
  341. LBL_PlayerScore(INT_Row).Caption = ""
  342. Next INT_Row
  343.  
  344. LST_Scores.Clear
  345.  
  346. End Sub
  347. Private Sub DisplayScorecard(ByRef INT_ScoreCard() As Integer)
  348.  
  349. Dim LNG_Row As Long
  350. Dim LNG_Col As Long
  351. Dim STR_RowScore As String
  352.  
  353. LST_Scores.AddItem vbTab & "Hole 1" & vbTab & "Hole 2" & vbTab & "Hole 3" & vbTab & "Hole 4" & vbTab & "Hole 5" & vbTab & "Hole 6" & vbTab & "Hole 7" & vbTab & "Hole 8" & vbTab & "Hole 9" & vbTab & "Hole 10" & vbTab & "Hole 11" & vbTab & "Hole 12" & vbTab & "Hole 13" & vbTab & "Hole 14" & vbTab & "Hole 15" & vbTab & "Hole 16" & vbTab & "Hole 17" & vbTab & "Hole 18"
  354.  
  355. For LNG_Row = LBound(INT_ScoreCard, 1) To UBound(INT_ScoreCard, 1)
  356. STR_RowScore = ""
  357. For LNG_Col = LBound(INT_ScoreCard, 2) To UBound(INT_ScoreCard, 2)
  358. STR_RowScore = STR_RowScore & INT_ScoreCard(LNG_Row, LNG_Col) & vbTab
  359. Next LNG_Col
  360. LST_Scores.AddItem "Player " & LNG_Row & vbTab & STR_RowScore
  361. Next LNG_Row
  362.  
  363. End Sub
  364. Private Sub CalculateWinners(ByRef INT_ScoreCard() As Integer)
  365.  
  366. Dim LNG_Row As Long
  367. Dim LNG_Col As Long
  368. Dim INT_LowScore As Integer
  369. Dim INT_WinnerRow As Integer
  370.  
  371. For LNG_Col = LBound(INT_ScoreCard, 2) To UBound(INT_ScoreCard, 2)
  372. INT_LowScore = 9
  373. For LNG_Row = LBound(INT_ScoreCard, 1) To UBound(INT_ScoreCard, 1)
  374. If INT_LowScore > INT_ScoreCard(LNG_Row, LNG_Col) Then
  375. INT_LowScore = INT_ScoreCard(LNG_Row, LNG_Col)
  376. INT_WinnerRow = LNG_Row
  377. End If
  378. Next LNG_Row
  379. LBL_PlayerScore(INT_WinnerRow).Caption = LBL_PlayerScore(INT_WinnerRow).Caption & Space(2) & "Hole " & LNG_Col
  380. Next LNG_Col
  381.  
  382. End Sub
  383. Private Sub CMD_Exit_Click()
  384.  
  385. Unload Me
  386.  
  387. End Sub
  388.  
  389. _______________________________________________________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement