• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 691
  • Last Modified:

Creating VB 6 DLL and Calling within ASP Page

I want to create a function in VB6 where I need to pass an array to and a percent value and then return a calculation through VB.   I then need to call this function in an ASP page and pass the array of values where there will be 4 and a percent value then I want to return the value in like RetValue variable.  I am rusty at using VB6 dll's within ASP.  Can someone provide me with an example on how to accomplish this?  Here is what I want to create in VB6 DLL function and then call this in an ASP page returing the value where I will response.write it out.  Here is the function its for a financial function where I want to use a VB6 DLL to handle all these larger calculations and keep it out of my ASP code except for the call to complete the calc.

 Dim Guess, RetRate, Values(4) As Double
   Dim Fmt, Msg As String
   Guess = 0.1  ' Guess starts at 10 percent.
   Fmt = "#0.00"   ' Define percentage format.
   Values(0) = -2465399   ' Business start-up costs.
   ' Positive cash flows reflecting income for four successive years.
   Values(1) = 1725956: Values(2) = 1686970
   Values(3) = 1599299
   RetRate = IRR(Values, Guess) * 100   ' Calculate internal rate.
   Msg = "The internal rate of return for these four cash flows is "
   Msg = Msg & Format(RetRate, CStr(Fmt)) & " percent."
   MsgBox (Msg)   ' Display internal return rate.

I need to complete the above and the Values pass as an array to it and then return the RetRate.  I want to play with this over the weekend to see if I can start a new financial calc DLL to use.  Thanks all.
0
sbornstein2
Asked:
sbornstein2
  • 9
  • 8
1 Solution
 
fritz_the_blankCommented:
This will walk you through it step by step.

Keep in mind that you will want to replace Msgbox with response.write


http://www.macronimous.com/resources/tutorials/asp_vb_dll.asp


FtB
0
 
sbornstein2Author Commented:
I am going to try that Fritz.  Can you help me setting up the function for that above code.  I want to return the value as a percent and the IRR is a built in function for VB where it passing inn the values and the guess.  I am going to want from my ASP app to make the call and pass it in an array of 4 values like above and a guess percent like 0.10.  Thanks again I am looking forward to trying this out.
0
 
fritz_the_blankCommented:
What you will need to do is to return an array with your values.

Can you tell me specifically what you need help with? Please re-read the article and then let me know.

FtB
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!

 
sbornstein2Author Commented:
Just the creation of the function I will need in VB6 to return the percent back.  I think I have the rest.
0
 
sbornstein2Author Commented:
I beleive in the ASP page I will pass an array like so for testing:

Dim arrIRR(3)
arrIRR(0) = CDBL(-2465399)
arrIRR(1) = CDBL(1725956)
arrIRR(2) = CDBL(1686970)
arrIRR(3) = CDBL(1599299)
0
 
fritz_the_blankCommented:

so when you are done, you would do


return arrIRR

FtB
0
 
sbornstein2Author Commented:
I have the following but the IRR function is not working and the first piece is saying "Type Mismatch:  Array or user defined type expected"  Here is what I have and I am just doing a compile in VB and it gets the error:

Public Function IRRCalc(ByRef Values As Variant, ByRef dblguess As Double) As Double
IRRCalc = IRR(Values, Guess) * 100
End Function


0
 
fritz_the_blankCommented:
Okay, here is the syntax and explanation from: http://www.int.gu.edu.au/courses/3008int/m03/FYI/Command_Syntax.htm#Heading97

IRR Function
IRR(values()[, guess])

Returns a Double value indicating the internal rate of return for an array of values that represent cash flow. The values() array must contain at least one negative value (payment) and one positive value (receipt). The optional guess argument specifies an estimate value to be returned by IRR (default estimate is .1).

so, it looks like you are close, but you you need to add one more line:

Public Function IRRCalc(ByRef Values As Variant, ByRef dblguess As Double) As Double
    IRRCalc = IRR(Values, Guess) * 100
    return IRRCalc
End Function

FtB

0
 
sbornstein2Author Commented:
No dice.  The line return is turning red.  I also tried diming an array in VB6 and it did not like it as well.
0
 
fritz_the_blankCommented:
>>The line return is turning red. <<

?!?!?

FtB
0
 
sbornstein2Author Commented:
Pasted this in a new class I created:
Public Function IRRCalc(ByRef Values As Variant, ByRef dblguess As Double) As Double
    IRRCalc = IRR(Values, Guess) * 100
    return IRRCalc
End Function

return IRRCalc says syntax error.  Do I need to reference anything in the project?  Also it did not like when I the array declaration when I tried that.
0
 
sbornstein2Author Commented:
I keep getting type mismath  Type mismatch: 'IRRCalc'.  Here is what I have:

VB DLL:
Public Function IRRCalc(ByRef Values() As Double, ByRef Guess As Double) As String
IRRCalc = Format(IRR(Values(), Guess) * 100, "#0.00") & "%"
End Function

ASP Page:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<%
Dim objCalcVal, RetVal
Dim arrIRR(3),valGuess
arrIRR(0) = CDBL(-2465399)
arrIRR(1) = CDBL(1725956)
arrIRR(2) = CDBL(1686970)
arrIRR(3) = CDBL(1599299)
valGuess = CDBL(0.1)
Set objCalcVal = Server.CreateObject("FinancialCalcs.clsFinancialCalcs")
RetVal = objCalcVal.IRRCalc(arrIRR,valGuess)
Response.Write RetVl
%>

</BODY>
</HTML>
0
 
sbornstein2Author Commented:
The DLL is working now however.
0
 
fritz_the_blankCommented:
Instead of passing an array, why not try passing the values like this:

objCalcVal.IRRCalc((-2465399,1725956,1686970,1599299,0.1)

and then in your .dll work with those parameters?

FtB
0
 
fritz_the_blankCommented:
In any event, work with your function in VB to get it working before you roll it into a .dll.

FtB
0
 
sbornstein2Author Commented:
How will the function change then?  Will I need to have 5 variables coming in then?
0
 
fritz_the_blankCommented:
Right. You would pass five simple parameters to the .dll and then you wouldn't have to fuss with creating/passing arrays.

ftB
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.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now