Link to home
Start Free TrialLog in
Avatar of ceb102298
ceb102298

asked on

Print screen and file

I need to put the print screen of my Vb6 forms in a Txt file, How can i do this.

I the file don't exist, I create this file, else I add at the end of the file the print screen of my forms.

Thanks for your help
Avatar of Erick37
Erick37
Flag of United States of America image

PrintScreen takes a bitmap snapshot of the screen.  To get the text contained in the form, you need to write the Text or Caption of each control to disk.  Here is an example using the Controls collection.

Private Sub Command1_Click()
    Dim sBuffer As String
    Dim c As Control
    Dim ff As Integer
    'Loop thru the controls and grab the
    'text from each control you want
    For Each c In Controls
        If TypeOf c Is TextBox Then
            sBuffer = sBuffer & c.Text & vbCrLf
        ElseIf TypeOf c Is Label Then
            sBuffer = sBuffer & c.Caption & vbCrLf
        End If
    Next
    'Append the buffer to file
    ff = FreeFile
    On Error GoTo FILEERR
    Open "c:\prntscrn.txt" For Append As #ff
    Print #ff, sBuffer
    Close #ff
    Exit Sub
FILEERR:
    MsgBox Err.Description
End Sub
Avatar of ceb102298
ceb102298

ASKER

I can't put the text of each control in my text file...

I have many forms.

If I can't put the print screen in a text files.....Can i create another type of file with my print screen and some text

Thanks
You can create a bitmap image of the forms and view them either in a graphics editor, or in your own application with a picturebox.

If you need to save the text of certain controls on the form, you can use the Tag property of the controls as a marker to ID them.  For example, for each control you need to read, set its Tag property to "ReadMe." Then in the loop which reads the controls, if c.Tag = "ReadMe" Then add the text to the file.

Can you explain a little better exactly what you want to see in the text file?  What information is important?
Hi Ceb, every form in your project is saved as a .frm file for example form1.frm and so on
This format is a Text format, you can open it with NotePad and you will see it contains every information about your form
I'm not sure if I get just what you mean. If you want to get the complete data for all the controls you can load all the project files into a file list box then go through the list and parse each file to get all the info.

Sub AppendOuputText(S as string)
   
    'you should know how to do this

End Sub

Sub ParseFormFile(FileName as String)

    Dim v as integer
    Dim strLastData as string
    Dim strNewData as string

    v = FreeFile
   
    Open FileName For Input As #v
   
        Do While Not EOF(v)        
            Line Input #v, strNewData
            If Mid(strNewData,1,15) <> "Option Explicit" Then Exit Do
            AppendOutputText strNewData

        Loop

     Close #v

End Sub
           
Oooops....

strLastData not used

If Mid(strNewData,1,15) = "Option Explicit" Then Exit Do

:o Good point TheMask...

ceb, are you talking about runtime forms or development code?
You can't really put images of screens in a text file, they aren't text.  If you are just creating documentation, you can use Alt-PrtSc and then paste the images into say, a microsoft word document.  Does this help any, or are we all off base here?
It's a realy big application. This application as been deliver to the customer.  But i have some bug.

When i have an error, i wan't to do a print screen of my form to see the data enter by the client and the status of the screen.

For example:

I have an error in my application.

I do a printscreen of my actual forms, I put this printscreen in a file rich text format with another text(The description of the error) and save this file on c:\.

Do you have an idea

Thanks

Eric
The only solution I can see is if you were to merely loop through all the controls in the currentform (I can't remember how 2 do it), and then u just have to save it to disk - that, or to use some OCR software on your screenshot... But I don't think that's wot you're talking about...
..WHY NOT USE THE DETAILS OF THE CONTROLS TO CREATE THE .FRM LAYOUT? THEN YOU COULD LOAD IT FROM VB... AND IT WOULD SEEM LIKE PART OF A PROJECT, & WOULD BE EASY TO MODIFY, OR I TOTALLY OFF THE POINT...
If i can't put my printscreen in a text file....can i create in VB a BMP or a JPG files and put the printscreen of my forms???
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

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
Thanks for your help.

Eric