negralince Posted December 17, 2012 Report Share Posted December 17, 2012 tenho esse código mas não sei como linkar ele com o comando. Preciso retirar informações de um arquivo em txt e exibir num form, com uma caixa combobox de meses do ano: Public Sub Command1_Click() Dim linha, data1, data2 As String ReDim dia(500) As String ReDim cracha(500) As String ReDim hora(500) As String ReDim codigo(500) As String Dim mes(12) As String ReDim ano(50) As String Dim mes As New arraylist With mes Add.New mes = "Janeiro", 1 Add.New mes = "fevereiro", 2 Add.New mes = "Março", 3 Add.New mes = "Abril", 4 Add.New mes = "Maio", 5 Add.New mes = "Junho", 6 Add.New mes = "Julho", 7 Add.New mes = "Agosto", 8 Add.New mes = "Setembro", 9 End With 'vincula o vetor ao controle Combo Box With ComboBox1 .DataSource = mes .DisplayMember = "getName" .ValueMember = "getId" End With x = 0 Open "C:\ABONO09.txt" For Input As #1 Line Input #1, linha Do While Not EOF(1) If UCase(Mid(linha, 34, 11)) = "OCORRENCIAS" Then data1 = Mid(linha, 60, 8) data2 = Mid(linha, 71, 8) Print "Data: "; data1; " à "; data2 ' quero q exiba a data uma vez só End If Line Input #1, linha If UCase(Mid(linha, 12, 1)) = ":" Then cracha(x) = Mid(linha, 14, 8) Print "Cracha: "; cracha(x) End If If UCase(Mid(linha, 72, 1)) = ":" Then dia(x) = Mid(linha, 1, 2) Print "Dia: "; dia(x); "/"; " "; "/"; " "; Spc(3); End If If UCase(Mid(linha, 72, 1)) = ":" Then hora(x) = Mid(linha, 70, 5) Print "Hora: "; hora(x); " "; Spc(2); End If If UCase(Mid(linha, 72, 1)) = ":" Then codigo(x) = Mid(linha, 77, 3) Print "Código: "; codigo(x) End If x = x + 1 ' indice do proximo elemento Loop Close #1 End Sub Link to comment Share on other sites More sharing options...
acao Posted December 17, 2012 Report Share Posted December 17, 2012 (edited) boas passe por aqui talvez ajude. http://www.portugal-a-programar.pt/topic/57420-ler-ficheiro-com-varias-linhas/ cumps acao Edited December 17, 2012 by acao Link to comment Share on other sites More sharing options...
negralince Posted January 14, 2013 Author Report Share Posted January 14, 2013 Private Sub Combo1_Change() End Sub Public Sub Command1_Click() Dim linha, data1, data2 As String ReDim dia(500) As String ReDim cracha(500) As String ReDim hora(500) As String ReDim codigo(500) As String Dim mes(12) As String ReDim ano(50) As String Dim tot As Integer 'linha Christian: variável criada pelo christian para armazenar a quantidade de vezes q ele encontrou a palavra "ocorrências" x = 0 Open "C:\ABONO09.txt" For Input As #1 Line Input #1, linha Do While Not EOF(1) If UCase(Mid(linha, 34, 11)) = "OCORRENCIAS" Then data1 = Mid(linha, 60, 8) data2 = Mid(linha, 71, 8) tot = tot + 1 'linha Christian: variável + 1 para passar pra próxima linha If tot = 1 Then 'linha Christian: se a linha for igual a 1 ele printa senão ele ignora. Print "Data: "; data1; " à "; data2; vbCrLf ' para pular uma linha End If End If Line Input #1, linha If UCase(Mid(linha, 12, 1)) = ":" Then cracha(x) = Mid(linha, 14, 8) Print "Cracha: "; cracha(x) End If If UCase(Mid(linha, 72, 1)) = ":" Then dia(x) = Mid(linha, 1, 2) Print "Dia: "; dia(x); "/"; " "; "/"; " "; Spc(3); End If If UCase(Mid(linha, 72, 1)) = ":" Then hora(x) = Mid(linha, 70, 5) Print "Hora: "; hora(x); " "; Spc(2); End If If UCase(Mid(linha, 72, 1)) = ":" Then codigo(x) = Mid(linha, 77, 3) Print "Código: "; codigo(x) End If x = x + 1 ' indice do proximo elemento Loop Close #1 End Sub Public Sub Form_Load() 'exibir as informações após o ok mes.AddItem "janeiro" mes.AddItem "Fevereiro" mes.AddItem "Março" mes.AddItem "Abril" mes.AddItem "Maio" mes.AddItem "Junho" mes.AddItem "Julho" mes.AddItem "Agosto" mes.AddItem "Setembro" End Sub Gente como faço pra linkar o subforload do mês? Link to comment Share on other sites More sharing options...
acao Posted January 14, 2013 Report Share Posted January 14, 2013 boas Call Form_Load cumps acao Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now