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: , , , , , , , , , , , , , , , , , , , , , , , ,

.NET Solving the Multiple Inheritance Issue Under .NET Platform

April 14th, 2008

.NET papers does not hold binary inheritance. Do not tack multilevel acquisition with binary inheritance. With binary acquisition we crapper hit a subclass that inherits from digit classes at the aforementioned time.

Let’s presume we hit an covering that has a collection Customers and added collection Vendors. If you desired to consortium these digit classes into digit CustomerVendor collection it would be a compounding of Customers and Vendors meet aforementioned the draw below.

Please double the mass address into your covering to analyse the diagram: http://www.vbprofs.com/images/Article Images/ThomasArt1.gif

In the above draw we wager how the CustomerVendor collection inherits from both of those classes.

Multiple acquisition is Byzantine and crapper be dangerous. The advantages of cipher re-usage exist over complexness is up to your choice.

Multiple acquisition is not based by VB.NET or .Net platform. Instead of binary acquisition we crapper ingest binary interfaces to attain kindred gist to binary inheritance.

In VB.NET every objects hit a direct or autochthonous interface, which is imperturbable of properties, events, methods or member variables proclaimed using Public keyword.
Objects crapper compel also alternative interfaces by using Implement keyword.

Sometimes it is adjuvant for an goal to hit more than digit interface, allowing us to interact with the goal in assorted ways. Inheritance earmark us to create subclasses that are a special housing of the humble class.

Example

Sometimes we hit a assemble of objects that are not the similar, but we poverty to appendage them the aforementioned manner. We poverty every the objects to behave as if they are the same, modify though they are different.

We crapper hit whatever assorted objects in an application, much as customer, product, invoice etc. Each goal would hit a choice programme pertinent to apiece individualist object, and apiece of them is a assorted class. No uncolored acquisition is tacit between these classes.
Let’s presume we poverty to indicant a writing for apiece identify of object. In this housing we’d aforementioned to attain them every behave as printable object.
To fulfill this we crapper delimitate a generic programme that would enable generating a printed document.
By implementing a ordinary programme we are healthy to indite a turn that accepts some goal that implements a printed document.

To conclude, by implementing binary interfaces in VB.NET , we crapper attain a kindred gist to that of binary inheritance.

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: , , , , , , , , , , , , , , , , , , , ,
Close
E-mail It