Link to home
Start Free TrialLog in
Avatar of SampathRamanujam
SampathRamanujam

asked on

Performance issue in VB 6.0

Hi all,
   In my project in VB 6.0. I select all the .mdx files within a folder(the folder path is stored in an .dat file). Then i populate all the file names within the path in a listbox.
   Then i move thro each items in a list box and open that file and read it and then fill 6 grids depending upon a criteria, the values for which comes from the .mdx file.
    I open a file, read line by line and seperate the values with a seperator(||). then store this values and then depending upon the criteria i fill the grid. The code for this is as below

Public Sub Maindata(SrcPath As String)

Dim i As Integer
Dim blnfnd  As Boolean
Dim strNotes  As String
Dim FilePath As String, strNm As String, strDep As String
Dim Data As String, strtxt As String

Screen.MousePointer = vbHourglass

Obj = "databases,units,parts,mapped_parts"
Arrobj = Split(Obj, ",")
test = Split(SrcPath, "\")
Var = Split(test(UBound(test)), ".")
Open SrcPath For Input As #1
'Close #1
'Exit Sub
    Do Until EOF(1)

        Line Input #1, Data
        a = Split(Data, "||")
       
        Do While UBound(a) = -1
            Line Input #1, Data
            a = Split(Data, "||")
        Loop
         
        If a(0) = Arrobj(0) Then 'Databases
            grdsch.Col = 1
            blnfnd = False
            blnfnd = False
           
            For i = 1 To grddb.Rows - 1
                 grddb.Row = i
                 grddb.Col = 1
                 strNm = grddb.Text
                 grddb.Col = 4
                 strDep = grddb.Text
             If strNm = a(7) Then 'And a(3) = strDep Then
                    grddb.Col = 0
                    intDBNbr = Val(grddb.Text) ''Dbt
                    grddb.Col = 1
                    blnfnd = True
                    Exit For
                End If
            Next i
             
            If tdb = 0 Or blnfnd = False Then
                intDBNbr = intNbr + 1
                intNbr = intDBNbr
                tdb = tdb + 1
                grddb.Rows = tdb + 1
                grddb.Row = tdb
                intSchNbr = intNbr + 1
                intNbr = intSchNbr
                'strSchnm = a(3)
                tsch = tsch + 1
                grdsch.Rows = tsch + 1
                grdsch.Row = tsch
                grdsch.Col = 0
                grdsch.Text = intSchNbr
                grdsch.Col = 1
                grdsch.Text = "Dummy_" & a(7)
                grddb.Col = 0
                grddb.Text = intDBNbr
                grddb.Col = 1
                grddb.Text = a(7)
                grddb.Col = 2
                grddb.Text = a(8)
                grddb.Col = 3
                grddb.Text = intSchNbr
                grddb.Col = 4
                grddb.Text = a(3)
            End If
           
        '--------------------------- Database End
       
        '--------------------------- Table Start
        ElseIf a(0) = Arrobj(1) Then
            blnfnd = False
            grdtab.Col = 1
           
            For i = 1 To grdtab.Rows - 1
                 grdtab.Row = i
                 
                 If grdtab.Text = a(9) Then
                    grdtab.Col = 3
                    intSchNbr = Val(grdtab.Text)
                    grdtab.Col = 1
                    blnfnd = True
                    Exit For
                End If
               
            Next i
             
            If ttab = 0 Or blnfnd = False Then
                intunits = intunits + 1
                intTabNbr = intNbr + 1
                intNbr = intTabNbr
               
                If a(10) = "\0" Then
                    strNotes = ""
                Else
                    strNotes = a(10)
                End If
                   
                ttab = ttab + 1
                grdtab.Rows = ttab + 1
                grdtab.Row = ttab
               
                grdtab.Col = 0
                grdtab.Text = intTabNbr
                grdtab.Col = 1
                grdtab.Text = a(9)
                grdtab.Col = 2
                grdtab.Text = strNotes
                grdtab.Col = 3
                grdtab.Text = intSchNbr

            End If
           
            '--------------------------- Table End
           
            '--------------------------- Column Start
        ElseIf a(0) = Arrobj(2) Then 'Columns
            blnfnd = False
           
            'For i = 1 To tcol
            For i = 1 To grdcol.Rows - 1
                 grdcol.Row = i
                 grdcol.Col = 1
                 strNm = grdcol.Text
                 grdcol.Col = 6
                 strDep = grdcol.Text
                 If strNm = a(10) And strDep = a(9) Then
                    grdcol.Col = 5
                    intTabNbr = Val(grdcol.Text)
                    grdcol.Col = 1
                    blnfnd = True
                    Exit For
                End If
             Next i
             
            If tcol = 0 Or blnfnd = False Then
                intparts = intparts + 1
                intColNbr = intNbr + 1
                intNbr = intColNbr
                intDomNbr = intNbr + 1
                intNbr = intDomNbr
               
                If a(13) = "\0" Then
                    strNotes = ""
                Else
                    strNotes = a(13)
                End If
           
                tcol = tcol + 1
                grdcol.Rows = tcol + 1
                grdcol.Row = tcol
       grdcol.Col = 0
                grdcol.Text = intColNbr
                grdcol.Col = 1
                grdcol.Text = a(10)
                grdcol.Col = 2
                grdcol.Text = a(11)
                grdcol.Col = 3
                grdcol.Text = a(12)
                grdcol.Col = 4
                grdcol.Text = strNotes
                grdcol.Col = 5
                grdcol.Text = intTabNbr
               
                '--------------------------- Domain Start
                blnfnd = False
               
                For i = 1 To grdDom.Rows - 1
                 grdDom.Row = i
                 grdDom.Col = 1
                 strNm = grdDom.Text
                 grdDom.Col = 2
                 strDep = grdDom.Text
                 If strNm = a(11) And strDep = a(12) Then
                    grdDom.Col = 0
                    intDomNbr = Val(grdDom.Text)
                    grdDom.Col = 1
                    blnfnd = True
                    Exit For
                End If
               Next i
               If blnfnd = False Then
                    tDom = tDom + 1
                intDomNbr = intNbr + 1
                intNbr = intDomNbr
                    grdDom.Rows = tDom + 1
                    grdDom.Row = tDom
                    grdDom.Col = 0
                    grdDom.Text = intDomNbr
                    grdDom.Col = 1
                    grdDom.Text = a(11)
                    grdDom.Col = 2
                    grdDom.Text = a(12)
                End If
                grdcol.Col = 6
                grdcol.Text = intDomNbr
                grdcol.Col = 7
                grdcol.Text = a(9)
            End If
            ElseIf a(0) = Arrobj(3) Then 'mapped_parts
                    For i = 0 To grdcol.Rows - 1
                        grdcol.Col = 1
                        grdcol.Row = i
                        If a(18) = grdcol.Text Then
                        grdcol.Col = 8
                        grdcol.Text = a(10) & ":" & a(18)
                        End If
                       
                    Next i
            End If
        a(0) = ""
    Loop
    Close #1
End Sub

---------------------

My main problem is this takes almost 8 minutes to read 43 .mdx files. I want to improve the situation to read faster... Is there any way i can do it.

Pls let me know
S.Ramanujam
Avatar of EDDYKT
EDDYKT
Flag of Canada image

See whether that helps

Use listview instead of listbox


https://www.experts-exchange.com/questions/20299351/speed-up-additem.html
Another thing:  If your control is visible during your operations, it will take much longer time. Set the visible-property to false and look for yourself.

Avatar of SampathRamanujam
SampathRamanujam

ASKER

Well... The problem for me is that the load time for filling the listbox is not slow..... but reading the .mdx file and then filling the same with the grid takes a longer time...

i would love if this postings could add attachments too

keep me posted...

S.Ramanujam
Your code is not very readable...

Setting the row and column of the grid takes a lot of time.  Not knowing what grid you're using, I'm not sure if this will work, but try

dbgrd.Value(YourRowVariable, ColNumber) = value

or

Variable = dbgrd.Value(YourRowVariable, ColNumber)
I recommend getting the file in as 1 large string, then splitting the lines into an array (split(sFileText,vbcrlf)).  The file operations are relatively slow and bringing them into local memory faster may be the key.


You can get the entire contents of the file like:

   Open "c:\mywhateverfile.mdx" For Input As #lFreefile    
   MyFile = Input$(LOF(lFreefile), lFreefile)

This should speed up the file access.
ASKER CERTIFIED SOLUTION
Avatar of tandrei
tandrei

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gr8 maan.. ur idea really did work fine...