Website Design United States, Website Design California, Website Designing United States, Website Designing California

Convert a simple VB6 app to a VB5 app - Visual Basic 6

These routines show you how to programmatically convert a VB6 .VBP file to a VB5 .VBP file... by removing two tags that VB6 requires and that VB5 can't handle.
Option Explicit

Private msSourceFile As String
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10
Private Const SE_ERR_NOASSOC As Long = 31

Private Sub MakeBackup(sBackPath As String)
Dim sR As String

On Error Resume Next '
Kill sBackPath & "\Backup" '
On Error GoTo 0 'Clear error trap
MkDir sBackPath & "\Backup" '
sR = Dir$(sBackPath & "\*.*", vbNormal) '
Do Until Len(sR) = 0 '
FileCopy sBackPath & "\" & sR, sBackPath & "\Backup\" & sR '
sR = Dir$ '
Loop
End Sub

Private Sub cmdBrowse_Click()
On Error Resume Next '
With cdgBrowse
.DialogTitle = "Please select the Source file:" '
.Filter = "Visual Basic (*.vbp)|*.vbp|All Files (*.*)|*.*" '
.InitDir = "C:\" '
.CancelError = True '
.Flags = cdlOFNHideReadOnly '
.FilterIndex = 1 '
.ShowOpen '
msSourceFile = .FileName '
End With
If Err.Number = 0 Then cmdConvert.Enabled = True '
txtSource.Text = msSourceFile '
On Error GoTo 0 'Clear error trap
End Sub

Private Sub cmdClose_Click()
Unload frmMain '
Set frmMain = Nothing 'Cleanup
End '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
End Sub

Private Sub cmdConvert_Click()
Dim sBuff As String, sTitle As String, sPath As String
Dim sLines() As String
Dim i As Integer, iBnd As Integer
Dim lR As Long

sPath = Left$(msSourceFile, InStrRev(msSourceFile, "\")) '
MakeBackup sPath '
Open msSourceFile For Binary As #1 'Open the file
sBuff = Space$(LOF(1)) 'Create a buffer to hold the entire file
Get #1, 1, sBuff 'Read the entire file into the buffer
Close #1 'Close the file
sLines = Split(sBuff, vbCrLf) 'Split each line into the array
Open msSourceFile For Output As #2 'Open the file for output
iBnd = UBound(sLines) 'Figure out how many items in the array
For i = 0 To iBnd 'Loop through each item
If Left$(sLines(i), 5) = "Title" Then 'Just so we can store the title
sBuff = sLines(i) 'Store the line for temp purposes
sTitle = Mid$(sBuff, InStrRev(sBuff, "=") + 2) '
sTitle = Left$(sTitle, Len(sTitle) - 1) 'Trim and finish up the Title
End If
If Left$(sLines(i), 8) = "Retained" Then 'If it is Retained, then
ElseIf Left$(sLines(i), 18) = "DebugStartupOption" Then 'If it is DebugStartupOption, then
Else 'Do Nothing, otherwise
Print #2, sLines(i) 'Print the line back
End If
Next i
Close #2 'Close the file
lR = MsgBox("You may delete the Backup folder if " & vbCrLf & "the project converts succesfully.", vbOKOnly + vbInformation, "Load Correctly") '
' lR = ShellExecute(hwnd, "Open", msSourceFile, 0&, 0&, SW_SHOWNORMAL) 'If you want to launc the VB program afterwards
End Sub

WEB DESIGN INDIA
42 B Malviya Nagar , New Delhi-110017

Skype: manmeetsi
Email: support.webdesignindia@gmail.com
Tel: 91-011-40502005, 9810067295

 















 


© 2008-2009 dotnet4all.com