How to convert this VB code to C#?

J

Jason Huang

Hi,

I would like to convert the following Visual Basic code to C#, does someone
has free tool to convert it?



Function PreConnect() As Boolean

Dim strDSN$, strUidPwd$, strDatabase$, strConnect$

Dim hFile As Integer, strBuffer As String

' open and read

hFile = FreeFile

Open App.Path & "\" & etcBootFile For Input As hFile

Line Input #hFile, strBuffer

strUidPwd = Decode(strBuffer)

Line Input #hFile, strDSN

Line Input #hFile, strDatabase

Close hFile

' try connect

If strDSN = "" Or strUidPwd = "" Then Exit Function

strConnect = "ODBC;DSN=" & strDSN & ";" & strUidPwd & ";DATABASE=" &
strDatabase

' pre-connect

PreConnect = ConnAttemp(strConnect)

End Function



Function Decode(strWhat$) As String

Decode = Encode(strWhat)

End Function

' 5/23

Function Encode(strWhat$) As String

Dim i As Integer, strResult As String

Dim b As Byte

For i = 1 To Len(strWhat)

b = Asc(Mid(strWhat, i, 1)) Xor etcEncodeKey

strResult = strResult & Chr(b)

Next

Encode = strResult

End Function



Thanks for help.



Jason
 
G

Guest

Compile and use Roeder's Reflector is one option. Most of the .NET
"decompilers" create C# code.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
G

Guest

(Thanks Jon)

Note that while not free, we do offer Demo Editions which convert snippets
up to 100 lines.

Note also that Instant C# only converts Microsoft.VisualBasic namespace
functions which have direct, unambiguous, functionally-equivalent methods in
the .NET Framework. The VB file functions are left as calls to the
Microsoft.VisualBasic namespace (but many string and date functions, MsgBox,
IIf, and constants are converted).

David Anton
www.tangiblesoftwaresolutions.com
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top