WebBrowser control problem

gotcha_Crazy
06-22-2004, 08:05 AM
I'm having trouble getting the webbrowser control to print in WinXP using VB6. My Sub is as follows:

Private Sub PrintGridToHtml(grdCurrent As MSFlexGrid)

Dim txt As String
Dim r As Integer
Dim c As Integer
Dim fname As String
Dim fnum As Integer

' Make a HTML string for the grid data.

txt = "<TABLE BORDER=0 BGCOLOR=#FFFFFF CELLPADDING=3>" & vbCrLf

' Display the first row in bold italics.
txt = txt & "<TR>" & vbCrLf
For c = 0 To grdCurrent.Cols - 1
txt = txt & " <TD><B><I>" & grdCurrent.TextMatrix(0, c) & "</I></B></TD>" & vbCrLf
Next c
txt = txt & "</TR>" & vbCrLf

' Display the rest of the rows.
For r = 1 To grdCurrent.Rows - 1
txt = txt & "<TR>" & vbCrLf
For c = 0 To grdCurrent.Cols - 1
txt = txt & " <TD>" & grdCurrent.TextMatrix(r, c) & "</TD>" & vbCrLf
Next c
txt = txt & "</TR>" & vbCrLf
Next r

txt = "<HTML><HEAD></HEAD><BODY>" & vbCrLf & _
txt & "</BODY></HTML>"

' Save the text into a file.
fname = App.Path
If Right$(fname, 1) <> "\" Then fname = fname & "\"
fname = fname & grdCurrent.Name & ".htm"
fnum = FreeFile
Open fname For Output As fnum
Print #fnum, txt
Close fnum

'Print the file
webDesc.Navigate2 fname
webDesc.Refresh2
webDesc.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

'Kill the file
Kill fname

End Sub

It seems that sometimes it works(in debug mode) and sometimes it doesn't. If anyone has had this problem and has a fix could you let me know.

Thanks in advance.

Peperl
06-22-2004, 08:20 AM
what the error you're getting? or simply is that the file is has been load fine in the webbrowser?

ah, and advice, to see better the vb code in your post, mark in into the vb tags [ v b ] and [ / v b ] (without spaces of course)

coloq
06-22-2004, 09:00 AM
Hi,

i've got the same problem on my app. It seem that the WebBrowser control works not very fine in visual basic during develop. If you try to compile your code you will see the web browser works fine.

I also suggest to use the [Refresh] and [Navigate] method and not the [Refresh2] and [Navigate2]

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum