Solved

Convert vbscript to C sharp

Posted on 2013-06-03
8
304 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
Comment Utility
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
Comment Utility
@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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 45

Expert Comment

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

Expert Comment

by:Kalpesh Chhatrala
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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 …
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…
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 …
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

7 Experts available now in Live!

Get 1:1 Help Now