Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    [VB6] Caricamento file esterno e progressbar

    Ciao a tutti,
    ho un codice di questo tipo per aprire un file esterno txt:
    codice:
    If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                myStream = openFileDialog1.OpenFile()
                MsgBox(myStream.Length)
                If Not (myStream Is Nothing) Then
                    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(openFileDialog1.FileName)
                        MyReader.TextFieldType = FileIO.FieldType.Delimited
                        MyReader.SetDelimiters(" ")
                        Dim currentRow As String()
                        While Not MyReader.EndOfData
                            currentRow = MyReader.ReadFields()
                            Dim currentField As String
                            For Each currentField In currentRow
    'codice
                            Next
                            myStream.Close()
                        End While
                    End Using
                End If
    End if
    Aprendo file txt grossi (ma lo fa già con file da 54Kb) si freeza tutto mentre carica in memoria...a parte che non capisco la lentezza nell'aprire un file da 60Kb, come posso visualizzare una progressbar mentre importa il suddetto file?

    Grazie, Lorenzo

  2. #2

  3. #3
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Hai indicato VB6 ... ma parliamo di VB.NET ... o no?

  4. #4

    Re: [VB6] Caricamento file esterno e progressbar

    Originariamente inviato da Lukather
    Ciao a tutti,
    ho un codice di questo tipo per aprire un file esterno txt:
    codice:
    If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                myStream = openFileDialog1.OpenFile()
                MsgBox(myStream.Length)
                If Not (myStream Is Nothing) Then
                    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(openFileDialog1.FileName)
                        MyReader.TextFieldType = FileIO.FieldType.Delimited
                        MyReader.SetDelimiters(" ")
                        Dim currentRow As String()
                        While Not MyReader.EndOfData
                            currentRow = MyReader.ReadFields()
                            Dim currentField As String
                            For Each currentField In currentRow
    'codice
                            Next
                            myStream.Close()
                        End While
                    End Using
                End If
    End if
    Aprendo file txt grossi (ma lo fa già con file da 54Kb) si freeza tutto mentre carica in memoria...a parte che non capisco la lentezza nell'aprire un file da 60Kb, come posso visualizzare una progressbar mentre importa il suddetto file?

    Grazie, Lorenzo
    keggendo il codice è vb.net e non vb6 cmq ad ogni modo
    crei un controllo progressbar chiamiamolo pBar.
    poi fai
    codice:
    pBar.minimum = 0 
    pBar.maximum = myStream.Length
    diventa così:
    codice:
    If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    pBar.minimum = 0 
    
                myStream = openFileDialog1.OpenFile()
                'MsgBox(myStream.Length)
                If Not (myStream Is Nothing) Then
                    MsgBox(myStream.Length) ' meglio qui, nel caso myStream fosse nullo(nothing) ti darebbe errore
                    pBar.maximum = myStream.Length
                    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(openFileDialog1.FileName)
                        MyReader.TextFieldType = FileIO.FieldType.Delimited
                        MyReader.SetDelimiters(" ")
                        Dim currentRow As String()
                        While Not MyReader.EndOfData
                            currentRow = MyReader.ReadFields()
                            Dim currentField As String
                            For Each currentField In currentRow
    'codice
                             
                            Next
                            myStream.Close()
                            pBar.Increment(1)
                        End While
                    End Using
                End If
    End if
    -----
    101110101011101111100000
    -----

  5. #5
    Originariamente inviato da oregon
    Hai indicato VB6 ... ma parliamo di VB.NET ... o no?
    si sorry ho cappellato il titolo

    grazie xam provo subito

  6. #6
    Mhhh allora, a parte che la pbar non mi funziona il problema è che per aprire un file di 50Kb ci mette veramente troppo bloccando l'applicazione, come si vede da questa immagine:



    Possibile che ci voglia così tanto tempo per aprire un file txt così piccolo? Forse sono troppi i dati dentro il file nonostante sia di queste dimensioni?

  7. #7
    qui l'esempio di pBar. per via della velocità, ora cerco metodi migliori...
    fai un progetto e scrivi questo codice:
    codice:
    Public Class Form1
        Inherits System.Windows.Forms.Form
    
    #Region " Codice generato da Progettazione Windows Form "
    
        Public Sub New()
            MyBase.New()
    
            'Chiamata richiesta da Progettazione Windows Form.
            InitializeComponent()
    
            'Aggiungere le eventuali istruzioni di inizializzazione dopo la chiamata a InitializeComponent()
    
        End Sub
    
        'Form esegue l'override del metodo Dispose per pulire l'elenco dei componenti.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub
    
        'Richiesto da Progettazione Windows Form
        Private components As System.ComponentModel.IContainer
    
        'NOTA: la procedura che segue è richiesta da Progettazione Windows Form.
        'Può essere modificata in Progettazione Windows Form.  
        'Non modificarla nell'editor del codice.
        Friend WithEvents NumericUpDown1 As System.Windows.Forms.NumericUpDown
        Friend WithEvents NumericUpDown2 As System.Windows.Forms.NumericUpDown
        Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents Label2 As System.Windows.Forms.Label
        Friend WithEvents Button1 As System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.NumericUpDown1 = New System.Windows.Forms.NumericUpDown()
            Me.NumericUpDown2 = New System.Windows.Forms.NumericUpDown()
            Me.ProgressBar1 = New System.Windows.Forms.ProgressBar()
            Me.Label1 = New System.Windows.Forms.Label()
            Me.Label2 = New System.Windows.Forms.Label()
            Me.Button1 = New System.Windows.Forms.Button()
            CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.NumericUpDown2, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'NumericUpDown1
            '
            Me.NumericUpDown1.Name = "NumericUpDown1"
            Me.NumericUpDown1.TabIndex = 0
            '
            'NumericUpDown2
            '
            Me.NumericUpDown2.Location = New System.Drawing.Point(0, 32)
            Me.NumericUpDown2.Maximum = New Decimal(New Integer() {1000, 0, 0, 0})
            Me.NumericUpDown2.Name = "NumericUpDown2"
            Me.NumericUpDown2.TabIndex = 1
            Me.NumericUpDown2.Value = New Decimal(New Integer() {100, 0, 0, 0})
            '
            'ProgressBar1
            '
            Me.ProgressBar1.Location = New System.Drawing.Point(8, 80)
            Me.ProgressBar1.Name = "ProgressBar1"
            Me.ProgressBar1.Size = New System.Drawing.Size(248, 24)
            Me.ProgressBar1.Step = 1
            Me.ProgressBar1.TabIndex = 2
            '
            'Label1
            '
            Me.Label1.Location = New System.Drawing.Point(128, 0)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(96, 16)
            Me.Label1.TabIndex = 3
            Me.Label1.Text = "MIN"
            '
            'Label2
            '
            Me.Label2.Location = New System.Drawing.Point(120, 32)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(112, 24)
            Me.Label2.TabIndex = 4
            Me.Label2.Text = "MAX"
            '
            'Button1
            '
            Me.Button1.Location = New System.Drawing.Point(24, 112)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(72, 32)
            Me.Button1.TabIndex = 5
            Me.Button1.Text = "AVANZA"
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(292, 266)
            Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.Label2, Me.Label1, Me.ProgressBar1, Me.NumericUpDown2, Me.NumericUpDown1})
            Me.Name = "Form1"
            Me.Text = "Form1"
            CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.NumericUpDown2, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
    
        End Sub
    
    #End Region
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ProgressBar1.Minimum = NumericUpDown1.Value
            ProgressBar1.Maximum = NumericUpDown2.Value
        End Sub
    
        Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
            ProgressBar1.Minimum = NumericUpDown1.Value
            ProgressBar1.Maximum = NumericUpDown2.Value
        End Sub
    
        Private Sub NumericUpDown2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown2.ValueChanged
            ProgressBar1.Minimum = NumericUpDown1.Value
            ProgressBar1.Maximum = NumericUpDown2.Value
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ProgressBar1.PerformStep()
        End Sub
    End Class
    ora cerco un metodo più veloce per aprire il txt...
    -----
    101110101011101111100000
    -----

  8. #8
    Gentilissimo

    EDIT:
    Il progetto che mi hai copiato mi da 3 errori:

    Error 1 'Protected Overrides Sub Dispose(disposing As Boolean)' has multiple definitions with identical signatures.

    Error 2 'Private Sub InitializeComponent()' has multiple definitions with identical signatures.

    Error 3 'components' is already declared as 'Private Dim components As System.ComponentModel.IContainer' in this class.

  9. #9
    devi sostituire l'intero codice della classe form1 al codice che ti ha generato vb.net. mandami in pvt una tua mail, ti mando lo zip del codice
    -----
    101110101011101111100000
    -----

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.