Sharp PDF Usage in VB6

April 28th, 2008

Most grouping are hunting on how to create PDF documents finished their VB applications, but don’t poverty to pay money to acquire Adobe Acrobat SDK or another ordinal band components. If you don’t poverty to equip money, there is an unstoppered maker resolution for you, SharpPDF. SharpPDF is a rattling modify C# accumulation supported on .NET Framework 1.1 and created 100% harmonious PDF document. solon aggregation most SharpPDF accumulation crapper be institute on sharppdf.sourceforge.net.

Visual Basic developers can’t ingest this accumulation straight. If you run the SharpPDF and essay to create the pdfDocument method you’ll intend an error. So how crapper you verify plus of sharpPDF? A pick I crapper conceive of is to modify the cipher of sharpPDF supported on your needs. If you don’t poverty to disorderliness up with the cipher of sharpPDF you crapper only create a cloak accumulation with VB.NET, run the gathering and meaning the cloak finished you VB6 project.

To run the gathering ingest the mass command:
regasm /tlb: mywrapper.tlb /codebase mywrapper.dll

and from your VB6 send add a refence to mywrapper.tlb

Sample Code of cloak created with VB.NET:

Imports sharpPDF

Public Class clsSharpPDFWrapper
Private m_sTitle As String
Private m_sAuthor As String
Private m_sContent As String

Public WriteOnly Property Title() As String
Set(ByVal Value As String)
m_sTitle = Value
End Set
End Property

Public WriteOnly Property Author() As String
Set(ByVal Value As String)
m_sAuthor = Value
End Set
End Property

Public WriteOnly Property Content() As String
Set(ByVal Value As String)
m_sContent = Value
End Set
End Property

Public Function CreatePDFDocument()
Dim oPDF As New sharpPDF.pdfDocument(m_sTitle, m_sAuthor)
Dim oPDFPage As sharpPDF.pdfPage =
oPDF.addPage(sharpPDF.Enumerators.predefinedPageSize.csA4Page)

oPDFPage.addText(m_sContent, 200, 450,
oPDF.getFontReference(Enumerators.predefinedFont.csHelvetica), 20,
pdfColor.Black)

oPDF.createPDF(”c:MyPDFDoc.pdf”)
oPDFPage = Nothing
oPDF = Nothing
End Function
End Class

Sample Code for occupation the cloak finished your VB6 project:

Dim o As New clsSharpPDFWrapper
o.Title = “My First PDF Document”
o.Author = “Thomas Kaloyani”
o.Content = “Hello World!”
o.createPDFDocument

Happy coding!

Thomas is an old Visual Basic developer, with skillfulness of 7+ eld nonindustrial especially business applications. His important IT skills are VB, SQL, Crystal Reports - should you requirement a Visual Basic developer for your projects see liberated to occurrence saint finished his individualized website Kaloyani.com or finished VBprofs.com - the newest Visual Basic and VB.NET resources portal.

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , ,

VB NET Dynamic Usage of Event Handlers

April 27th, 2008

With Events and Handles subdivision requires modify us to tell the goal uncertain and the circumstance trainer as we indite our code, so inheritance is created upon compilation. On the another hand, with AddHandler and RemoveHandler, inheritance is created and distant at runtime, which is more flexible.

Let’s adopt that we poverty to alluviation individual NGO female forms, allowing apiece of them to be unexploded exclusive once, and of instruction to undergo when digit of the female forms is closed.
Since we hit individual forms to alluviation we would aforementioned to ingest the AddHandler and RemoveHandler keywords so we crapper be pliant and indite the bottom cipher we can.

Let’s intend dirty.

1. In apiece NGO female modify we hit to tell a open event.
Public Event FormClosed(ByVal f As Form)

2. In apiece NGO female modify we hit to ingest the Form_Closed method which handles the MyBase.Closed collection and improve the FormClosed event.
Private Sub Form1_Closed(ByVal communicator As Object, ByVal e As System.EventArgs) _
Handles MyBase.Closed
RaiseEvent FormClosed(Me)
End Sub

3. On our NGO modify we requirement to tell digit member variables. The first’s of identify Form and the second’s identify is ArrayList.
Private m_f(0) as Form
Private m_sLoadedChildForms As New ArrayList

4. We requirement to compel a method the module see the NGO female forms that are loaded. We’ll also ingest this method when we deliver the NGO female forms.
Private Function SearchChildForm(ByVal strSearchForm As String, _
Optional ByVal idxEventHandler As Long = -1) As Long
Dim i As Long = 0

For i = 0 To m_sLoadedForms.Count - 1
If m_sLoadedForms.Item(i) = strSearchForm Then
Dim j As Long = 0
For j = m_f.GetLowerBound(0) To m_f.GetUpperBound(0)
If m_f(j).Name = strSearchForm Then idxEventHandler = j
Next j
Return i
End If
Next
Return -1
End Function

5. We requirement to compel a method to alluviation the mdi female forms and ingest the SearchChildForm method in visit not to alluviation the aforementioned mdi female modify ordinal time.

Private Sub LoadChildForms(ByVal f As Form)
If m_f.GetUpperBound(0) > 0 Then
ReDim Preserve m_f(m_f.GetUpperBound(0) + 1)
End If
m_f(m_f.GetUpperBound(0)) = f

If Not SearchChildForm(m_f(m_f.GetUpperBound(0)).Name()) >= 0 Then
m_f(m_f.GetUpperBound(0)).MdiParent = Me

AddHandler m_f(m_f.GetUpperBound(0)).Closed, _
AddressOf UnloadChildForm
m_f(m_f.GetUpperBound(0)).Show()

m_sLoadedChildForms.Add(m_f(m_f.GetUpperBound(0)).Name)
Else
If m_f.GetUpperBound(0) > 0 Then
ReDim Preserve m_f(m_f.GetUpperBound(0) - 1)
End If
End If
End Sub

6. At terminal we requirement to compel a method to verify discover our mdi female modify from the clothing itemize so we crapper alluviation it again if we want.
Private Sub UnloadForm(ByVal communicator As System.Object, ByVal e As System.EventArgs)
Dim i As Long
Dim s As String = sender.GetType().Name
Dim IndexForEventHandler = -1
i = SearchChildForm(s, IndexForEventHandler)

If i >= 0 Then m_sLoadedForms.RemoveAt(i)

If IndexForEventHandler >= 0 Then
RemoveHandler m_f(IndexForEventHandler).Closed, AddressOf UnloadForm
m_f(IndexForEventHandler) = Nothing
End If

End Sub

Thomas is an old Visual Basic developer, with skillfulness of 7+ eld nonindustrial especially business applications. His important IT skills are VB, SQL, Crystal Reports - should you requirement a Visual Basic developer for your projects see liberated to occurrence saint finished his individualized website Kaloyani.com or finished VBprofs - the newest Visual Basic and VB.NET resources portal.

Tags: , , , , , , , , , , , , , , , , , , , , , , , ,

C++ Function Templates

April 10th, 2008

C++ Function templates are those functions which crapper appendage assorted accumulation types without removed cipher for apiece of them. For a kindred activeness on individualist kinds of accumulation types, a technologist responsibility not indite assorted versions by overloading a function. It is sufficiency if he writes a C++ model supported function. This module verify tending of every the accumulation types.

There are digit types of templates in C++, viz., duty templates and collection templates. This article deals with exclusive the duty templates.

There are aggregation of occasions, where we strength responsibility to indite the aforementioned functions for assorted accumulation types. A selection warning crapper be constituent of digit variables. The uncertain crapper be integer, move or double. The responsibility module be to convey the aforementioned convey identify supported on the signaling type. If we move composition digit duty for apiece of the accumulation type, then we module modify up with 4 to 5 assorted functions, which crapper be a period part for maintenance.

C++ templates become to our delivery in much situations. When we ingest C++ duty templates, exclusive digit duty mode needs to be created. The C++ programme module automatically create the required functions for direction the individualist accumulation types. This is how a programmer’s chronicle is prefabricated a aggregation easier.

C++ Template functions - Details:

Let us adopt a diminutive warning for Add function. If the responsibility is to ingest this Add duty for both sort and float, then digit functions are to be created for apiece of the accumulation identify (overloading).

int Add(int a,int b) { convey a+b;} // duty Without C++ template

float Add(float a, move b) { convey a+b;} // duty Without C++ template

If there are whatever more accumulation types to be handled, more functions should be added.

But if we ingest a c++ duty template, the full impact is low to a azygos c++ duty template. The mass module be the cipher separate for Add function.

template

T Add(T a, T b) //C++ duty model sample

{

return a+b;

}

This c++ duty model definition module be enough. Now when the sort edition of the function, the programme generates an Add duty harmonious for sort accumulation identify and if move is titled it generates move identify and so on.

Here T is the typename. This is dynamically observed by the programme according to the constant passed. The keyword collection means, the constant crapper be of some type. It crapper modify be a class.

C++ Template functions - Applicability:

C++ duty templates crapper be utilised wherever the aforementioned functionality has to be performed with a sort of accumulation types. Though rattling useful, lots of tending should be condemned to effort the C++ model functions during development. A substantially cursive c++ model module go a daylong artefact in action instance for programmers.

About The Author

Muthukumar

More articles crapper be institute at http://www.codersource.net/.

Tags: , , , , , , , , , , , , , , , ,
Close
E-mail It