Guest User

Untitled

a guest
Oct 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  2. Function conexao()
  3.  
  4. Dim cn As ADODB.Connection
  5. Set cn = New ADODB.Connection
  6. Dim sql As String
  7. Dim hora As Date
  8. Dim hora_banco As String
  9. Dim total As Integer
  10. Dim s As String
  11. Dim hora_Inicial As Date
  12. Dim Hora_final As Date
  13. Dim strConn As String
  14.  
  15. 'Atribui horas inicias e finais para as variaveis
  16.  
  17. hora_Inicial = TimeValue("8:00:00")
  18. Hora_final = TimeValue("18:00:00")
  19. 'Pega a hora do sistema
  20.  
  21. hora = TimeValue(Time())
  22.  
  23. ' faz a conexao com o banco
  24. strConn = "Driver={SQL Server};Server=d1736368;Database=DB_CONSIGNADO_ESPECIFICO"
  25. 'abre a conexao
  26. cn.Open strConn
  27. 'Cria o objeto Recordset
  28. Dim rs, a As ADODB.Recordset
  29. Set rs = New ADODB.Recordset
  30. Set a = New ADODB.Recordset
  31. 'pega a hora do sistema
  32. hora = Time()
  33.  
  34.  
  35. Do Until hora_Inicial >= Hora_final
  36. DoEvents
  37.  
  38. Application.Wait (Now + TimeValue("00:00:02"))
  39. 'faz o select no banco de dados e converte para hora
  40. sql = "SELECT top 1 Convert(Char(8),GetDate(),114),(DT_SISTEMA) FROM T_PROPOSTA_FILHOTE"
  41. 'printa o valor das variaveis
  42. Debug.Print hora
  43. Debug.Print sql
  44.  
  45. 'inicia o bloco with com a varivale rs
  46. With rs
  47. .ActiveConnection = cn
  48. .Open sql
  49. Plan1.Range("A2").CopyFromRecordset rs
  50. .Close
  51. End With
  52. 'recebe o ultima atualizacao de hora do banco
  53. hora_banco = CDate(Range("A2").Value)
  54. total = hora - (hora_banco = CDate(Range("A2").Value))
  55. Debug.Print total
  56.  
  57. If total >= 5 Then
  58.  
  59. s = Shell("C:testeReinicia_Robo.bat", vbNormalFocus)
  60.  
  61. End If
  62.  
  63. DoEvents
  64.  
  65. Loop
  66. 'fecha a conexao
  67. cn.Close
  68. Set rs = Nothing
  69. Set cn = Nothing
  70.  
  71. End Function
  72.  
  73. TempoEspera = Now() + TimeValue("00:00:10")
  74. While Now() < TempoEspera
  75. DoEvents
  76. Wend
  77.  
  78. #If VBA7 Then
  79. Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) '64 Bit
  80. #Else
  81. Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds as Long) '32 Bit
  82. #End If
Add Comment
Please, Sign In to add comment