Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code that I developed using VBA in word (macros). I am trying the same functionality in VB.NET(2008) as in I am trying to convert the code to VB.NET(2008). I was just wondering how different the two programming languages would be. I tried looking up online for some easy code migration stuff but couldnot find any. If you could suggest and share how to start working on this, It would be very helpful.
thank U............
Posted

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Nov-11 1:49am    
My 5 for good links, but I think a word of warning would be helpful, please see my solution.
--SA
Maciej Los 25-Nov-11 16:14pm    
And my 5! - for links. I agree with comment/solution of SAKryukov.
Member 12702758 1-Sep-16 13:19pm    
i want to convert vba to vs 2013
thatraja 21-Sep-16 0:27am    
That's not recommended. Better thing is write code from scratch which is good for you.
Thanks goodness, VB.NET has almost nothing in common with VB6, there is only resemblance in very basic syntax. The paradigms are completely different, and target platforms are dramatically different. First of all, VB.NET is a fully-fledged object-oriented language and the .NET platform is truly object-oriented, too. (VB5 could be called "object-based" at best, which most crazy limitations.) While there is probably nothing good about VB6, VB.NET is a decent language (slightly behind C# in features), though absolutely not standard, in contrast to C# and C++/CLI which are standardized under ECMA and ISO.

So, it is amazing that Microsoft offers some automated migration method. However, from what I know, it's not too effective: for more or less complex project, some critical review of converted code and a good deal of manual work is unavoidable.

—SA
 
Share this answer
 
v2
Comments
thatraja 25-Nov-11 2:22am    
Ofcourse, 5!
Sergey Alexandrovich Kryukov 25-Nov-11 2:26am    
Thank you, Raja.
--SA
thatraja 25-Nov-11 2:30am    
Wow, you crossed 200K well done! I need to take a long walk for that :D
Maciej Los 25-Nov-11 16:09pm    
Maybe you have a long way to go, but... you are MVP! ;)
thatraja 25-Nov-11 22:31pm    
Only for a month. Not sure about after that.
VB
Set xlb1 = xla1.Workbooks.Open(g_strTemplate)
Set xls1 = xlb1.Worksheets("PIVOT")
 
Share this answer
 
Public Function CreateSurfaceByImportXML() As Boolean
    Dim oSurfaces As AeccSurfaces
    Set oSurfaces = g_oDocument.Surfaces
    
    ' Get a reference to the existing surface ("EG").  If
    ' it does not exist, try loading surface data from a
    ' XML file.
    Dim oSurface As AeccSurface
    Dim sXmlFileName As String
    On Error Resume Next
    Set oSurface = oSurfaces.Item("EG")
    On Error GoTo 0
    
    If (oSurface Is Nothing) Then
        sXmlFileName = "d:\temp\EG.xml"
        Set oSurface = oSurfaces.ImportXML(sXmlFileName)
        If (oSurface Is Nothing) Then
            Debug.Print "Error loading XML file: " & Err.Description
            CreateSurfaceByImportXML = False
            Err.Clear
        End If
    End If
    
    ' Fill the screen with the surface, and show the triangles
    ' that make up the surface.
    ThisDrawing.Application.ZoomExtents
    Call DisplayBorderTrianglesOnly
    
    CreateSurfaceByImportXML = True
End Function
 
Share this answer
 
Imports Microsoft.Office.InfoPath
Imports System
Imports System.Xml
Imports System.Xml.XPath
Imports IOP
Imports System.Data


Namespace Form1
Public Class FormCode
' Member variables are not supported in browser-enabled forms.
' Instead, write and read these values from the FormState
' dictionary using code such as the following:
'
' Private Property _memberVariable() As Object
' Get
' _memberVariable = FormState("_memberVariable")
' End Get
' Set
' FormState("_memberVariable") = value
' End Set
' End Property

' NOTE: The following procedure is required by Microsoft InfoPath.
' It can be modified using Microsoft InfoPath.
Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup
AddHandler DirectCast(EventManager.ControlEvents("CTRL23_5"), ButtonEvent).Clicked, AddressOf CTRL23_5_Clicked
End Sub

Public Sub CTRL23_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

'declare Webswevice
Dim BudgetWS As New Budget.BudgetWS
'declare dataset
Dim dsTransactions As New DataSet
Dim dtTransactions As DataTable
Dim drTransactions As DataRow
' Dataset Coulmns
Dim clmID As DataColumn
Dim clmOperatingDate As DataColumn
Dim clmItemCode As DataColumn
Dim clmAssetCategoryID As DataColumn
Dim clmCompanyDescription As DataColumn
Dim clmPCGroup As DataColumn
Dim clmPCDesc As DataColumn
Dim clmCCGroup As DataColumn
Dim clmCCDesc As DataColumn
Dim clmQty As DataColumn
Dim clmCurrency As DataColumn


dtTransactions = New Data.DataTable()

clmID = New Data.DataColumn("ID", Type.GetType("System.Int32"))
clmOperatingDate = New Data.DataColumn("OperatingDate", Type.GetType("System.String"))
clmItemCode = New Data.DataColumn("ItemCode", Type.GetType("System.String"))
clmAssetCategoryID = New Data.DataColumn("AssetCategoryID", Type.GetType("System.String"))
clmCompanyDescription = New Data.DataColumn("CompanyDescription", Type.GetType("System.String"))
clmPCGroup = New Data.DataColumn("PCGroup", Type.GetType("System.String"))
clmPCDesc = New Data.DataColumn("PCDesc", Type.GetType("System.String"))
clmCCGroup = New Data.DataColumn("CCGroup", Type.GetType("System.String"))
clmCCDesc = New Data.DataColumn("CCDesc", Type.GetType("System.String"))
clmQty = New Data.DataColumn("Qty", Type.GetType("System.Decimal"))
clmCurrency = New Data.DataColumn("Currency", Type.GetType("System.String"))

dtTransactions.Columns.Add(clmID)
dtTransactions.Columns.Add(clmOperatingDate)
dtTransactions.Columns.Add(clmItemCode)
dtTransactions.Columns.Add(clmAssetCategoryID)
dtTransactions.Columns.Add(clmCompanyDescription)
dtTransactions.Columns.Add(clmPCGroup)
dtTransactions.Columns.Add(clmPCDesc)
dtTransactions.Columns.Add(clmCCGroup)
dtTransactions.Columns.Add(clmCCDesc)
dtTransactions.Columns.Add(clmQty)
dtTransactions.Columns.Add(clmCurrency)


'drTransactions = dtTransactions.NewRow()
'loop
Dim TableRows As XPathNodeIterator = Me.MainDataSource.CreateNavigator().Select("/my:myFields/my:group5/my:group6", NamespaceManager)
For i As Integer = 1 To TableRows.Count
Dim repTable As XPathNavigator = Me.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group5/my:group6[" & i & "]", NamespaceManager)
Dim nID As XPathNavigator = repTable.SelectSingleNode("my:ID", NamespaceManager) '/my:myFields/my:group5/my:group6/
Dim dtOperatingDate As XPathNavigator = repTable.SelectSingleNode("my:OperatingDate", NamespaceManager)

Dim nItemCode As XPathNavigator = repTable.SelectSingleNode("my:ItemCode", NamespaceManager)
Dim nAssetCategoryID As XPathNavigator = repTable.SelectSingleNode("my:AssetCategoryID", NamespaceManager)
Dim strCompanyDescription As XPathNavigator = repTable.SelectSingleNode("my:CompanyDescription", NamespaceManager)
Dim strPCGroup As XPathNavigator = repTable.SelectSingleNode("my:PCGroup", NamespaceManager)
Dim strPCDesc As XPathNavigator = repTable.SelectSingleNode("my:PCDesc", NamespaceManager)
Dim strCCGroup As XPathNavigator = repTable.SelectSingleNode("my:CCGroup", NamespaceManager)
Dim strCCDesc As XPathNavigator = repTable.SelectSingleNode("my:CCDesc", NamespaceManager)
Dim nQty As XPathNavigator = repTable.SelectSingleNode("my:Qty", NamespaceManager)
Dim nCurrency As XPathNavigator = repTable.SelectSingleNode("my:Currency", NamespaceManager)

drTransactions = dtTransactions.NewRow()
drTransactions("ID") = nID.Value
drTransactions("OperatingDate") = dtOperatingDate.Value
drTransactions("ItemCode") = nItemCode.Value
drTransactions("AssetCategoryID") = nAssetCategoryID.Value
drTransactions("CompanyDescription") = strCompanyDescription.Value
drTransactions("PCGroup") = strPCGroup.Value
drTransactions("PCDesc") = strPCDesc.Value
drTransactions("CCGroup") = strCCGroup.Value
drTransactions("CCDesc") = strCCDesc.Value
drTransactions("Qty") = nQty.Value
drTransactions("Currency") = nCurrency.Value
dtTransactions.Rows.Add(drTransactions)
Next

'---------------
dsTransactions.Tables.Add(dtTransactions)
BudgetWS.BudgetTransactionsInsertData(dsTransactions)



'XPathNavigator mainDataNavigator = MainDataSource.CreateNavigator();

' ' Get objects for the two value nodes hooked up to the data connection
' XPathNavigator employeeNode= mainDataNavigator.SelectSingleNode("create a field to hold the employee name value for the submit data connection and put its XPath here", NamespaceManager);
' XPathNavigator productNode = mainDataNavigator.SelectSingleNode("create a field to hold the product name and put its XPath here", NamespaceManager);
' Loop through each node of the repeating group
' foreach (XPathNavigator values in mainDataNavigator.Select("/dfs:myFields/dfs:dataFields/d:EE_Prod_Cat_Task", NamespaceManager))
' {
' // copy the values from this group's nodes to the submit fields
' employeeNode.SetValue(values.SelectSingleNode("d:Employee/@EmployeeName", NamespaceManager).Value);
' productNode.SetValue(values.SelectSingleNode("d:Product/@ProductName", NamespaceManager).Value);

' // Invoke the data connection
' DataConnections["Data_Submit"].Execute();


''modified code
''' Write your code here.
'Dim TableRows As XPathNodeIterator = Me.MainDataSource.CreateNavigator().Select("/my:myFields/my:testw", NamespaceManager)
'For i As Integer = 1 To TableRows.Count
' Dim repTable As XPathNavigator = Me.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:testw[" & i & "]", NamespaceManager)
' Dim taskOwner As XPathNavigator = repTable.SelectSingleNode("my:TransDate", NamespaceManager)

' taskOwner.SetValue(taskOwner.Value.ToLower())
' DataConnections("Web Service Submit").Execute()


'original code
'' Write your code here.
'Dim TableRows As XPathNodeIterator = Me.MainDataSource.CreateNavigator().Select("/my:myFields/my:testw", NamespaceManager)
'For i As Integer = 1 To TableRows.Count
' Dim repTable As XPathNavigator = Me.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:testw[" & i & "]", NamespaceManager)

' Dim taskOwner As XPathNavigator = repTable.SelectSingleNode("my:TransDate", NamespaceManager)
' 'Dim Field1 As XPathNavigator = Me.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field1", NamespaceManager)
' 'Field1.SetValue(taskOwner.Value.ToString())
' 'WebServiceConnection wsSubmit = (WebServiceConnection)Me.DataConnections["Web Service Submit"];
' 'DataConnections["Web Service Submit"].Execute();
' ' 'taskOwner.SetValue(taskOwner.Value.ToLower())
' DataConnections("Web Service Submit").Execute()







'Next


End Sub

End Class
End Namespace

'Public Sub CTRL23_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

' 'declare Webswevice
' Dim BudgetWS As New Budget.BudgetWS
' 'declare dataset
' Dim dsTransactions As New DataSet
' Dim dtTransactions As DataTable
' Dim drTransactions As DataRow
' ' Dataset Coulmns
' Dim clmID As DataColumn
' Dim clmOperatingDate As DataColumn
' Dim clmItemCode As DataColumn
' Dim clmAssetCategoryID As DataColumn
' Dim clmCompanyDescription As DataColumn
' Dim clmPCGroup As DataColumn
' Dim clmPCDesc As DataColumn
' Dim clmCCGroup As DataColumn
' Dim clmCCDesc As DataColumn
' Dim clmQty As DataColumn
' Dim clmCurrency As DataColumn


' dtTransactions = New Data.DataTable()

' clmID = New Data.DataColumn("ID", Type.GetType("System.Int32"))
' clmOperatingDate = New Data.DataColumn("OperatingDate", Type.GetType("System.String"))
' clmItemCode = New Data.DataColumn("ItemCode", Type.GetType("System.String"))
' clmAssetCategoryID = New Data.DataColumn("AssetCategoryID", Type.GetType("System.String"))
' clmCompanyDescription = New Data.DataColumn("CompanyDescription", Type.GetType("System.String"))
' clmPCGroup = New Data.DataColumn("PCGroup", Type.GetType("System.String"))
' clmPCDesc = New Data.DataColumn("PCDesc", Type.GetType("System.String"))
' clmCCGroup = New Data.DataColumn("CCGroup", Type.GetType("System.String"))
' clmCCDesc = New Data.DataColumn("CCDesc", Type.GetType("System.String"))
' clmQty = New Data.DataColumn("Qty", Type.GetType("System.Decimal"))
' clmCurrency = New Data.DataColumn("Currency", Type.GetType("System.String"))

' dtTransactions.Columns.Add(clmID)
' dtTransactions.Columns.Add(clmOperatingDate)
' dtTransactions.Columns.Add(clmItemCode)
' dtTransactions.Columns.Add(clmAssetCategoryID)
' dtTransactions.Columns.Add(clmCompanyDescription)
' dtTransactions.Columns.Add(clmPCGroup)
' dtTransactions.Columns.Add(clmPCDesc)
' dtTransactions.Columns.Add(clmCCGroup)
' dtTransactions.Columns.Add(clmCCDesc)
' dtTransactions.Columns.Add(clmQty)
' dtTransactions.Columns.Add(clmCurrency)


' drTransactions = dtTransactions.NewRow()
' 'loop
' Dim TableRows As XPathNodeIterator = Me.MainDataSource.CreateNavigator().Select("/my:myFields/my:group1", NamespaceManager)
' For i As Integer = 1 To TableRows.Count
' Dim repTable As XPathNavigator = Me.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group1[" & i & "]", NamespaceManager)
' Dim nID As XPathNavigator = repTable.SelectSingleNode("my:group2/my:ID", NamespaceManager)
' Dim dtOperatingDate As XPathNavigator = repTable.SelectSingleNode("my:group2/my:OperatingDate", NamespaceManager)

' Dim nItemCode As XPathNavigator = repTable.SelectSingleNode("my:group2/my:ItemCode", NamespaceManager)
' Dim nAssetCategoryID As XPathNavigator = repTable.SelectSingleNode("my:group2/my:AssetCategoryID", NamespaceManager)
' Dim strCompanyDescription As XPathNavigator = repTable.SelectSingleNode("my:group2/my:CompanyDescription", NamespaceManager)
' Dim strPCGroup As XPathNavigator = repTable.SelectSingleNode("my:group2/my:PCGroup", NamespaceManager)
' Dim strPCDesc As XPathNavigator = repTable.SelectSingleNode("my:group2/my:PCDesc", NamespaceManager)
' Dim strCCGroup As XPathNavigator = repTable.SelectSingleNode("my:group2/my:CCGroup", NamespaceManager)
' Dim strCCDesc As XPathNavigator = repTable.SelectSingleNode("my:group2/my:CCDesc", NamespaceManager)
' Dim nQty As XPathNavigator = repTable.SelectSingleNode("my:group2/my:Qty", NamespaceManager)
' Dim nCurrency As XPathNavigator = repTable.SelectSingleNode("my:group2/my:Currency", NamespaceManager)


' drTransactions("ID") = nID.Value
' drTransactions("OperatingDate") = dtOperatingDate.Value
' drTransactions("ItemCode") = nItemCode.Value
' drTransactions("AssetCategoryID") = nAssetCategoryID.Value
' drTransactions("CompanyDescription") = strCompanyDescription.Value
' drTransactions("PCGroup") = strPCGroup.Value
' drTransactions("PCDesc") = strPCDesc.Value
' drTransactions("CCGroup") = strCCGroup.Value
' drTransactions("CCDesc") = strCCDesc.Value
' drTransactions("Qty") = nQty.Value
' drTransactions("Currency") = nCurrency.Value
' dtTransactions.Rows.Add(drTransactions)
' Next

' '---------------
' dsTransactions.Tables.Add(dtTransactions)

' BudgetWS.BudgetTransactionsInsertData(dsTransactions)



' 'XPathNavigator mainDataNavigator = MainDataSource.CreateNavigator();

' ' ' Get objects for the two value nodes hooked up to the data connection
' ' XPathNavigator employeeNode= mainDataNavigator.SelectSingleNode("create a field to hold the employee name value for the submit data connection and put its XPath here", NamespaceManager);
' ' XPathNavigator productNode = mainDataNavigator.SelectSingleNode("create a field to hold the product name and put its XPath here", NamespaceManager);
' ' Loop through each node of the repeating group
' ' foreach (XPathNavigator values in mainDataNavigator.Select("/dfs:myFields/dfs:dataFields/d:EE_Prod_Cat_Task", NamespaceManager))
' ' {
' ' // copy the values from this group's nodes to the submit fields
' ' employeeNode.SetValue(values.SelectSingleNode("d:Employee/@EmployeeName", NamespaceManager).Value);
' ' productNode.SetValue(values.SelectSingleNode("d:Product/@ProductName", NamespaceManager).Value);

' ' // Invoke the data connection
' ' DataConnections["Data_Submit"].Execute();


' ''modified code
' ''' Write your code here.
' 'Dim TableRows As XPathNodeIterator = Me.MainDataSource.CreateNavigator().Select("/my:myFields/my:testw", NamespaceManager)
' 'For i As Integer = 1 To TableRows.Count
' ' Dim repTable As XPathNavigator = Me.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:testw[" & i & "]", NamespaceManager)
' ' Dim taskOwner As XPathNavigator = repTable.SelectSingleNode("my:TransDate", NamespaceManager)

' ' taskOwner.SetValue(taskOwner.Value.ToLower())
' ' DataConnections("Web Service Submit").Execute()


' 'original code
' '' Write your code here.
' 'Dim TableRows As XPathNodeIterator = Me.MainDataSource.CreateNavigator().Select("/my:myFields/my:testw", NamespaceManager)
' 'For i As Integer = 1 To TableRows.Count
' ' Dim repTable As XPathNavigator = Me.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:testw[" & i & "]", NamespaceManager)

' ' Dim taskOwner As XPathNavigator = repTable.SelectSingleNode("my:TransDate", NamespaceManager)
' ' 'Dim Field1 As XPathNavigator = Me.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field1", NamespaceManager)
' ' 'Field1.SetValue(taskOwner.Value.ToString())
' ' 'WebServiceConnection wsSubmit = (WebServiceConnection)Me.DataConnections["Web Service Submit"];
' ' 'DataConnections["Web Service Submit"].Execute();
' ' ' 'taskOwner.SetValue(taskOwner.Value.ToLower())
' ' DataConnections("Web Service Submit").Execute()







' 'Next


'End Sub

________________________________________

Notice: The transmitted information is intended only for the person or entity to which it is addressed. It may contain confidential and/or privileged material. Any review, retransmission, dissemination or any other use of or taking any action in reliance upon this information by persons or entities other than the intended recipient(s) is strictly prohibited. If you receive this information in error, please contact the sender and delete the material from your system immediately.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900