473,398 Members | 2,389 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,398 software developers and data experts.

Convert VB.NEt to C# problem

I'm trying to convert the following (simplified) VB.Net code to C#,
that makes use of some externally developed COM code written in VB6.

VB.Net Code

Sub Main()
Dim oAPP As Object
Dim oApp2 As APP2.Class

Dim user As String
Dim pass As String
Dim db As String
Dim var1 as String

User = "user"
pass = "password"
db = "test"

oAPP = CreateObject("VBAPP.Session")
oAPP.Method1(user, pass, db)
oApp2 = oAPP.SessionItem("APP2")
var1 = oApp2.Properties.Item("Date").Value
End Sub

The C# Code looks like
static void Main(string[] args)
{
VBAPP.Session oApp;
APP2.Class oApp2;
string User = "user";
string pass = "password";
string db = "test";
string var1;

oAPP = new VBAPP.SessionClass();
oAPP.Method1(ref User, ref Pass, ref DataSource);
oApp2 = oAPP.get_SessionItem("APP2") as APP2.Class;
var1 = oApp2.Properties.Item(............
}

I'm trying to figure out how to get the same value for var1 as
oApp2.Properties.Item(.. wants a ref Object vIndex

When I add Object d = "Date"; and do oAppProperties.Item(ref d) it
returns System.___ComObject

What am I missing?

Thanks

Oct 5 '06 #1
7 1719
Mike,

Are you sure it is working in VB.Net

This would normally not work in VB.Net

oAPP = CreateObject("VBAPP.Session")
oAPP.Method1(user, pass, db)

(The code you make for this in C# is by the way complete different)

Cor
Oct 5 '06 #2

Yes, I'm sure it works in VB.Net - the code is in use right now and
returns a the value I expect.

Oct 5 '06 #3
Mike,

Then put in that VB.Net program in top Option Strict On

Cor

"Mike Howard" <mh********@gmail.comschreef in bericht
news:11*********************@m73g2000cwd.googlegro ups.com...
>
Yes, I'm sure it works in VB.Net - the code is in use right now and
returns a the value I expect.

Oct 5 '06 #4

Thanks, but I'm trying to get rid of the VB code

If I do:

App2.PropertyClass var1 = oApp2.Properties.Item(ref d) as
App2.PropertyClass;

and step through the code I can see in the watch window

var1.Value has a Value of "04-Oct-2006" and this gets returned when I
do a var1.Value in the immediate window, but I can't complie and
execute with Console.WriteLine(var1.Value);

I know I'm missing something basic here...

Oct 5 '06 #5
I have a solution but don't yet fully understand what's happening

If I do:

App2.PropertyClass var1 = oApp2.Properties.Item(ref d) as
App2.PropertyClass;
string f = var1.get_Value();

f contains what I was expecting.

get_Value is not one of the Options listed by intellisense and all the
other options that are such as var1.Length, var1.access worked as I
expected.

Oct 5 '06 #6

Mike

As a general rule of thumb. If you start with VB.net code and translate it.
The at the top of the VB.net COde, put the following declarations.
Option Explicit On
Option Strict On

Yes , I know you're not keeping the vb.net code.
But using those 2 will make a translation easier............... because C#
has "built in" .. "Option Explicit On" and "Option Strict On" (for lack of a
better way to describe it)

After it compiles in VB.net (with those 2 declarations), then you can work
on the translation in an easier fashion.

"Mike Howard" <mh********@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
I have a solution but don't yet fully understand what's happening

If I do:

App2.PropertyClass var1 = oApp2.Properties.Item(ref d) as
App2.PropertyClass;
string f = var1.get_Value();

f contains what I was expecting.

get_Value is not one of the Options listed by intellisense and all the
other options that are such as var1.Length, var1.access worked as I
expected.

Oct 5 '06 #7
Just for your information, if you want the equivalent C# late-binding approach:
public void Main()
{
object oAPP = null;
APP2.Class oApp2 = null;

string user = null;
string pass = null;
string db = null;
string var1 = null;

user = "user";
pass = "password";
db = "test";

System.Type oAPPType = System.Type.GetTypeFromProgID("VBAPP.Session");
oAPP = System.Activator.CreateInstance(oAPPType);
oAPPType.InvokeMember("Method1",
System.Reflection.BindingFlags.InvokeMethod, null, oAPP, new object[] {user,
pass, db});
oApp2 = oAPPType.InvokeMember("SessionItem",
System.Reflection.BindingFlags.InvokeMethod, null, oAPP, new object[]
{"APP2"});
var1 = oApp2.Properties["Date"].Value;
}

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Mike Howard" wrote:
I'm trying to convert the following (simplified) VB.Net code to C#,
that makes use of some externally developed COM code written in VB6.

VB.Net Code

Sub Main()
Dim oAPP As Object
Dim oApp2 As APP2.Class

Dim user As String
Dim pass As String
Dim db As String
Dim var1 as String

User = "user"
pass = "password"
db = "test"

oAPP = CreateObject("VBAPP.Session")
oAPP.Method1(user, pass, db)
oApp2 = oAPP.SessionItem("APP2")
var1 = oApp2.Properties.Item("Date").Value
End Sub

The C# Code looks like
static void Main(string[] args)
{
VBAPP.Session oApp;
APP2.Class oApp2;
string User = "user";
string pass = "password";
string db = "test";
string var1;

oAPP = new VBAPP.SessionClass();
oAPP.Method1(ref User, ref Pass, ref DataSource);
oApp2 = oAPP.get_SessionItem("APP2") as APP2.Class;
var1 = oApp2.Properties.Item(............
}

I'm trying to figure out how to get the same value for var1 as
oApp2.Properties.Item(.. wants a ref Object vIndex

When I add Object d = "Date"; and do oAppProperties.Item(ref d) it
returns System.___ComObject

What am I missing?

Thanks

Oct 5 '06 #8

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

Similar topics

19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
1
by: Sam Smith | last post by:
Hi, I wan't a function to take a const char*, a start bit position and number of bits and convert that bit-stream into a primitive of desired type. I.e. something like: char convert(const...
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...
4
by: Rodusa | last post by:
I am having problem to apply updates into this function below. I tried using cursor for updates, etc. but no success. Sql server keeps telling me that I cannot execute insert or update from inside...
4
by: Irepan | last post by:
does anybody know how to change the global IFormatProvider of my project so everycall to Convert.ToDouble on it uses this format provider instead of the one the one on the computer's regional...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
1
by: vipin | last post by:
My C# console application takes 5 parameters two of which are supposed to be inherently integers So I do COnvert.ToInt32(args) There is no problem with the console application when I run it...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
12
by: Wolfgang Kaml | last post by:
Dear all, I am using the following code to retrieve the size of a certain file and the available (free) space on the disk. The problem is, that I get the size of the file returned as a Long and...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.