Pavle_nis

SLAGALICA KVIZ

Nov 30th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Attribute VB_Name = "Form1"
  2. Attribute VB_GlobalNameSpace = False
  3. Attribute VB_Creatable = False
  4. Attribute VB_PredeclaredId = True
  5. Attribute VB_Exposed = False
  6. Dim Conn        As New ADODB.Connection
  7. Dim i           As Long
  8. Dim slova(11)   As String
  9. Dim rec         As String
  10. Dim proteklo    As Long
  11. Dim korisceno   As String
  12. Dim lastLen     As Long
  13. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  14.     If KeyCode = 32 And Shift = 0 Then Call lblStartStop_Click
  15. End Sub
  16. Private Sub Form_Load()
  17.     Conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\" & "slagalica.mdb" & ";Persist Security Info=False")
  18.     Randomize
  19.     Me.Show
  20.     DoEvents
  21.     Call lblNova_Click
  22. End Sub
  23.  
  24. Private Sub lblIzlaz_Click()
  25.     Unload Me
  26. End Sub
  27. Private Sub lblNova_Click()
  28.     Dim rs      As New ADODB.Recordset
  29.     Dim n       As Long
  30.     Dim duzina  As Long
  31.     Dim tmp     As String
  32.     Dim ascii   As Long
  33.    
  34.     lblStartStop.Caption = "Start": Timor.Enabled = False
  35.     lblStartStop.Enabled = False
  36.    
  37.     txtInput.Text = "": txtNajduza.Text = ""
  38.     txtInput.Enabled = False
  39.    
  40.     duzina = getRandom(8, 12)
  41.     Call rs.Open("SELECT DISTINCT Reci FROM " & CStr(duzina), Conn, adOpenKeyset)
  42.     rs.Move getRandom(0, rs.RecordCount - 1)
  43.     rec = rs.Fields(0).Value
  44.     tmp = UCase$(rec)
  45.    
  46.     Do While Not Len(tmp) = 12
  47.         ascii = getRandom(65, 90)
  48.         Do While Not (ascii <> Asc("W") And ascii <> Asc("X") And ascii <> Asc("Q"))
  49.             ascii = getRandom(65, 90)
  50.         Loop
  51.         tmp = tmp & Chr$(ascii)
  52.     Loop
  53.    
  54.     For n = 0 To 11
  55.         lblSlovo(n).Caption = ""
  56.         slova(n) = Mid$(tmp, n + 1, 1)
  57.     Next
  58.    
  59.     shuffleArray slova
  60.     picSlova.SetFocus
  61.    
  62.     picProgres.Width = 0
  63.     proteklo = 0
  64.     lblPoeni.Caption = "0"
  65.     korisceno = ":"
  66.    
  67.     lblStartStop.Enabled = True
  68.    
  69. End Sub
  70.  
  71. Private Sub lblStartStop_Click()
  72.     If Not lblStartStop.Enabled Then Exit Sub
  73.     If lblStartStop.Caption = "Start" Then
  74.         i = 0
  75.         Timor.Enabled = True
  76.         lblStartStop.Caption = "Stop"
  77.         lblStartStop.Enabled = True
  78.     Else
  79.         lblSlovo(i).Caption = slova(i)
  80.         i = i + 1
  81.         If i = 12 Then
  82.             txtInput.Enabled = True
  83.             lblStartStop.Enabled = False
  84.             lblStartStop.Caption = "Start"
  85.             Timor.Enabled = False
  86.             Vreme.Enabled = True
  87.             txtInput.SetFocus
  88.         End If
  89.     End If
  90. End Sub
  91. Private Sub Timor_Timer()
  92.     Dim ascii As Long
  93.    
  94.     ascii = getRandom(65, 90)
  95.     Do While Not (ascii <> Asc("W") And ascii <> Asc("X") And ascii <> Asc("Q"))
  96.         ascii = getRandom(65, 90)
  97.     Loop
  98.    
  99.     lblSlovo(i).Caption = Chr$(ascii)
  100.     DoEvents
  101. End Sub
  102. Private Sub Vreme_Timer()
  103.     proteklo = proteklo + 1
  104.     picProgres.Width = (proteklo / 60) * picVreme.ScaleWidth
  105.     If proteklo = 60 Then
  106.         txtNajduza.Text = rec
  107.         setInfo "Vreme je isteklo."
  108.         proteklo = 0
  109.         Vreme.Enabled = False
  110.         txtInput.Enabled = False
  111.     End If
  112.     DoEvents
  113. End Sub
  114. Private Sub txtInput_KeyPress(KeyAscii As Integer)
  115.     Dim n       As Long
  116.     Dim ima     As Boolean
  117.     Dim r       As String
  118.     Dim rs      As New Recordset
  119.    
  120.     If KeyAscii > 96 And KeyAscii < 123 Then KeyAscii = KeyAscii - 32
  121.     If KeyAscii < 65 Or KeyAscii > 90 Then
  122.         If KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete Then Exit Sub
  123.         If KeyAscii = vbKeyReturn Then
  124.             Vreme.Enabled = False
  125.             r = txtInput.Text
  126.            
  127.             If Len(r) < 2 Then
  128.                 setInfo "Takva rec ne postoji."
  129.                 lblPoeni.Caption = "0"
  130.                 GoTo proc_exit
  131.             End If
  132.            
  133.             Set rs = Conn.Execute("SELECT DISTINCT Reci FROM " & CStr(Len(r)))
  134.            
  135.             ima = False
  136.             Do While Not rs.EOF
  137.                 If UCase$(rs.Fields(0).Value) = r Then
  138.                     ima = True
  139.                     Exit Do
  140.                 End If
  141.                 rs.MoveNext
  142.             Loop
  143.            
  144.             If ima Then
  145.                 lblPoeni = 10 * Len(r) - Round(((picProgres.Width / picVreme.ScaleWidth) * 60))
  146.                 setInfo "Prihvatamo vasu rec."
  147.             Else
  148.                 lblPoeni.Caption = "0"
  149.                 setInfo "Takva rec ne postoji."
  150.             End If
  151.            
  152.             picProgres.Width = 0
  153.            
  154. proc_exit:
  155.             txtNajduza.Text = UCase$(rec)
  156.         End If
  157.         KeyAscii = 0
  158.     Else
  159.         Dim k As Long
  160.         k = 0
  161. tryAgain:
  162.         ima = False
  163.         For n = k To 11
  164.             If KeyAscii = Asc(slova(n)) Then
  165.                 ima = True
  166.                 If InStr(1, korisceno, ":" & n & ":") > 0 Then
  167.                     k = n + 1
  168.                     GoTo tryAgain
  169.                 Else
  170.                    korisceno = korisceno & n & ":"
  171.                 End If
  172.                 Exit For
  173.             End If
  174.         Next
  175.         If Not ima Then KeyAscii = 0
  176.     End If
  177. End Sub
  178. Private Sub txtInput_Change()
  179.     Dim n   As Long
  180.     Dim k   As Long
  181.     Dim l   As Long
  182.     Dim tmp As String
  183.    
  184.     If Len(txtInput.Text) < lastLen Then
  185.         korisceno = ":"
  186.         For n = 1 To Len(txtInput.Text)
  187.             tmp = Mid$(txtInput.Text, n, 1)
  188.             l = 0
  189. findNext:
  190.             For k = l To 11
  191.                 If tmp = slova(k) Then
  192.                     If InStr(1, korisceno, ":" & k & ":") > 0 Then
  193.                         l = k + 1
  194.                         GoTo findNext
  195.                     Else
  196.                         korisceno = korisceno & k & ":"
  197.                         Exit For
  198.                     End If
  199.                 End If
  200.             Next
  201.         Next
  202.     Else
  203.         lastLen = Len(txtInput.Text)
  204.     End If
  205.  
  206. End Sub
  207. Private Sub infoTimer_Timer()
  208.     infoTimer.Enabled = False
  209.     lblInfo.Caption = ""
  210. End Sub
  211. Sub setInfo(inf As String)
  212.     lblInfo.Caption = inf
  213.     infoTimer.Enabled = True
  214. End Sub
  215. Function getRandom(min As Long, max As Long) As Long
  216.     getRandom = CLng(Int((max - min + 1) * Rnd + min))
  217. End Function
  218. Sub shuffleArray(inArray() As String)
  219.     Dim n       As Long
  220.     Dim k       As Long
  221.     Dim tmp     As Variant
  222.    
  223.     For n = LBound(inArray) To UBound(inArray)
  224.         k = getRandom(LBound(inArray), UBound(inArray))
  225.         tmp = inArray(n)
  226.         inArray(n) = inArray(k)
  227.         inArray(k) = tmp
  228.     Next
  229.  
  230. End Sub
Advertisement
Add Comment
Please, Sign In to add comment