Convert VB Script to VB.Net

z.arriola

New member
Joined
Oct 6, 2008
Messages
2
Programming Experience
1-3
im migrating ms sql 2000 to ms sql 2005 so where talking about vbscript to vb.net translation can someone help me translating these set of vbscripts
Function Main()
Dim arrSailWeeks


arrSailWeeks = Split(ReadFile(DTSGlobalVariables("FileOfSailWeeks").Value), vbCrLf)

DTSGlobalVariables("SailWeekIndex").Value = 0
DTSGlobalVariables("SailWeek").Value = arrSailWeeks(DTSGlobalVariables("SailWeekIndex").Value)

Main = DTSTaskExecResult_Success
End Function

Function ReadFile(strFilePathAndName)
Dim strFileContents

Set objFS = CreateObject("Scripting.FileSystemObject")

If objFS.FileExists(strFilePathAndName) = True Then
Set objTextStream = objFS.OpenTextFile(strFilePathAndName,1)
strFileContents = objTextStream.ReadAll
objTextStream.Close
Set objTextStream = Nothing
End if

Set objFS = nothing

ReadFile = strFileContents
End Function
YOUR HELP WILL BE MUCH APPRICIATED :D THANKS IN ADVANCE
 
yeah for vbscript what i want to happen to full translate it to vb.net some of the syntax is not recognized by vb.net from vb script
 
Looks ok, just make sure to declare and initialise the variable types (eg, Dim strFileContents becomes Dim strFileContents As String = "").

There is a VB6 to .NET migration tool in Visual Studio, but I don't recommend using that or you'll get a sore brain. :)
 
'vbCrLf' should be 'Environment.NewLine'

Neither of your two functions return a value.

The 'Set' Keyword is redundant in VB.Net

Look into object initialization and Object instantiaion.

VB.NET:
Function Main()
Dim arrSailWeeks


arrSailWeeks = Split(ReadFile(DTSGlobalVariables("FileOfSailWeeks ").Value), vbCrLf)

DTSGlobalVariables("SailWeekIndex").Value = 0
DTSGlobalVariables("SailWeek").Value = arrSailWeeks(DTSGlobalVariables("SailWeekIndex").V alue)

Main = DTSTaskExecResult_Success
End Function

Function ReadFile(strFilePathAndName) 
Dim strFileContents 

Set objFS = CreateObject("Scripting.FileSystemObject") 

If objFS.FileExists(strFilePathAndName) = True Then 
Set objTextStream = objFS.OpenTextFile(strFilePathAndName,1) 
strFileContents = objTextStream.ReadAll 
objTextStream.Close 
Set objTextStream = Nothing
End if 

Set objFS = nothing 

ReadFile = strFileContents
End Function
 
Back
Top