Global pw As New clsLibhllapi Global sString As String Global sString2 As String Sub BuscaDados49() Dim LinhaT, LinhaP, LinhaD As Integer If pw.Connect = False Then Call SemTelaInicial Set pw = Nothing Exit Sub End If Load frmLogin frmLogin.Show pw.WaitExec pw.SendKeys ("49<ENTER>") pw.WaitExec pw.WaitForString "Usuario", 16, 5, 30 Do senhaerrada = True 'Inicializa novamente para caso tenha voltado novamente pw.SendKeys ("<HOME>") pw.WaitExec pw.SendKeys ("<TAB>") pw.SendKeys (sString2) pw.WaitExec pw.SendKeys ("<ENTER>") pw.WaitExec If pw.GetString(23, 5, 15) = "SENHA INCORRETA" Then ThisWorkbook.Application.Visible = True sString2 = "" If MsgBox("SENHA inválida ou USUÁRIO não cadastrado.Gostaria de tentar novamente?", vbOKCancel, "A T E N Ç Ã O!") = vbCancel Then ' TOMAZ pw.SendKeys ("<PF3>") Else pw.SendKeys ("<PF3>") Exit Do End If ElseIf pw.GetString(23, 5, 12) = "VOCE JA ESTA" Then nada = MsgBox("Você já está logado no 5.41 em outro RedeCaixa" & Chr(13) & "Saia e tente novamente", vbCritical, "A T E N Ç Ã O!") pw.SendKeys ("<PF3>") Else senhaerrada = False End If Loop While (pw.GetString(12, 29, 7) = "SISTEMA") pw.WaitExec ' ' AQUI COMEÇA A MÁGICA DE VERDADE ' ' Enquanto Linha 2, Coluna 71, Comprimento 8 não for NA00MM01, faça: While Not pw.GetString(2, 71, 8) = "NA00MM01" ' Se linha 2, coluna 71, tamanho 8 caracteres for diferente de NA00MM01, teclar Enter. If pw.GetString(2, 71, 8) <> "NA00MM01" Then pw.WaitExec pw.SendKeys ("<ENTER>") pw.WaitExec End If ' Mover cursor para Linha 22, Coluna 73 pw.MoveTo 22, 73 pw.WaitExec Wend ' Envia a string "LOTA,C" pw.SendKeys ("LOTA,C") pw.WaitExec ' Tecla Enter pw.SendKeys ("<ENTER>") pw.WaitExec ' Espera aparecer LT50 na Linha 2, Coluna 71 pw.WaitForString "LT50", 2, 71, 30 pw.WaitExec ' Linha inicial da planilha Agencias LinhaP = 2 ' Linha inicial da planilha Dados LinhaD = 2 ' Linha inicial do PW3270 LinhaT = 7 'Enquanto existir dados na linha especificada da coluna A da planilha Agencias, fazer: While (Sheets("Agencias").Range("a" & LinhaP).value <> "") pw.WaitExec ' Enviar no PW3270 o texto da linha especificada, da coluna A, da planilha Agencias pw.SendKeys Sheets("Agencias").Range("a" & LinhaP).value pw.WaitExec ' Teclar ENTER pw.SendKeys ("<ENTER>") pw.WaitExec ' Para as linhas 7 a 18 do PW3270, faça: For LinhaT = 7 To 18 'Apresentar no terminal do app do VBA Debug.Print pw.GetString(LinhaT, 6, 6) 'Se linha especificada, da coluna 6 com comprimento 6 for " ", finalizar o FOR (loops) If pw.GetString(LinhaT, 6, 6) = " " Then Exit For 'Adicionar na planilha Dados: 'Copiar da tabela agências, Linha especificada, Coluna A. Colar na tabela Dados, Linha especificada, Coluna A, removendo espaços e formatando como "0000". Sheets("Dados").Cells(LinhaD, "A") = Trim(Format(Sheets("Agencias").Range("a" & LinhaP).value, "0000")) 'Código Agência 'Definir valor do PW3270, Linha especificada, Coluna 6, Comprimento 8. Na tabela Dados, Linha especificada, Coluna B. Sheets("Dados").Cells(LinhaD, "B") = Trim(pw.GetString(LinhaT, 6, 8)) ' Matricula 'Definir valor do PW3270, Linha especificada, Coluna 17, Comprimento 38. Na tabela Dados, Linha especificada, Coluna C. Sheets("Dados").Cells(LinhaD, "C") = Trim(pw.GetString(LinhaT, 17, 38)) ' Nome pw.SendKeys ("<pf11>") pw.WaitExec 'Definir valor do PW3270, Linha especificada, Coluna 17, Comprimento 38. Na tabela Dados, Linha especificada, Coluna C. Sheets("Dados").Cells(LinhaD, "D") = Trim(pw.GetString(LinhaT, 21, 12)) ' FC/CCO EFETIVO 'Definir valor do PW3270, Linha especificada, Coluna 17, Comprimento 38. Na tabela Dados, Linha especificada, Coluna C. Sheets("Dados").Cells(LinhaD, "E") = Trim(pw.GetString(LinhaT, 41, 12)) ' FC/CCO Eventual pw.SendKeys ("<pf10>") pw.WaitExec 'Se linha especificada no PW3270 for igual a 18, então: If LinhaT = 18 Then ' *função CDbl converte um valor para double ' Verifica se a página atual é menor que a página total, se sim, passar para próxima página If CDbl(pw.GetString(4, 71, 3)) < CDbl(pw.GetString(4, 76, 3)) Then ' Resetar variável para linha inicial da tabela LinhaT = 6 ' Passar para próxima página pw.SendKeys ("<pf8>") pw.WaitExec End If End If 'Passar para a próxima linha utilizada nas tabelas Dados 'E passar para o próximo loop para pegar os dados da próxima linha do PW3270 LinhaD = LinhaD + 1 Next ' Terminado de pegar as linhas da página, apertar tecla PF3 pw.SendKeys ("<pf3>") pw.WaitExec ' Passar para a próxima agência, caso termine as agências, será finalizado o while ' Que provávelmente verificava os empregados de cada agência LinhaP = LinhaP + 1 'pw.WaitForString " LT50", 2, 71 Wend pw.SendKeys ("<PF12>") pw.WaitExec MsgBox " FIM, DADOS CAPTURADOS, confira na planilha Dados." End Sub Public Sub SemTelaInicial() nada = MsgBox(" * * * A T E N Ç Ã O * * *" & Chr(13) & _ Chr(13) & _ Chr(13) & _ "NÃO EXISTE UM REDECAIXA (PW com certificado digital) ABERTO NA TELA INCIAL." & Chr(13) & Chr(13) & _ " ABRA UM NOVO REDE CAIXA - pw3270 NA TELA INICIAL(SEM SISTEMA)" & Chr(13) & _ " E TENTE NOVAMENTE", vbCritical, "Verificação do Extra") ThisWorkbook.Application.Visible = True End Sub Public Sub VerTelaInicial() Do While (InStr(pw.GetString(17, 10, 40), "SELECIONE") + InStr(pw.GetString(15, 5, 65), "SISTEMAS")) = 0 'Do While (InStr(pw.GetString(17, 1, 80), "SELECIONE") + InStr(pw.GetString(17, 1, 80), "S E L E C I O N E")) = 0 'Do While (InStr(pw.GetString(17, 30, 10), "==>") = 0) ' FAz enquanto NÃO ENCONTRAR O texto da tela inicial nada = MsgBox("* * * * * * * * * * A T E N Ç Ã O * * * * * * * * * * " & Chr(13) & _ Chr(13) & _ "O SEU REDECAIXA ESTÁ LOGADO MAS NÃO ESTÁ ABERTO NA TELA INCIAL." & Chr(13) & Chr(13) & _ " MAXIMIZE A JANELA DO REDECAIXA E VÁ PARA A TELA INICIAL(SEM SISTEMA)" & Chr(13) & Chr(13) & _ " APÓS ISSO, DÊ OK PARA CONTINUAR", vbCritical, "Verificação do PW") ThisWorkbook.Application.Visible = True Loop End Sub
Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net
. OneCompiler also has reference programs, where you can look for the sample code to get started with.
OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.
Public Module Program
Public Sub Main(args() As string)
Dim name as String = Console.ReadLine() ' Reading input from STDIN
Console.WriteLine("Hello " & name) ' Writing output to STDOUT
End Sub
End Module
Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.
Variable is a name given to the storage area in order to identify them in our programs.
Simple syntax of Variable declaration is as follows
Dim variableName [ As [ New ] dataType ] [ = initializer ]
variableName = value
If condition-expression Then
'code
End If
If(conditional-expression)Then
'code if the conditional-expression is true
Else
'code if the conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
Else If(conditional-expression) Then
'code if the above conditional-expression is true
Else
'code if the above conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
If(conditional-expression)Then
'code if the above conditional-expression is true
End If
End If
Select [ Case ] expression
[ Case expressionlist
'code ]
[ Case Else
'code ]
End Select
For counter [ As datatype ] = begin To end [ Step step ]
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ counter ]
For Each element [ As datatype ] In group
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ element ]
While conditional-expression
'Code
[ Continue While ]
'Code
[ Exit While ]
'Code
End While
Do { While | Until } conditional-expression
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop
Do
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop { While | Until } conditional-expression
Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Procedures are of two types.
Functions return a value when they are called.
[accessModifiers] Function functionName [(parameterList)] As returnType
'code
End Function
Sub-procedures are similar to functions but they don't return any value.
Sub ProcedureName (parameterList)
'Code
End Sub