Saturday, July 5, 2008

Print via DOS mode using a DotMatrix printer in VB 6.0.

Q:
Hi Iam preparing a report on VB6. I wish to have my report printed in the DOS mode using a DotMatrix printer. How will I do it, since Iam not working on the command prompt. Is there any way to solve this issue? Are there any general rules irrespective of the tools used to undertake such printing ? Any help/suggestion in this regard would be highly appreciated.
Answer:
I wrote a driver module using windows API's for DOS print through VB 6.0. If you want the Module please send me your mail ID via comments in the bottom of this Post. Or simply copy and paste the solution below . if you have any doubt in this feel free to ask me...
Program:


Declare Function PrinterProperties Lib "winspool.drv" (ByVal hWnd As Long, ByVal hPrinter As Long) As Long
Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Public Declare Function DefineDosDevice Lib "kernel32" Alias "DefineDosDeviceA" (ByVal dwFlags As Long, ByVal lpDeviceName As String, ByVal lpTargetPath As String) As Long
Public Const DDD_RAW_TARGET_PATH = &H1
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
ByVal pDefault As Long) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pDocInfo As DOCINFO) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
pcWritten As Long) As Long
Dim lhPrinter As Long
Dim lsp As Integer
Dim hsp As Integer
'------------------------------------------------------------
Function load_pr() As Boolean
Dim lReturn As Long
Dim lDoc As Long
Dim MyDocInfo As DOCINFO
lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
If lReturn = 0 Then
MsgBox "The Printer Name you typed wasn't recognized."
Exit Function
End If
MyDocInfo.pDocName = "AAAAAA"
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
Call StartPagePrinter(lhPrinter)
End Function
'---------------------------------------------------
Function send_pr(sss As String) As Boolean
Dim lReturn As Long
Dim lpcWritten As Long
'Dim sWrittenData As String
'sWrittenData = "How's that for Magic !!!!" & vbCrLf
sss = sss & vbCrLf
lReturn = WritePrinter(lhPrinter, ByVal sss, Len(sss), lpcWritten)

End Function
'--------------------------------------------------------------------
Function unload_pr() As Boolean
Dim lReturn As Long

lReturn = EndPagePrinter(lhPrinter)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)

End Function

The workgroup Information file is missing or opened exclusively by another user in VB 6.0

The below code will be helpful if you have the error like
The workgroup Information file is missing or opened exclusively by another user in VB 6.0

Public cn As ADODB.Connection

Public Function DBConnect() As Boolean

On Error GoTo OpenErr

Dim MSDatabase

Dim str As String Set cn = New ADODB.Connection

cn.CursorLocation = adUseClient

str = "DBQ=" & App.Path & "\db.mdb;" & "DefaultDir=" & App.Path & ";" ' database name and directory

str = str + "Driver={Microsoft Access Driver (*.mdb, *.accdb)};"

str = str + "PWD=dbb;UID=admin;" ' password & user id

str = str + "DriverId%;FIL=MS Access;MaxBufferSize 48;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;T hreads=3;UserCommitSync=Yes;"

cn.ConnectionString = str

cn.Open DBConnect = True

Exit Function

OpenErr:

MsgBox "Error Opening " & MSDatabase & vbNewLine & Err.Description, vbCritical, "Open Database Error"

DBConnect = False

End Function

'You just use the above code it will work nicely instead of Jet OLEDB 4.0

Technology

Technology has affected society and its surroundings in a number of ways. In many societies, technology has helped develop more advanced economies (including today's global economy) and has allowed the rise of a leisure class. Many technological processes produce unwanted by-products, known as pollution, and deplete natural resources, to the detriment of the Earth and its environment. Various implementations of technology influence the values of a society and new technology often raises new ethical questions. Examples include the rise of the notion of efficiency in terms of human productivity, a term originally applied only to machines, and the challenge of traditional norms.

However the Technology grows Up …. Up …. Up the life style and natural resources goes down………. Down …………… down………… .

So please be harmless to nature and protect
our world.

Birth of Technology

Birth of Technology
Technology is a broad concept that deals with usage and knowledge of tools and crafts, and how it affects ability to control and adapt to its environment. The human race's use of technology began with the conversion of natural resources into simple tools.
The use of tools by early humans was partly a process of discovery, partly of evolution.Human ancestors have been using stone and other tools since long before the emergence of Homo sapiens approximately 200,000 years ago.

The discovery and utilization of fire, a simple energy source with many profound uses, was a turning point in the technological evolution of humankind.



Science and Technology
Technology is often a consequence of science and engineering — although technology as a human activity precedes the two fields. For example, science might study the flow of electrons in electrical conductors, by using already-existing tools and knowledge. This new-found knowledge may then be used by engineers to create new tools and machines, such as semiconductors, computers, and other forms of advanced technology. In this sense, scientists and engineers may both be considered technologists; the three fields are often considered as one for the purposes of research and reference.

The distinction between science, engineering and technology is not always clear. Science is the reasoned investigation or study of phenomena, aimed at discovering enduring principles among elements of the phenomenal world by employing formal techniques such as the scientific method.[8] Technologies are not usually exclusively products of science, because they have to satisfy requirements such as utility, usability and safety.

Engineering is the goal-oriented process of designing and making tools and systems to exploit natural phenomena for practical human means, often (but not always) using results and techniques from science. The development of technology may draw upon many fields of knowledge, including scientific, engineering, mathematical, linguistic, and historical knowledge, to achieve some practical result.