将vb6源转换为visual basic.net 2010 [英] Conversion vb6 source to visual basic.net 2010

查看:88
本文介绍了将vb6源转换为visual basic.net 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我将以下代码转换为visual basic.net 2010:

Please tell me in converting the following code to visual basic.net 2010:

Dim FName As String   ' FileName of the html file
Dim LeftX As Integer   ' Global x coordinate for the nodes in html
Dim TopY As Integer    ' Global Y coordinate for nodes in html
Dim totalHTML As String ' this variable holds the HTML code generated throughout the program
Const TopIncrement = 20   ' the number of pixels of difference between nodes
Const LeftIncrement = 30


Public Function WriteTextFileContents(TeXt As String, FileName As String)
' Simple Function writes text to a file
' Used for outputing to html format
    Dim fNum As Integer, isOpen As Boolean
    On Error GoTo ErrHandle
    fNum = FreeFile()
        Open FileName For Output As #fNum
        isOpen = True
        Print #fNum, TeXt
ErrHandle:
        If isOpen Then Close #fNum
End Function

Public Function ReadTextFileContents(FileName As String) As String
    ' Simply Reads a text file
    Dim fNum As Integer, isOpen As Boolean
    On Error GoTo ErrHandle
    fNum = FreeFile()
    Open FileName For Input As #fNum
    isOpen = True
    ReadTextFileContents = Input(LOF(fNum), fNum)
ErrHandle:
    If isOpen Then Close #fNum
End Function

Private Function horizontalline(top, x1, x2)
    ' Returns VML (Vector Markup language) equivalent
    ' Of a horizontal line
    Dim width
    If x1 > x2 Then width = x1 - x2 Else width = x2 - x1
    horizontalline = "<v:rect style='removed:absolute;removed" & x1 & ";removed" & top & ";width:" & width & "px;height:1px;Z-INDEX: 0;'></v:rect>"
End Function

Private Function verticalline(left, y1, y2)
    ' Returns VML (Vector Markup language) equivalent
    ' Of a vertical line
    Dim height
    If y1 > y2 Then height = y1 - y2 Else height = y2 - y1
    verticalline = "<v:rect style='removed:absolute;removed" & left & ";removed" & y1 & ";width:1px;height:" & height & "px;Z-INDEX: 0;'></v:rect>"
End Function

Public Function SaveAllChildrenOf(indexOfNodeToBePrinted As Integer, htmlFileName As String)
    ' The main public function . Does three things
    ' Firstly, Initializes the program and the html file
    Initialise htmlFileName
    ' Secondly calls the recursive function to convert the nodes to html
    PrintNode indexOfNodeToBePrinted
    ' This statement to write the html to a file
    WriteTextFileContents totalHTML, htmlFileName
End Function

Private Function PrintNode(NodeIndex As Integer)
    ' First one of the two recursive functions that go through the tree
    
    TopY = TopY + TopIncrement ' this topY variable maintains the Y coordinates of the nodes in html
    Form1.Tree.Nodes(NodeIndex).Tag = TopY 'Storing the Y coordinates in the Tag part of the treeview control so that they can be refrenced later by their last children
    WriteHTML Form1.Tree.Nodes(NodeIndex).TeXt ' This functions just produces html at the current x and y coordinates and increments the y coordinate
    
    If NodeIndex <> 1 Then  ' SInce the first node would not have parent
        If Form1.Tree.Nodes(NodeIndex).index = Form1.Tree.Nodes(NodeIndex).Parent.Child.LastSibling.index Then  ' This means if this is the last child of its parent then
             totalHTML = totalHTML & verticalline(LeftX - LeftIncrement + 3, Int(Form1.Tree.Nodes(NodeIndex).Parent.Tag) + 7, TopY + 7)  ' then draw a vertical line from parents y (as stored in tag property(see Above)) coordinate to its Y coordinate (A shift of 7 pixels is given to improve looks)
        End If
    End If

    
    PrintAllChildren (NodeIndex) ' this function goes through all the children of this node and calls the current method for each children.
End Function

Private Function PrintAllChildren(index As Integer)
    ' What this function does is that it calls the above function for all the children of the node specified
    ' So these two functions basically call each other to go through the whole tree
    If Form1.Tree.Nodes(index).Children = 0 Then Exit Function ' No use of the function if it doesnt even have children
    
    LeftX = LeftX + LeftIncrement ' The children should be a little to the left of the parent. Dont you think?
    Dim curIndex As Integer 'This would be the Index of the current child
    curIndex = Form1.Tree.Nodes(index).Child.index 'getting its childs index
    For f = 1 To Form1.Tree.Nodes(index).Children ' for all children
        PrintNode (curIndex) 'call the above function
        If f <> Form1.Tree.Nodes(index).Children Then curIndex = Form1.Tree.Nodes(curIndex).Next.index ' if we are not at the last child then goto next child
    Next
    LeftX = LeftX - LeftIncrement ' after all the children have been displayed (And their children have been displayed), back to the old X coordinate
End Function

Private Function WriteHTML(TeXt As String)
    ' Simple function to use <div> tags and style sheets to put the node at a specific x and y coordinate in the web page
    totalHTML = totalHTML & "<div style='{BACKGROUND-COLOR: white;color:black;Z-INDEX: 1;removed:absolute;top=" & TopY & ";left=" & LeftX & ";}'>" & TeXt & "</div>" & horizontalline(TopY + 7, LeftX - LeftIncrement + 3, LeftX + 3)
End Function

Private Function Initialise(FileName As String)
    ' Initalizing variables
    FName = FileName   ' The FileName
    LeftX = 10               ' Left Margin. Change this to change the left margin
    TopY = 10                ' Top Margin. Change this to change the top margin
    totalHTML = "<font face='courier new'><html xmlns:v='urn:schemas-microsoft-com:vml'><head> <style> v\:* { behavior: url(#default#VML); } </style> </head><pre>"  ' Html to Initialise XML VML stuff
End Function

推荐答案

这是一个可悲的事实,如果您打算使用VB.Net,您应该学习语言。转换代码后,您将需要知道如何修复那些不能以相同方式工作的部分,并且您需要知道如何维护代码。



没有免费粘贴你的代码在这里获得VB.Net代码返回解决方案。然而,它真的不是那么糟糕。有资源可以帮助您将代码转换(读取...重写)到VB.Net。



这是一个很好的资源,你可以参考:

他们甚至有一个你可以下载的免费电子书。

https://msdn.microsoft.com/en-us/vstudio/ms788229.aspx [ ^ ]



去吧!你最终会成为一个更好的程序员。
Here's the sad fact, if you are going to work with VB.Net, you should learn the language. Once you convert the code, you will need to know how to fix that parts that won't work the same way, and you will need to know how to maintain the code.

There is no "free" paste your code here get VB.Net code back solution. However, it's really not all that bad. There are resources out there that will help you in converting (Read... rewriting) your code to VB.Net.

Here is a good resource you can refer to:
They even have a free e-book you can download.
https://msdn.microsoft.com/en-us/vstudio/ms788229.aspx[^]

Go get 'em! You will be a better programmer in the end for having done this..


这听起来有点刺耳。 VB6代码对你来说是无用的。



这是因为VB.NET因.NET Framework提供的功能和功能而异乎寻常。在VB6中可以使用几行代码完成代码页面的操作。只需几行代码即可在.NET中完成。



您转换此代码的工作相当于理解VB6代码背后的重点,完全废弃它并在VB.NET中重写。机会真的很好,代码会更短更容易理解。



提供了你理解.NET框架提供的功能。
This is going to sound a bit harsh. That VB6 code is USELESS to you.

This is because VB.NET is so vastly different because of the capabilities and functionality offered by the .NET Framework. Things that would take you pages of code to do in VB6 can be done in .NET with a just few lines of code.

Your job converting this code amounts to understanding the point behind the VB6 code and completely scrapping it and rewriting in VB.NET. Chances are really good the code is going to be much shorter and easier to understand.

PROVIDED YOU UNDERSTAND WHAT CAPABILITIES THE .NET FRAMEWORK OFFERS.


这篇关于将vb6源转换为visual basic.net 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆