http://wwww.erezsoft.co.il Business Softwares Ltd.

VISUAL BASIC TIPS

FREE SOURCE CODE

In this page we try to contribute our experience to solve some VISUAL BASIC problems especially those involved with RTL and Hebrew problems.

Dear VB Developer,
Feel free to download and use, free of charge, all the tips of this page.

CONTENT
1. How to print the content of Richtextbox to PictureBox or to printer without using Selprint method. Get WYSIWYG without using API or third party OCX
2. Creating shortcut on the desktop via VISUAL BASIC 6 during installing software on the client machine
3. How to force the installation folder on the client machine and let him change only the drive
4. How to prevent error during passing to excel which caused from the various version of Office excel and the various Operating systems

1. How to print the content of RichTextbox to PictureBox
Get WYSIWYG without using API or third party OCX

There is sometimes problem when mixing RTL and LTR in the same line in RichTextbox. Trying to print such mixed document to the printer or other control causes sometimes a messy printing.
Here is an interesting way how to get WYSIWYG without using API or third party OCX. I took the "TextRtf" of the RichTextbox Control to pieces. The "TextRtf" includes all the definitions of each character in the RichTextbox. If you have the ability to control each character in the RichTextbox, you can decide when to start new page, avoid color when output to non color printer, decide where to output the formatted text: PictureBox, Printer or any other control and more.
the following EXAMPLE illustrates how the formatted text of the RichTextbox is printed to a PictureBox which has the property "right to left=true"
you may DOWNLOAD the full free source code of the example

Back To The Content


2. Creating shortcut on the desktop via VISUAL BASIC 6
during installing software on the client machine

Package and Deployment
The Visual Basic Package and Deployment Wizard makes it easy for you to create the necessary .cab files and setup programs for your application. The Wizard also Allows you to specify the start menu groups and group items that should be created on the end-user's computer during installation of your application.
But the Wizard doesn't create shortcut on the end-user's computer Desktop.
In order to get shortcut at the desktop we should add few code lines.
how it can be done will be discussed hereinafter:

The files of your standard packages
After the Package and Deployment Wizard finished its task you get several files that are always part of your standard packages. These include:
The setup.exe file
Setup.exe acts as a pre-installation executable. Setup.exe is the first thing run on the user's machine in the installation process, and it performs necessary processing that must occur before the main installation takes place. You cannot change this file because Microsoft didn't expose the source code of this file.
The .cab files for your application
Both Internet and Windows-based applications are packaged into .cab you can have a single .cab for your application, or you can create multiple .cabs for floppy disk delivery.
The setup.lst file
Text file that contains installation instructions and lists all the files to be installed on the user's machine.
The setup1.exe file
Setup1.exe acts as the main setup program for your application. This file is included at the above cab file.
Fortunately, Microsoft let the developers change this file for their needs and that what we are going to do in order to cause the setup to create shortcut on the end-user's computer Desktop.
Visual basic 6 has folder "Wizards" under "VB98". Save the folder "Wizards" on another drive. You can find a project "setup1.vbp" at the folder VB98\Wizards\PDWizard\Setup1.

Code Lines to add
load the project Setup1.vbp .
Add to the module 'basCommon' after the first line (Option Explicit) the line "Public strDRV$".
Add to the form 'frmBegin' at the form load strDRV = "c:\".
the form 'frmPath' has Private Sub drvDrives_Change which should be changed as follows:
    Private Sub drvDrives_Change()
      Static strOldDrive As String
      Dim strDrive As String
      If mfSinkEvents Then
        mfSinkEvents = False
        If GetDrive(drvDrives.Drive, strDrive) Then
          If CheckDrive(strDrive, Caption) Then
            strOldDrive = strDrive
            dirDirs.Path = strDrive
            strDRV = strDrive
            txtPath.Text = dirDirs.Path & Right(txtPath.Text, Len(txtPath.Text) - 3)
           Else
            drvDrives.Drive = strOldDrive
          End If
        End If
        mfSinkEvents = True
      End If
    End Sub

the 'basSetup1' module include Public Sub CreateShellLink
at the end of this sub put this line:
fSuccess = OSfCreateShellLink("..\..\Desktop", "name of your program",
strDRV & "name of your program.exe file with full path", "",
fPrivate, sParent)
if you install your software also on computers which have WIN Localize
you have to add the next lines to your code:
If Not fSuccess Then
      fSuccess = OSfCreateShellLink("..\..\your language desktop name",
      "name of your program",
      strDRV & "name of your program.exe file with full path", "",
      fPrivate, sParent)
End If
Compile the project Setup1.vbp, copy the new file Setup1.exe
to the folder "Support" and run the batch file (with the name of your program.bat).
now you have the cab file with the new file Setup1.exe

G O O D   L U C K !

Back To The Content


3. How to force the installation folder on the client machine
and let him change only the drive

Read the above Creating shortcut paragraph.
Load the project Setup1.vbp .
The form 'frmPath' has TextBox named "txtPath"
change the Enabled Property to False.
The file Setup.Lst which described above has a group named "[Setup]".
Edit that file with editor like Notepad and change the line of the DefaultDir to
your Dir like "c:\name of your directory".
After the line of DefaultDir add a line which include ForceUseDefDir=
note that after the sign = there is space.
Save the file Setup.Lst and run the batch file as explained at the previous paragraph in order to update the cab file.

Back To The Content


4. How to prevent error during passing to excel which caused from
the various version of Office excel and the various Operating systems

So, you are now very glad because you succeeded to pass the data from your VB program to Excel.
Let say that you use Windows XP and Microsoft Office 2003.
Some users of your program announced you that they have problem with passing to excel.
They get error just when your program tries to open the Excel.
Probably your user has for example Microsoft Office 97 with Windows XP.
If you want that your program covers the various version of Operating systems and Office excel, use the following code in order to open Excel:
In your VB declaration section (at the top of your form) write:
Dim objExcel As Object
instead of
Dim objExcel As Excel.Application
and in the Form load section write:
Set objExcel = CreateObject("Excel.Application")
instead of
Set objExcel = New Excel.Application
After you created the object above you have to write in the Form load section
objExcel.Visible = True so you can see Excel
This will cause passing data to excel to be less quick but more stabile with the various version of Operating systems and Office excel

Back To The Content


Print preview ActiveX control fot VB6    Please send us your feedback

מאזנים הפקת חשבוניות קבלות הנהלת חשבונות חד צדדית