473,419 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

How to convert this VB code to C#?

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
Nov 17 '05 #1
4 1959
Jason Huang <Ja************@hotmail.com> wrote:
I would like to convert the following Visual Basic code to C#, does someone
has free tool to convert it?


Try Instant C#:
http://www.instantcsharp.com/

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
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!
***************************
"Jason Huang" wrote:
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

Nov 17 '05 #3
Jim
That code is VB not VB.net
Nov 17 '05 #4
(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

"Jon Skeet [C# MVP]" wrote:
Jason Huang <Ja************@hotmail.com> wrote:
I would like to convert the following Visual Basic code to C#, does someone
has free tool to convert it?


Try Instant C#:
http://www.instantcsharp.com/

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
3
by: Thubaiti | last post by:
Hi, I have this code in my ASP.NET and I want to convert it to C# (code behind) <asp:Repeater id="subCategoryRepeater" runat="server"> <ItemTemplate> <ul> <li> <asp:HyperLink...
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
0
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.