Solved

Convert vbscript to C sharp

Posted on 2013-06-03
8
308 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rhino JavaScript import, load 25 67
How to get the web content with different encodings 2 28
C# Offline Apllication 5 55
C# Json POSt to Rest API 4 37
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now