Solved

Convert vbscript to C sharp

Posted on 2013-06-03
8
318 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

730 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