Click here to Skip to main content
15,176,221 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Please tell me in converting the following code to visual basic.net 2010:
VB
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
Posted
Updated 1-Feb-15 0:16am
v2
Comments
Kenneth Haugland 1-Feb-15 5:15am
   
Oh, thank you, I was looking for something to do... no wait. You try, and come back when you are stuck on something.

Personally I'd use this though:
https://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument(v=vs.110).aspx

and forget about the vb6 code, if you know what to look for.

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..
   
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.
   

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