Visualizzazione dei risultati da 1 a 5 su 5

Discussione: [VB6] Creazione LOG

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2005
    Messaggi
    89

    [VB6]Creazione LOG

    Salve a tutti,
    ho un'applicazione che preleva da un sito internet dei files .xml...e fin qui tutto ok! Ora ho bisogno di aggiungere a questo progetto una ListView che funga da Log. Tale finestra deve contenere il nome del file che non è stato trovato sul sito, e quindi non caricato correttamente.

    Se un file non è presente, viene ugualmente creato un xml nel quale ci sono alcuni messaggi di errore, tra cui 'HTTP Error 404...' ; dunque ricerco nel generico file questo stringa, se la trovo il file non è stato trovato sul sito e quindi aggiungo una riga al log.
    Il problema è...che non funziona perchè mi dice di trovare il file!!

    Potete aiutarmi? Sto impazzendo! vi posto il codice:

    codice:
    'dichiara una variabile per il corrente URL
    Dim percorso As String
    Dim mercati As String
    Dim data_inizio As Date
    Dim data_fine As Date
    Dim data_corrente As Date
    Dim nome_file As String
    Dim strdt As String
    Dim strUrl As String
     
    Private Sub Command1_Click()
    Dim elementi As ListItem
    Dim intestazione As ColumnHeaders
    Dim strPercorsoLog As String
     
    MousePointer = vbHourglass
    DoEvents
    mercati = Combo1
    data_inizio = DTPicker1
    data_fine = DTPicker2
    data_corrente = data_inizio
    While (data_corrente <= data_fine)
    strdt = data_corrente
    percorso = mercati + strdt
    strUrl= "http://www.mercatoelettrico.org/GmewebItaliano/WebServerDataStore/" + gunnellabug(percorso) + ".xml"
    Label1.Caption = strUrl
     
    Open nome_file For Input As #1
                While Not EOF(1)
                    Line Input #1, strUrl
                    If InStr(1, Trim(UCase(strUrl)), "HTTP Error 404 - File or directory not found.") <> 0 Then
                        Set elementi = lstFileLOG.ListItems.Add(, , nome_file)
     
                    End If
                Wend
                Close #1
                DoEvents
     
    'CommonDialog1.DefaultExt = "XML"
    'CommonDialog1.Filter = "XML files (*.XML;*.XML)|*.XML;XML"
    'CommonDialog1.ShowSave             'visualizza la finestra di dialogo Salva
    'If CommonDialog1.FileName <> "" Then
     
    
        Open "D:\" + nome_file For Output As #1
        
        '"\\aupadb01\gme_xml\" + nome_file For Output As #1
        
        'CommonDialog1.FileName
        
        Print #1, Inet1.OpenURL(strUrl)    'salva la stringa nel file
        Close #1                           'chiude il file
     
    'Else
     '   MsgBox "Nome del File Non Valido!", vbExclamation + vbOKOnly, "ATTENZIONE..."
    'End If
     
    data_corrente = data_corrente + 1
    Wend
    MsgBox "Download effettuato"
    End
    MousePointer = vbNormal
    DoEvents
    End Sub
    Private Sub Command2_Click()
    Unload Me
    End Sub
    Private Sub Form_Load()
    Combo1.AddItem "MGP_Prezzi"
    Combo1.AddItem "MGP_Quantita"
    Combo1.AddItem "MGP_Fabbisogno"
    Combo1.AddItem "MA1_Prezzi"
    Combo1.AddItem "MA1_Quantita"
    Combo1.AddItem "MSD_ServiziDispacciamento"
    Combo1.AddItem "MB_ServiziDispacciamento"
     
    End Sub
     
    'funzione che permette di salvare i file nel formato numerico
    Public Function gunnellabug(formina As String) As String
    'dichiarazione variabili
    Dim val As String
    Dim risultato_mercato As String
    Dim posizione_mercato As String
    Dim posizione_attributo As String
    Dim risultato_attributo As String
    Dim lungtot As String
    Dim data_estratta As String
    Dim strdata As String 'data finale composta dall'unione dei singoli pezzetti
     
    'assoccio la stringa da valutare
    val = formina
     
    'conto i caratteri che compongono la mia stringa
    posizione_mercato = InStr(val, "_") 'posizione mercati
    If (posizione_mercato = 3) Then
        risultato_mercato = Mid(val, 1, 2) ' MGP,MA1
        posizione_attributo = InStr(val, "/") 'posizione attributo
        risultato_attributo = Mid(val, 4, posizione_attributo - 6) 'Prezzi,quantità,fabbisogno
    Else
        risultato_mercato = Mid(val, 1, 3) ' MGP,MA1
        posizione_attributo = InStr(val, "/") 'posizione attributo
        risultato_attributo = Mid(val, 5, posizione_attributo - 7) 'Prezzi,quantità,fabbisogno
    End If
     
    lungtot = InStr(val, "2005")
    data_estratta = Mid(val, lungtot + 4 - 10)
    strdata = Mid(data_estratta, 7, 4) + Mid(data_estratta, 4, 2) + Mid(data_estratta, 1, 2)
    nome_file = strdata + risultato_mercato + risultato_attributo + ".xml"
    'compongo la stringa finale codificata numericamente
    gunnellabug = risultato_mercato + "_" + risultato_attributo + "/" + strdata + risultato_mercato + risultato_attributo
     
    End Function
    Grazie in anticipo

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Due commenti ...

    1) Non capisco quando scrivi "... Il problema è...che non funziona perchè mi dice di trovare il file!! ..."

    2) Nella Instr, se trasformi in maiuscolo tutta la stringa in cui cercare con la UCase, non potrai mai trovare stringhe in cui ci sono caratteri minuscoli ...

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2005
    Messaggi
    89
    Scusami, il problema è che dice di NON trovare il file....
    Giustissimo il fatto della Ucase...ma non funzia ancora

  4. #4
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Scusa ... ma che senso ha la

    Open nome_file ...

    se nella stringa nome_file non c'e' nulla ?

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2005
    Messaggi
    89
    Grazie uguale Oregon, ho risolto....mando il codice per i posteri:

    codice:
    'dichiara una variabile per il corrente URL
    Dim percorso As String
    Dim mercati As String
    Dim data_inizio As Date
    Dim data_fine As Date
    Dim data_corrente As Date
    Dim nome_file As String
    Dim strdt As String
    Dim strUrl As String
    Private Sub Command1_Click()
    Dim Elementi As ListItem
    Dim Intestazione As ColumnHeader
    Dim strPercorsoLog As String
    Dim blnElimina As Boolean
    
    MousePointer = vbHourglass
    DoEvents
    
    Me.lstFileLOG.ColumnHeaders.Clear
    Me.lstFileLOG.ListItems.Clear
    
    blnElimina = False
    Set Intestazione = Me.lstFileLOG.ColumnHeaders.Add(, , "XML non presenti", 20000)
    
    DoEvents
    mercati = Combo1
    data_inizio = DTPicker1
    data_fine = DTPicker2
    data_corrente = data_inizio
    
    While (data_corrente <= data_fine)
        blnElimina = False
        strdt = data_corrente
        percorso = mercati + strdt
        strUrl = "http://www.mercatoelettrico.org/GmewebItaliano/WebServerDataStore/" + gunnellabug(percorso) + ".xml"
        Label1.Caption = strUrl
          
        Open "d:\" + nome_file For Output As #1
                Print #1, Inet1.OpenURL(strUrl)    'salva la stringa nel file
        Close #1                           'chiude il file
        Open "d:\" + nome_file For Input As #1
    
        While Not EOF(1)
            Line Input #1, strPercorsoLog
            If InStr(1, strPercorsoLog, "<h2>HTTP Error 404 - File or directory not found.
    Internet Information Services (IIS)</h2>") <> 0 Then
                Set Elementi = lstFileLOG.ListItems.Add(, , nome_file)
                blnElimina = True
            End If
        Wend
        Close #1
        DoEvents
        If blnElimina = True Then
            Kill "d:\" + nome_file
            DoEvents
        End If
        
           
        data_corrente = data_corrente + 1
    Wend
    MsgBox "Download effettuato"
    
    MousePointer = vbNormal
    DoEvents
    End Sub
    Private Sub Command2_Click()
    Unload Me
    End Sub
    Private Sub DTPicker1_Change()
        
        DTPicker2.MinDate = DTPicker1.Value
    End Sub
    
    Private Sub Form_Load()
    
        Combo1.AddItem "MGP_Prezzi"
        Combo1.AddItem "MGP_Quantita"
        Combo1.AddItem "MGP_Fabbisogno"
        Combo1.AddItem "MA1_Prezzi"
        Combo1.AddItem "MA1_Quantita"
        Combo1.AddItem "MSD_ServiziDispacciamento"
        Combo1.AddItem "MB_ServiziDispacciamento"
        Me.DTPicker1 = Date
        Me.DTPicker2 = Date
        DTPicker1_Change
    End Sub
    
    'funzione che permette di salvare i file nel formato numerico
    Public Function gunnellabug(formina As String) As String
    'dichiarazione variabili
    Dim val As String
    Dim risultato_mercato As String
    Dim posizione_mercato As String
    Dim posizione_attributo As String
    Dim risultato_attributo As String
    Dim lungtot As String
    Dim data_estratta As String
    Dim strdata As String 'data finale composta dall'unione dei singoli pezzetti
    
    'assoccio la stringa da valutare
    val = formina
    
    'conto i caratteri che compongono la mia stringa
    posizione_mercato = InStr(val, "_") 'posizione mercati
    If (posizione_mercato = 3) Then
        risultato_mercato = Mid(val, 1, 2) ' MGP,MA1
        posizione_attributo = InStr(val, "/") 'posizione attributo
        risultato_attributo = Mid(val, 4, posizione_attributo - 6) 'Prezzi,quantità,fabbisogno
    Else
        risultato_mercato = Mid(val, 1, 3) ' MGP,MA1
        posizione_attributo = InStr(val, "/") 'posizione attributo
        risultato_attributo = Mid(val, 5, posizione_attributo - 7) 'Prezzi,quantità,fabbisogno
    End If
    
    lungtot = InStr(val, "2005")
    data_estratta = Mid(val, lungtot + 4 - 10)
    strdata = Mid(data_estratta, 7, 4) + Mid(data_estratta, 4, 2) + Mid(data_estratta, 1, 2)
    nome_file = strdata + risultato_mercato + risultato_attributo + ".xml"
    'compongo la stringa finale codificata numericamente
    gunnellabug = risultato_mercato + "_" + risultato_attributo + "/" + strdata + risultato_mercato + risultato_attributo
    
    End Function

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.