Private Sub Command1_Click()
Dim i As Integer, j As Integer
For i = 1 To 10000
For j = 1 To 10000
Print "SDFGH========="; j
Next j
Next i

End Sub

when i click on command1, i want to view the enitre execution of loop,i.e, from

SDGGH=============1
                      SDFGH=============2
                      .
                      .
            till.......SDFGH============10000

in separate lines but form is too small and it displays only till ...
SDFGH=============42
please help...

Dani AI

Generated

Two important points up front: the nested loops in your first post generate 10,000 * 10,000 = 100,000,000 output lines. Trying to render that live on a form will freeze the UI, consume huge memory, and produce enormous files if you try to capture it. If the outer loop was accidental, remove it. If you really need every line, do not try to stream all of it to a form control.

A practical approach is to write incrementally to disk and inspect the file with a text viewer. Using the FileSystemObject to append lines avoids building one giant in-memory string:

Dim fso As Object, ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile("C:\temp\looplog.txt", True)

Dim i As Long, j As Long
For i = 1 To 10000
  For j = 1 To 10000
    ts.WriteLine "SDFGH=========" & j
  Next j
Next i

ts.Close
Set ts = Nothing
Set fso = Nothing

If you must show progress in the UI, update the control in batches instead of every iteration. Use a Timer to do small chunks (keeps UI responsive) and append a buffered string every N lines:

' accumulate into buf, then append to TextBox every BatchSize items
Const BatchSize = 1000
Dim buf As String
' in Timer: perform BatchSize iterations, then Text1.Text = Text1.Text & buf : buf = ""

Notes and troubleshooting: declare counters as Long to avoid overflows; do not build one huge string in memory (stream or flush in batches); check disk space before logging; add a Cancel button checked between batches; avoid heavy use of DoEvents (use Timer chunking instead) to prevent reentrancy. 's idea of clearing the form will only hide earlier lines; 's control-based approach works for modest amounts but will not scale to tens of millions. For very large traces, write to disk and sample or search the file with an external viewer.

Recommended Answers

All 2 Replies

something like...

If j Mod 42 = 0 Then Me.cls
Print ...

This will clear the form of the printing you have done to it and reset the currentx and currenty properties to 0. Look it up in help to make sure you use it right if you are manipulating the forms autoredraw property.

Good Luck

You can also try and the loop to a list box -

Private Sub Command1_Click()Dim i As Integer, j As Integer
For i = 1 To 10000
For j = 1 To 10000
Print "SDFGH=========";j
List1.AddItem j   'Or the like
Next j
Next i 
End Sub

If this is not working for you and you want to print to your form, use a scrollable form. I have add a attachment with code on how to create such a form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.