VB6 to VB.NET Val(mid&( and Line Input #

cnash52

New member
Joined
Feb 18, 2016
Messages
3
Programming Experience
Beginner
I have a lengthy project of converting VB6 code to VB.NET. This is the beginning of the code. I can't figure out how to change the val(mid$( to VB.NET and the Line Input # doesn't seem to have a direct translation to VB.NET either. I am trying to learn how to go about the conversion to ensure functionality. The first module is about 700 lines of text and the second graphical is over 2000. There are many Private Sub's like the cmdlist_click() that I don't understand how to convert over with all of the true and false statements. I have worked with code in excel VBA but VB.Net is very different. Thank you for your time.

Code:
Option Explicit
Dim Sens(75) As Double
Public LnSlope As Double, UFile As String, DFile As String, ProjInfo As String, RutBarWidth As String
Public retval As String, UpLine As String, UStation As Long, ISta As Double, StaCnt As Integer
Public MSta As Double, FSta As String, StrSta As String, Roll As Double, I As Integer, holdval As Double
Public DStation As Long, SensArray As Integer, MaxSens As Double, Sta As Integer, FlipSect As Boolean
Public Sta_Suffix As String, Sta_Prefix As String, Sta_str As String, UpChainCrown As Double, TempSens As Double
Public DnChainCrown As Double, CrownDelta As Double, myfile As String, oldpath As String, cpath As String
Public TruckLane As Boolean
Private Declare Function OSWinHelp% Lib "user32" Alias "WinHelpA" (ByVal hwnd&, ByVal HelpFile$, ByVal wCommand%, dwData As Any)
Private Sub cmdCurrentJob_Click()
'need to evaluate which unit system was used on previous job
 Open "c:\temp\asap\shim.txt" For Input As #1
 Line Input #1, ProjInfo
 RutBarWidth = Val(Mid$(ProjInfo, 40, 4))
 Close #1
 If RutBarWidth < 3000 Then
  MsgBox ("Previously loaded project was Imperial")
  Unload frmMain
  frmShim_Imp.Show
 Else
  MsgBox ("Previously loaded project was Metric")
  Unload frmMain
  frmShim_Met.Show
 End If
  
End Sub
Private Sub cmdList_Click()
    frmMain.Height = 4705
    drvList = "c:\"
    dirList = "c:\temp\asap\raw"
    filList = "*.raw"
    Frame3.Visible = True
    cmdCopy.Visible = False
    cmdProcess.Visible = False
    cmdList.Visible = False
    Picture2.Visible = True
    cmdSelUp.Visible = True
    cmdSelDn.Visible = True
    opImperial.Value = True
End Sub
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,331
Location
Norway
Programming Experience
10+
try this:
        Dim file = IO.File.OpenText("c:\temp\asap\shim.txt")
        Dim line = file.ReadLine
        Dim part = line.Substring(40, 4)
        Dim value = CInt(part)

Some related reading material:
File Class (System.IO)
StreamReader Methods (System.IO)
String Methods (System)
Type Conversion Functions (Visual Basic)

Writing application as VB.Net to what it is supposed to do is much better than trying to translate old VB6 code.
 

cnash52

New member
Joined
Feb 18, 2016
Messages
3
Programming Experience
Beginner
Thank you very much for your prompt response. I wanted to make my question more specific to fully follow the forum rules but it is very difficult for me with my lack of .net programming. I am going to review the materials you referenced before any more hail mary postings. Do you know of a good resource for graphical programming with VB.NET? I am going to have to enable a graphical representation of the data with best fit lines and area calculations.
 

Herman

Well-known member
Joined
Oct 18, 2011
Messages
882
Location
Montreal, QC, CA
Programming Experience
10+
Please, for the love of the G man, do NOT try to translate old VB6 code line by line. You are bound to fail.

Start with a blank pad of paper and a pen. Break down the original project into sections, and each section into functional parts.

Then recode that in .NET. That is the only way you will have something decent in the end. Most of the code will be forms related anyway, and that will all change. So start with making a mock up of your old UI in .NET, and recode it functionally. The only thing you have to make sure of is that each functional bit has the same input and output as the old code.

If you have a lot of code in VB6 COM libraries already, it will make your job easier. Create a new .NET project and add references to your old COM components. Visual Studio (.NET) will create Interop files for each. Copy them back into your main .NET project and add references to them. This way you reference the Interop file, the Interop file references the COM server, and you save translating on a whole bunch of code.
 
Top Bottom