473,508 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems in exe file of project

274 Contributor
Hi everyone
I am facing a strange problem in the exe file of my project. i.e

I created setup for software instllation. I tried it on my PC and works fine. However, when my supervisor run it on his laptop i.e connected to a wireless network; and a printer is attached in the network. He complains that:

he is not able to Save a transaction and Print it on his laptop.(When I save a transection it prints a ticket and then save it). When he Reprint Last Ticket(last performed transection) it generates a MDI file and opens Microsift Office Document Imaging.

p.s.Currently I m working on a standalone computer with a dedicated printer attached to it.

I am not able ti understand what the problem is. As its working on my pc and save a transection. I hope I'll get a useful information to resolve thid problem.
Farhana
Oct 6 '07 #1
7 1548
Killer42
8,435 Recognized Expert Expert
It could just be a matter of what he has set up as his default printer.
Oct 6 '07 #2
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

Why don't you try installing a new printer in your client's system?
Maybe his default printer is configured to print to a file.

Regards
Veena
Oct 6 '07 #3
Mayur2007
67 New Member
...when my supervisor run it on his laptop i.e connected to a wireless network; and a printer is attached in the network. He complains that:

he is not able to Save a transaction and Print it on his laptop...
Hi ,

Make sure that if you are using any .dll file or other then it should be in the same folder in which you have saved the VB project. Make changes in the code like if you give the path as "\\server\abc\dddd\mm.bmp" then just change it to "mm.bmp".
I was facing same type of problem as you are facing but after that solution my problem is solved out.

Mayur
Oct 10 '07 #4
creative1
274 Contributor
Hello guys thanks for your help
Problem is solved and ticket can be printed and transection is saved successfully into the machine.

What I did?
I used default printer attached to the PC to print ticket, before this I had mentioned which printer to use to print the ticket. I think my client and I didn't have same printers.

But this is not what I want to do. Actually I want to select a printer at runtime because I want to print tickets on ticket printer and reports on another printer

Any clues?? please

thanks in advance
Farhana
Oct 27 '07 #5
9815402440
180 New Member
hi
following is the code to set default printer

open a new standard exe project
add a moudle

on the form1 draw a command button and name it cmdSetDef
add a listbox List1

copy and paste following code in the Form1 code window
Expand|Select|Wrap|Line Numbers
  1. Private Function PtrCtoVbString(Add As Long) As String
  2.  
  3.     Dim sTemp As String * 512, x As Long
  4.  
  5.     x = lstrcpy(sTemp, Add)
  6.     If (InStr(1, sTemp, Chr(0)) = 0) Then
  7.          PtrCtoVbString = ""
  8.     Else
  9.          PtrCtoVbString = Left(sTemp, InStr(1, sTemp, Chr(0)) - 1)
  10.     End If
  11. End Function
  12.  
  13. Private Sub Win95SetDefaultPrinter()
  14.     Dim Handle As Long          'handle to printer
  15.     Dim PrinterName As String
  16.     Dim pd As PRINTER_DEFAULTS
  17.     Dim x As Long
  18.     Dim need As Long            ' bytes needed
  19.     Dim pi5 As PRINTER_INFO_5   ' your PRINTER_INFO structure
  20.     Dim LastError As Long
  21.  
  22.     ' determine which printer was selected
  23.     PrinterName = List1.List(List1.ListIndex)
  24.     ' none - exit
  25.     If PrinterName = "" Then
  26.         Exit Sub
  27.     End If
  28.  
  29.     ' set the PRINTER_DEFAULTS members
  30.     pd.pDatatype = 0&
  31.     pd.DesiredAccess = PRINTER_ALL_ACCESS
  32.  
  33.     ' Get a handle to the printer
  34.     x = OpenPrinter(PrinterName, Handle, pd)
  35.     ' failed the open
  36.     If x = False Then
  37.         'error handler code goes here
  38.         Exit Sub
  39.     End If
  40.  
  41.     ' Make an initial call to GetPrinter, requesting Level 5
  42.     ' (PRINTER_INFO_5) information, to determine how many bytes
  43.     ' you need
  44.     x = GetPrinter(Handle, 5, ByVal 0&, 0, need)
  45.     ' don't want to check GetLastError here - it's supposed to fail
  46.     ' with a 122 - ERROR_INSUFFICIENT_BUFFER
  47.     ' redim t as large as you need
  48.     ReDim t((need \ 4)) As Long
  49.  
  50.     ' and call GetPrinter for keepers this time
  51.     x = GetPrinter(Handle, 5, t(0), need, need)
  52.     ' failed the GetPrinter
  53.     If x = False Then
  54.         'error handler code goes here
  55.         Exit Sub
  56.     End If
  57.  
  58.     ' set the members of the pi5 structure for use with SetPrinter.
  59.     ' PtrCtoVbString copies the memory pointed at by the two string
  60.     ' pointers contained in the t() array into a Visual Basic string.
  61.     ' The other three elements are just DWORDS (long integers) and
  62.     ' don't require any conversion
  63.     pi5.pPrinterName = PtrCtoVbString(t(0))
  64.     pi5.pPortName = PtrCtoVbString(t(1))
  65.     pi5.Attributes = t(2)
  66.     pi5.DeviceNotSelectedTimeout = t(3)
  67.     pi5.TransmissionRetryTimeout = t(4)
  68.  
  69.     ' this is the critical flag that makes it the default printer
  70.     pi5.Attributes = PRINTER_ATTRIBUTE_DEFAULT
  71.  
  72.     ' call SetPrinter to set it
  73.     x = SetPrinter(Handle, 5, pi5, 0)
  74.     ' failed the SetPrinter
  75.     If x = False Then
  76.         MsgBox "SetPrinterFailed. Error code: " & GetLastError()
  77.         Exit Sub
  78.     End If
  79.  
  80.     ' and close the handle
  81.     ClosePrinter (Handle)
  82.  
  83. End Sub
  84. Private Sub GetDriverAndPort(ByVal Buffer As String, DriverName As String, PrinterPort As String)
  85.     Dim iDriver As Integer
  86.     Dim iPort As Integer
  87.     DriverName = ""
  88.     PrinterPort = ""
  89.  
  90.     'The driver name is first in the string terminated by a comma
  91.     iDriver = InStr(Buffer, ",")
  92.     If iDriver > 0 Then
  93.  
  94.         'Strip out the driver name
  95.         DriverName = Left(Buffer, iDriver - 1)
  96.  
  97.         'The port name is the second entry after the driver name
  98.         'separated by commas.
  99.         iPort = InStr(iDriver + 1, Buffer, ",")
  100.  
  101.         If iPort > 0 Then
  102.             'Strip out the port name
  103.             PrinterPort = Mid(Buffer, iDriver + 1, _
  104.             iPort - iDriver - 1)
  105.         End If
  106.     End If
  107. End Sub
  108.  
  109. Private Sub ParseList(lstCtl As Control, ByVal Buffer As String)
  110.     Dim i As Integer
  111.  
  112.     Dim s As String
  113.  
  114.     Do
  115.         i = InStr(Buffer, Chr(0))
  116.         If i > 0 Then
  117.             s = Left(Buffer, i - 1)
  118.             If Len(Trim(s)) Then lstCtl.AddItem s
  119.             Buffer = Mid(Buffer, i + 1)
  120.         Else
  121.             If Len(Trim(Buffer)) Then lstCtl.AddItem Buffer
  122.             Buffer = ""
  123.         End If
  124.     Loop While i > 0
  125. End Sub
  126.  
  127. Private Sub WinNTSetDefaultPrinter()
  128.     Dim Buffer As String
  129.     Dim DeviceName As String
  130.     Dim DriverName As String
  131.     Dim PrinterPort As String
  132.     Dim PrinterName As String
  133.     Dim r As Long
  134.     If List1.ListIndex > -1 Then
  135.         'Get the printer information for the currently selected
  136.         'printer in the list. The information is taken from the
  137.         'WIN.INI file.
  138.         Buffer = Space(1024)
  139.         PrinterName = List1.Text
  140.         r = GetProfileString("PrinterPorts", PrinterName, "", _
  141.             Buffer, Len(Buffer))
  142.  
  143.         'Parse the driver name and port name out of the buffer
  144.         GetDriverAndPort Buffer, DriverName, PrinterPort
  145.  
  146.         If DriverName <> "" And PrinterPort <> "" Then
  147.             SetDefaultPrinter List1.Text, DriverName, PrinterPort
  148.         End If
  149.     End If
  150. End Sub
  151.  
  152. Private Sub SetDefaultPrinter(ByVal PrinterName As String, _
  153.     ByVal DriverName As String, ByVal PrinterPort As String)
  154.     Dim DeviceLine As String
  155.     Dim r As Long
  156.     Dim l As Long
  157.     DeviceLine = PrinterName & "," & DriverName & "," & PrinterPort
  158.     ' Store the new printer information in the [WINDOWS] section of
  159.     ' the WIN.INI file for the DEVICE= item
  160.     r = WriteProfileString("windows", "Device", DeviceLine)
  161.     ' Cause all applications to reload the INI file:
  162.     l = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, "windows")
  163. End Sub
  164.  
  165.  
  166. Private Sub cmdSetDef_Click()
  167.     Dim osinfo As OSVERSIONINFO
  168.     Dim retvalue As Integer
  169.  
  170.     osinfo.dwOSVersionInfoSize = 148
  171.     osinfo.szCSDVersion = Space$(128)
  172.     retvalue = GetVersionExA(osinfo)
  173.  
  174.     If osinfo.dwMajorVersion = 3 And osinfo.dwMinorVersion = 51 And _
  175.        osinfo.dwBuildNumber = 1057 And osinfo.dwPlatformId = 2 Then
  176.         Call WinNTSetDefaultPrinter
  177.     ElseIf osinfo.dwMajorVersion = 4 And osinfo.dwMinorVersion = 0 _
  178.        And osinfo.dwBuildNumber >= 67109814 And osinfo.dwPlatformId = 1 Then
  179.         Call Win95SetDefaultPrinter
  180.     ElseIf osinfo.dwMajorVersion = 4 And osinfo.dwMinorVersion = 0 _
  181.        And osinfo.dwBuildNumber = 1381 And osinfo.dwPlatformId = 2 Then
  182.         Call WinNTSetDefaultPrinter
  183.     End If
  184.  
  185. End Sub
  186.  
  187. Private Sub Form_Load()
  188.     Dim r As Long
  189.     Dim Buffer As String
  190.  
  191.     'Get the list of available printers from WIN.INI
  192.     Buffer = Space(8192)
  193.     r = GetProfileString("PrinterPorts", vbNullString, "", _
  194.        Buffer, Len(Buffer))
  195.  
  196.     'Display the list of printer in the list box List1
  197.     ParseList List1, Buffer
  198. End Sub
  199.  
************************

paste following code in the Module1
Expand|Select|Wrap|Line Numbers
  1. Public Const WM_WININICHANGE = &H1A
  2.  
  3. ' constants for DEVMODE structure
  4. Public Const CCHDEVICENAME = 32
  5. Public Const CCHFORMNAME = 32
  6.  
  7. ' constants for DesiredAccess member of PRINTER_DEFAULTS
  8. Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
  9. Public Const PRINTER_ACCESS_ADMINISTER = &H4
  10. Public Const PRINTER_ACCESS_USE = &H8
  11. Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
  12.  
  13. ' constant that goes into PRINTER_INFO_5 Attributes member
  14. ' to set it as default
  15. Public Const PRINTER_ATTRIBUTE_DEFAULT = 4
  16.  
  17. Public Type OSVERSIONINFO
  18.     dwOSVersionInfoSize As Long
  19.     dwMajorVersion As Long
  20.     dwMinorVersion As Long
  21.     dwBuildNumber As Long
  22.     dwPlatformId As Long
  23.     szCSDVersion As String * 128
  24. End Type
  25.  
  26. Type ACL
  27.     AclRevision As Byte
  28.     Sbz1 As Byte
  29.     AclSize As Integer
  30.     AceCount As Integer
  31.     Sbz2 As Integer
  32. End Type
  33.  
  34.  
  35. Type SECURITY_DESCRIPTOR
  36.     Revision As Byte
  37.     Sbz1 As Byte
  38.     Control As Long
  39.     Owner As Long
  40.     Group As Long
  41.     Sacl As ACL
  42.     Dacl As ACL
  43. End Type
  44.  
  45.  
  46. Public Type DEVMODE
  47.     dmDeviceName As String * CCHDEVICENAME
  48.     dmSpecVersion As Integer
  49.     dmDriverVersion As Integer
  50.     dmSize As Integer
  51.     dmDriverExtra As Integer
  52.     dmFields As Long
  53.     dmOrientation As Integer
  54.     dmPaperSize As Integer
  55.     dmPaperLength As Integer
  56.     dmPaperWidth As Integer
  57.     dmScale As Integer
  58.     dmCopies As Integer
  59.     dmDefaultSource As Integer
  60.     dmPrintQuality As Integer
  61.     dmColor As Integer
  62.     dmDuplex As Integer
  63.     dmYResolution As Integer
  64.     dmTTOption As Integer
  65.     dmCollate As Integer
  66.     dmFormName As String * CCHFORMNAME
  67.     dmLogPixels As Integer
  68.     dmBitsPerPel As Long
  69.     dmPelsWidth As Long
  70.     dmPelsHeight As Long
  71.     dmDisplayFlags As Long
  72.     dmDisplayFrequency As Long
  73.     dmICMMethod As Long        ' // Windows 95 only
  74.     dmICMIntent As Long        ' // Windows 95 only
  75.     dmMediaType As Long        ' // Windows 95 only
  76.     dmDitherType As Long       ' // Windows 95 only
  77.     dmReserved1 As Long        ' // Windows 95 only
  78.     dmReserved2 As Long        ' // Windows 95 only
  79. End Type
  80.  
  81. Type PRINTER_INFO_2
  82.     pServerName As String
  83.     pPrinterName As String
  84.     pShareName As String
  85.     pPortName As String
  86.     pDriverName As String
  87.     pComment As String
  88.     pLocation As String
  89.     pDevMode As DEVMODE
  90.     pSepFile As String
  91.     pPrintProcessor As String
  92.     pDatatype As String
  93.     pParameters As String
  94.     pSecurityDescriptor As SECURITY_DESCRIPTOR
  95.     Attributes As Long
  96.     Priority As Long
  97.     DefaultPriority As Long
  98.     StartTime As Long
  99.     UntilTime As Long
  100.     Status As Long
  101.     cJobs As Long
  102.     AveragePPM As Long
  103. End Type
  104.  
  105.  
  106. Public Type PRINTER_INFO_5
  107.     pPrinterName As String
  108.     pPortName As String
  109.     Attributes As Long
  110.     DeviceNotSelectedTimeout As Long
  111.     TransmissionRetryTimeout As Long
  112. End Type
  113.  
  114. Public Type PRINTER_DEFAULTS
  115.     pDatatype As Long
  116.     pDevMode As DEVMODE
  117.     DesiredAccess As Long
  118. End Type
  119.  
  120. Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
  121. Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
  122. Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lparam As String) As Long
  123. Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
  124. Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
  125. Public Declare Function SetPrinter Lib "winspool.drv" Alias "SetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Any, ByVal Command As Long) As Long
  126. Public Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Any, ByVal cbBuf As Long, pcbNeeded As Long) As Long
  127. Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Any) As Long
  128. Public Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
  129. Public Declare Function GetLastError Lib "kernel32" () As Long
  130.  
regards
manpreet singh dhillon hoshiarpur
Oct 27 '07 #6
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

First Re-Name the Ticket Printer as TicketPrinter, and Another Default Printer as DefPrinter.

write this Code in .bas Module:

Expand|Select|Wrap|Line Numbers
  1. Public Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
  2.  
  3. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  4.  
  5. Public Const HWND_BROADCAST = &HFFFF&
  6. Public Const WM_WININICHANGE = &H1A
  7.  
  8. Public Function SetDefaultPrinter(objPrn As Printer) As Boolean
  9.     Dim X As Long, sztemp As String
  10.     sztemp = objPrn.DeviceName & "," & objPrn.DriverName & "," & objPrn.Port
  11.     X = WriteProfileString("windows", "device", sztemp)
  12.     X = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0&, "windows")
  13. End Function
  14.  
From VB call this To Select the Printer:

Ticket :
Expand|Select|Wrap|Line Numbers
  1.    SetDefaultPrinter "TicketPrinter"
  2.  
Default:
Expand|Select|Wrap|Line Numbers
  1.    SetDefaultPrinter "DefPrinter"
  2.  

REgards
Veena
Oct 28 '07 #7
creative1
274 Contributor
Thanks guys
I'll try this code.
farhana
Oct 28 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2574
by: Daniel Moree | last post by:
I'm using MS VC++ 6.0 I'm working on a big project. I've currently have several files for this project. Here's the problem. I have one header file phead.h I have two code files main.cpp and...
5
1419
by: Dan Smith | last post by:
When I try to create a new C# Web Reference in Visual Studio 2003, I get an error message "The proxy settings on this computer are not configured correctly for web discovery. ..." This web...
0
974
by: Ditlef | last post by:
We have a large C++ COM-based project we will migrate (slowly) to .NET. We have several basic libraries we need to wrap with C++ managed wrapper libraries. Having C++ runtime Debug/Release mixed...
0
916
by: spam | last post by:
Sorry if this is the wrong group but I can't find one on the IDE. I am finding lots and lots of problems with it and I'm surprised I cannot find anyone else with the same problems. I'm using 2003...
4
1458
by: JM | last post by:
Hi, I am an old programmer who is only just getting back into it after about 10 years, and for the life of me I can not work out what I am doing wrong. Firstly, I've recently downloaded and...
5
9109
by: Richard J Foster | last post by:
Hi there, I have a pair of C# projects in VS2003. The first project, a dll, is referenced in the second via a project reference. The assemblies in question are delay-signed during a...
0
2394
by: drawing in aspnet | last post by:
Question about putting the data layer in a separate class library. I keep reading that the data layer should be separated from the presentation layer and put in its own class library. I am...
3
2609
by: =?Utf-8?B?VG9kZCBEb2JtZXllcg==?= | last post by:
I am working on developing a program using Visual Studio 2003 but am having problems getting my program to find my GL.h and GLU.h, and I am guessing it will have the same problems trying to link to...
5
1583
by: Simon | last post by:
I have problem with namespaces. I have a program that consumes the web service and has for instance names space nsProgram. In this program I have defined several classes that I use for storing and...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.