VB to c# conversion...

F

filia&sofia

Hello,

any volunteers to convert VB source code below to c#? I really would
appreciate that, because I wouldn't like to learn two new languages...
This function can be found from ExceleTel Inc www-site and is
copyrighted by the corresponding corporation. Unfortunately, they
didn't have c# version from this... Thx in advance!

Source:
-----------

Private Function IsVoiceModem() As Boolean
Dim ModemMediaModes As Integer
Dim VoiceModemMediaModes As Integer

' These are the minimal media modes expected for standard data
modems
ModemMediaModes = LINEMEDIAMODE_INTERACTIVEVOICE +
LINEMEDIAMODE_DATAMODEM
' These are the minimal media modes expected for voice modems
VoiceModemMediaModes = ModemMediaModes + LINEMEDIAMODE_UNKNOWN + _
LINEMEDIAMODE_AUTOMATEDVOICE

' Check to see if the selected device is a modem and it is a voice
modem
If (InStr(1, etLine1.TAPITSP, "Modem", 1) > 0) And _
((etLine1.DeviceMediaModesAvailable And VoiceModemMediaModes)
VoiceModemMediaModes) Then
IsVoiceModem = True
Else
IsVoiceModem = False
End If
End Function

Private Sub SetCompletion(ByVal Status As String)
Select Case CurrentPhoneNumber
Case 1
If TextCompletion1.Text = "" Then
TextCompletion1.Text = Status
End If
Case 2
If TextCompletion2.Text = "" Then
TextCompletion2.Text = Status
End If
Case 3
If TextCompletion3.Text = "" Then
TextCompletion3.Text = Status
End If
Case 4
If TextCompletion4.Text = "" Then
TextCompletion4.Text = Status
End If
Case 5
If TextCompletion5.Text = "" Then
TextCompletion5.Text = Status
End If
End Select
End Sub
 
M

Miroslav Stampar

private bool IsVoiceModem()
{
int ModemMediaModes;
int VoiceModemMediaModes;

//These are the minimal media modes expected for standard
data modems
ModemMediaModes = LINEMEDIAMODE_INTERACTIVEVOICE +
LINEMEDIAMODE_DATAMODEM;

//These are the minimal media modes expected for voice
modems
VoiceModemMediaModes = ModemMediaModes +
LINEMEDIAMODE_UNKNOWN + LINEMEDIAMODE_AUTOMATEDVOICE;

//Check to see if the selected device is a modem and it is
a voice modem

if(etLine1.TAPITSP.Contains("Modem")&&((etLine1.DeviceMediaModesAvailable&VoiceModemMediaModes)>=VoiceModemMediaModes))
IsVoiceModem = true;
else
IsVoiceModem = false;
}

private void SetCompletion(string Status)
{
switch (CurrentPhoneNumber)
{
case 1:
if (TextCompletion1.Text == "")
TextCompletion1.Text = Status;
break;
case 2:
if (TextCompletion2.Text == "")
TextCompletion2.Text = Status;
break;
case 3:
if (TextCompletion3.Text == "")
TextCompletion3.Text = Status;
break;
case 4:
if (TextCompletion4.Text == "")
TextCompletion4.Text = Status;
break;
case 5:
if (TextCompletion5.Text == "")
TextCompletion5.Text = Status;
break;
default:
break;
}
}

filia&sofia je napisao/la:
 
A

Alberto Poblacion

filia&sofia said:
any volunteers to convert VB source code below to c#?


A few messages back another poster asked a very similar question, and I
pointed out that several translation tools are publicly available on the
'net. For example, the code below is the result of translationg your sample
with http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx.
There is one thing that wil not immediately work in the translated code,
which is the call to "InStr". You can provide similar functionality in C# by
means of string.IndexOf, rather than importing the namespace
Microsoft.VisualBasic (which was probably implied in the original code but
was not visible in the sample). You will also want to replace the "&"
operator with "&&" (both are "AND" in VB).


private bool IsVoiceModem()
{
int ModemMediaModes;
int VoiceModemMediaModes;
ModemMediaModes = LINEMEDIAMODE_INTERACTIVEVOICE + LINEMEDIAMODE_DATAMODEM;
VoiceModemMediaModes = ModemMediaModes + LINEMEDIAMODE_UNKNOWN +
LINEMEDIAMODE_AUTOMATEDVOICE;
if ((InStr(1, etLine1.TAPITSP, "Modem", 1) > 0) &
((etLine1.DeviceMediaModesAvailable & VoiceModemMediaModes) >=
VoiceModemMediaModes)) {
IsVoiceModem = true;
} else {
IsVoiceModem = false;
}
}

private void SetCompletion(string Status)
{
if (CurrentPhoneNumber == 1) {
if (TextCompletion1.Text == "") {
TextCompletion1.Text = Status;
}
} else if (CurrentPhoneNumber == 2) {
if (TextCompletion2.Text == "") {
TextCompletion2.Text = Status;
}
} else if (CurrentPhoneNumber == 3) {
if (TextCompletion3.Text == "") {
TextCompletion3.Text = Status;
}
} else if (CurrentPhoneNumber == 4) {
if (TextCompletion4.Text == "") {
TextCompletion4.Text = Status;
}
} else if (CurrentPhoneNumber == 5) {
if (TextCompletion5.Text == "") {
TextCompletion5.Text = Status;
}
}
}
 
G

Guest

The problem with the above 2 conversions is that the implicit temp method
name variable remains (IsVoiceModem = true, etc.). You must use explicit
'return' statements in C#.

(The following is produced by Instant C#):
private bool IsVoiceModem()
{
bool tempIsVoiceModem = false;
int ModemMediaModes = 0;
int VoiceModemMediaModes = 0;

// These are the minimal media modes expected for standard data modems
ModemMediaModes = LINEMEDIAMODE_INTERACTIVEVOICE + LINEMEDIAMODE_DATAMODEM;
// These are the minimal media modes expected for voice modems
VoiceModemMediaModes = ModemMediaModes + LINEMEDIAMODE_UNKNOWN +
LINEMEDIAMODE_AUTOMATEDVOICE;

// Check to see if the selected device is a modem and it is a voice modem
if (((etLine1.TAPITSP.ToUpper().IndexOf("Modem".ToUpper(), 0) + 1) > 0) &
((etLine1.DeviceMediaModesAvailable & VoiceModemMediaModes) >=
VoiceModemMediaModes))
{
tempIsVoiceModem = true;
}
else
{
tempIsVoiceModem = false;
}
return tempIsVoiceModem;
}

private void SetCompletion(string Status)
{
switch (CurrentPhoneNumber)
{
case 1:
if (TextCompletion1.Text == "")
{
TextCompletion1.Text = Status;
}
break;
case 2:
if (TextCompletion2.Text == "")
{
TextCompletion2.Text = Status;
}
break;
case 3:
if (TextCompletion3.Text == "")
{
TextCompletion3.Text = Status;
}
break;
case 4:
if (TextCompletion4.Text == "")
{
TextCompletion4.Text = Status;
}
break;
case 5:
if (TextCompletion5.Text == "")
{
TextCompletion5.Text = Status;
}
break;
}
}

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
 
M

Michael D. Ober

Create an additional VB project as a DLL library and put this function in
it. After you compile once, you can then use the function directly.

Mike Ober.
 

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

Similar Threads

An A-Z guide to computing 6

Top