Solved

Convert vbscript to C sharp

Posted on 2013-06-03
8
312 Views
Last Modified: 2013-07-03
I have a vb dll called "dsextract.dll that is currently been called in a vb script file, I belief the dll was created in vb5.  I need help in converting the vbscript (see below) to a code I can run in a Csharp  asp.net environment.

Thanks for your assistance.
Note: Instead of writing the output to a csv file alone, I'll like to also be able to write it to  a dataset that can be inserted to a table.

--------- VBscript code
DataFields = "general.txtEmployerTaxID|general.txt3digitplannumber|plan.plantype"
OutputFileName = "extract.csv"
PlanID = "abcX"
fieldArray = Split(DataFields,"|")
Set ds = createobject("dsextract.clsdsextract")
Set fso = CreateObject("scripting.filesystemobject")
Set fsfile = fso.createtextfile(OutputFileName,true)
For n=lbound(FieldArray) to ubound(FieldArray)
	Output = Output & FieldArray(n) & ","
Next
fsfile.writeline("PlanIdent," & Output)
Output=""
ds.PlanIdent = PlanID
For n=lbound(FieldArray) to ubound(FieldArray)
Result = ds.getdata(FieldArray(n)& "")
If n=0 Then	'precede first field with plan ident
Output= Chr(34) & ds.planident & Chr(34) & ","
End if
Output = Output & chr(34) & Trim(Result & "") & chr(34) & ","
	Next
	fsfile.writeline(Output)
fsfile.close
Set ds=nothing
Set fsfile=nothing
Set fso=nothing

Open in new window

0
Comment
Question by:ITDeptAtPCS
  • 4
  • 2
8 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 39218548
first of all you need to convert Vb5 Dll into C# envrionment.

Do you have Dll Source Code ?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39218563
@kalpesh2804

Since the DLL already communicates through COM, why does it need to be converted?  .Net programs can consume and produced COM objects.
0
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 39218579
Author want to use this code in asp.net Environment

Usually vb5 Dll need to add in Registry (using regsvr32).

So it's required to Register this Dll in Server.

is it supported by their WebServer ?
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 45

Expert Comment

by:aikimark
ID: 39218588
Yes.  Where ever it runs, it needs to be registered.
0
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 39218607
most of Shared Hosting is not supporting COM Component Registration in Server Registry.

If Author has VPS then its possible to register Dll on Server.

that's why i asked about VB5 Dll Source Code.
0
 
LVL 1

Author Comment

by:ITDeptAtPCS
ID: 39218942
The dll has been registered. I do not have the source code, just the dll and the vbscript. Once the dll is registered, running the vbscript works ok in a .vbs file but having it run in an asp.net page will provide better flexibility and this is why am trying to convert the vbscript to .Net
0
 
LVL 16

Accepted Solution

by:
Kalpesh Chhatrala earned 500 total points
ID: 39219024
i tried to convert code in c#. may be you will get some Error.

string DataFields = "general.txtEmployerTaxID|general.txt3digitplannumber|plan.plantype";
string OutputFileName = "extract.csv";
string PlanID = "abcX";
string[] fieldArray = Strings.Split(DataFields, "|");
dynamic ds = Interaction.CreateObject("dsextract.clsdsextract");

dynamic fso = Interaction.CreateObject("scripting.filesystemobject");
dynamic fsfile = fso.createtextfile(OutputFileName, true);
for (n = Information.LBound(FieldArray); n <= Information.UBound(FieldArray); n++) {
	Output = Output + FieldArray(n) + ",";
}
fsfile.writeline("PlanIdent," + Output);
Output = "";
ds.PlanIdent = PlanID;
for (n = Information.LBound(FieldArray); n <= Information.UBound(FieldArray); n++) {
	Result = ds.getdata(FieldArray(n) + "");
	//precede first field with plan ident
	if (n == 0) {
		Output = Strings.Chr(34) + ds.planident + Strings.Chr(34) + ",";
	}
	Output = Output + Strings.Chr(34) + Strings.Trim(Result + "") + Strings.Chr(34) + ",";
}
fsfile.writeline(Output);
fsfile.close();
dynamic ds = null;
dynamic fsfile = null;
dynamic fso = null;

Open in new window

0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question