Google
 

it » comp » appl » access

Contare record in file di testo

di "santommaso"
il Mon, 9 Jul 2007 17:33:24 +0200
newsgroups it.comp.appl.access
message-id <f6t1r3$9kp$1@nnrp.ngi.it>

Ciao a tutti.
Ho l'esigenza di contare velocemente  i record presenti in un grosso file di 
testo.
ho utilizzato il seguente metodo, seguendo i consigli dati in un post di 
qualche tempo fa.

---------------------------------------------------------
Option Compare Database
Option Explicit
Private Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long

Private Declare Function apiGetFocus Lib "user32" _
        Alias "GetFocus" _
         () As Long

Private Const EM_GETLINECOUNT = &HBA

****

Function fhWnd(ctl As Control) As Long
    On Error Resume Next
    ctl.SetFocus
    If Err Then
        fhWnd = 0
    Else
        fhWnd = apiGetFocus
    End If
    On Error GoTo 0
End Function

****

Private Sub Tasto_Click()
 Dim fno As Integer
    Dim fname As String
    Dim cnt As Integer
    Dim lineCount As Long
    Dim hwndCtl As Long
    On Local Error Resume Next

    'load the file into the textbox
    fname = "c:\testo.txt"
    fno = FreeFile    <- questo l'ho aggiunto io altrimenti la casella di 
testo non si riempiva
    Open fname For Input As #fno
        Me!Text1 = Input$(LOF(fno), fno)
    Close #fno

    hwndCtl = fhWnd(Me!Text1)

   'get/show the number of lines in the edit control
    lineCount = SendMessage(hwndCtl, EM_GETLINECOUNT, ByVal 0&, 0&)
    MsgBox "Numero linee = " & Format$(lineCount, "##,###")
end sub
------------------------------------------------------------------------------------------------------------

la casella di testo non si riempiva e ci sono riuscito aggiungendo la riga:
fno=FreeFile

il punto è che linecount è sempre = 0

Utilizzo Access 2002

Qualcuno ha qualche consiglio per venirne fuori?


Grazie 1000
Roberto 


Risposte

Tutti i messaggi della discussione