Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 19th, 2006, 04:27 AM
Authorized User
 
Join Date: Aug 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default vb6 to vb.NET

hi everyone!

i'm rather new to vb.NET. i'm trying to migrate from vb6 to vb.NET. i've got visual studio 2003 installed. my problem is this:

in vb6 i use this code for a method in a class (clsVehicles):
------------------------------------------------------------
Option Explicit

Dim conDB As ADODB.Connection
Dim strSQL As String

Private Sub Class_Initialize()
Set conDB = New ADODB.Connection
conDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source =D:\LUECO\MPCS\MotorPool.mdb"
End Sub

Private Sub Class_Terminate()
Set conDB = Nothing
End Sub

Public Function Add_Vehicle(ByVal strUnitNo As String, _
                            ByVal strVtype As String, _
                            ByVal strPlateNo As String, _
                            ByVal strRegCert As String, _
                            ByVal dtExpiry As Date, _
                            ByVal strDriver1 As String, _
                            ByVal strDriver2 As String) As Boolean
Dim rsVehicle As New ADODB.Recordset

On Error GoTo ErrHandler

conDB.Open
conDB.CursorLocation = adUseServer

strSQL = "SELECT * FROM vehicles WHERE 1=2"
rsVehicle.Open strSQL, conDB, adOpenKeyset, adLockOptimistic

conDB.BeginTrans
With rsVehicle
   .AddNew
   .Fields("Unit_No") = strUnitNo
   .Fields("Vehicle_Type") = strVtype
   .Fields("Plate_No") = strPlateNo
   .Fields("LTO_Reg_No") = strRegCert
   .Fields("Expiry_Date") = dtExpiry
   .Fields("Driver_1") = strDriver1
   .Fields("Driver_2") = strDriver2
   .Update
End With
conDB.CommitTrans
Add_Vehicle = True
conDB.Close
Exit Function

ErrHandler:
   Debug.Print "Error : " & Err.Number & " - " & Err.Description
   conDB.RollbackTrans
   conDB.Close
   Add_Vehicle = False
End Function
-------------------------------
i would like to convert the code to vb.NET (2003 version)
would anyone show me how?

thanks a lot

jorge


 
Old October 24th, 2006, 04:55 AM
Registered User
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are two things that I would mention. I would have

Option Strict On
Option Explicit On

This should help with the transition. Secondly, don't use On Error in .NET. It's a legacy VB6 thing.

Use something like this instead:

Code:
Try
  conDB.Open
  conDB.CursorLocation = adUseServer

   strSQL = "SELECT * FROM vehicles WHERE 1=2"
   rsVehicle.Open strSQL, conDB, adOpenKeyset, adLockOptimistic

   conDB.BeginTrans
   With rsVehicle
    .AddNew
    .Fields("Unit_No") = strUnitNo
    .Fields("Vehicle_Type") = strVtype
    .Fields("Plate_No") = strPlateNo
    .Fields("LTO_Reg_No") = strRegCert
    .Fields("Expiry_Date") = dtExpiry
    .Fields("Driver_1") = strDriver1
    .Fields("Driver_2") = strDriver2
    .Update
   End With
  conDB.CommitTrans
  Add_Vehicle = True

Catch ex As Exception
   messagebox.Show(ex.message)
   conDB.RollbackTrans
   Add_Vehicle = False

Finally
   conDB.Close

End Try
Although 2003 should have a converter to help you when you import code.

Stim

 
Old October 26th, 2006, 05:05 AM
Authorized User
 
Join Date: Aug 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Stim, this would help. I'll try it.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Consume VB6.0 WebService in ASP.NET using VB.NET pinkarc .NET Web Services 1 March 5th, 2007 08:19 AM
Should I go VB.NET or VB 2005 from VB6? HB Visual Studio 2005 1 December 9th, 2005 03:13 AM
VB6 vs VB .Net ioates VB.NET 2002/2003 Basics 2 January 7th, 2004 12:55 PM
VB6 vs VB.Net ioates Pro VB.NET 2002/2003 4 December 29th, 2003 10:30 AM
VB6 and VB.Net ioates VB.NET 2002/2003 Basics 1 December 9th, 2003 05:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.