-2

One of my client is facing this issue that the vb6 exe is crashing every time he tries to print the message text from the print button present in the exe.

Following is the code written for print button.

 iRetValue = GetProfileString("windows", "device", ",,,", strBuffer, 254)

strDefaultPrinterInfo = Left(strBuffer, InStr(strBuffer, Chr(0)) - 

tblDefaultPrinterInfo = Split(strDefaultPrinterInfo, ",")






Dim picount As Integer

picount = 0

    For Each objPrinter In Printers

        picount = picount + 1

        If objPrinter.DeviceName = tblDefaultPrinterInfo(0) Then

            ' Default printer found !

            Exit For

        End If

    Next


    If objPrinter.DeviceName <> tblDefaultPrinterInfo(0) Then

        Set objPrinter = Nothing

        GoTo ExitHandler
    End If

    Set GetDefaultPrinter = objPrinter

    txtPrintMsg.text = txtMsg.text

    txtPrintMsg.SelPrint objPrinter.hDC

Total printers they have are 700.

1 Answers1

0

GetDefaultPrinter function return a bool value, while you try to SET a value.

Then, your statement: Set GetDefaultPrinter = objPrinter is totally wrong.

GetDefaultPrinter function (Windows) https://msdn.microsoft.com/en-us/library/windows/desktop/dd144876(v=vs.85).aspx

Giorgio Brausi
  • 414
  • 3
  • 7