?
Solved

Convert vbscript to C sharp

Posted on 2013-06-03
8
Medium Priority
?
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 46

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
Industry Leaders: 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 46

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 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

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