Forums
This topic is locked
Wrtiting visual basic results to database
Posted 03 Apr 2006 18:38:40
1
has voted
03 Apr 2006 18:38:40 Ricky Cortes posted:
Hi how can I write the results from this visual basic script eather strigth to a table in my database or as a string to another page that can request te string and write to a database need help here thanks in advance
Dim P 'Payment
Dim I 'Interest
Dim L 'Loan Term In Years
Dim J
Dim N
Dim M
Dim H
Dim C
Dim Q
Dim X
Dim k
'Set the Conter for the Ammoritization
X=0
'Replace these with your variables
'Total of Loan Amount
P= 2000
'Interest Rate
I=25
'Loan term in months
L=10
'Calculate Monthly Interest
J=I/(12 * 100)
'Length of loan in Months
N=L
'Now the magic.....
M = P * ( J / (1 - (1 + J) ^ -N))
Response.Write "<B>Monthly Payment: " & Round(M, 2) & "</B><BR>"
Response.Write "<TABLE cellSpacing=1 cellPadding=1 width=""55%"" bgColor=silver border=0>"
Response.Write "<TD bgColor=#708090>Contrato ID</TD>"
Response.Write "<TD bgColor=#708090>Fecha de Pago</TD>"
Response.Write "<TD bgColor=#708090>Interes</TD>"
Response.Write "<TD bgColor=#708090>Principal </TD>"
Response.Write "<TD bgColor=#708090>Balance</TD>"
Response.Write "<TD bgColor=#708090>Pago</TD></TR>"
Response.Write "<TR>"
'Loop through And Get the Monthly Paymen
' ts for the length of the loan
Do While X < N
Response.Write "<TD bgColor=silver>" & (z.Fields.Item("contrato_id".Value) & "</TD>"
Response.Write "<TD bgColor=silver>" & dateadd("m",X,(z.Fields.Item("con_fecha".Value)) & "</TD>"
H=P*J
Response.Write "<TD bgColor=silver>" & Round(H, 2) & "</TD>"
C=M-H
Response.Write "<TD bgColor=silver>" & Round(C, 2) & "</TD>"
Q=P-C
Response.Write "<TD bgColor=silver>" & Round(Q, 2) & "</TD>"
P=Q
Response.Write "<TD bgColor=silver>" & Round(C+H,2) & "</TD></TR>"
X=X+1
Loop
Replies
Replied 03 Apr 2006 19:24:13
03 Apr 2006 19:24:13 micah santos replied:
<%
// Direct saving to the database
// Open recordset
objRs.Open "SELECT * TABLE",conn,1
objRs.Addnew
// C=M-H
objRs("field1" = C
// Q=P-C
objRs("field2" = Q
objRs.Update
objRs.Close
%>
// Direct saving to the database
// Open recordset
objRs.Open "SELECT * TABLE",conn,1
objRs.Addnew
// C=M-H
objRs("field1" = C
// Q=P-C
objRs("field2" = Q
objRs.Update
objRs.Close
%>
Replied 04 Apr 2006 04:28:20
04 Apr 2006 04:28:20 Ricky Cortes replied:
Well Im not updating Im inserting I try this way but it wont work can you ilustrate me how to do an insert
Replied 04 Apr 2006 14:28:58
04 Apr 2006 14:28:58 micah santos replied:
INSERT INTO tableName(Field1, Field2, Field3) VALUES(C, Q, P)
Note: if field1 or any other fields are set to character, you should put ' ' in between like this:
strText = "character"
INSERT INTO tableName(Field1, Field2, Field3) VALUES ('strText',Q,P)
Replied 05 Apr 2006 18:10:28
05 Apr 2006 18:10:28 Ricky Cortes replied:
I still dont guet it
set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_selectasystem_STRING
Command1.CommandText = "INSERT INTO con_pagare (pa_contrato_id,pa_interes) VALUES (2970," + Replace(Command1__objRs, "'", "''" + " "
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
Dim P 'Payment
Dim I 'Interest
Dim L 'Loan Term In Years
Dim J
Dim N
Dim M
Dim H
Dim C
Dim Q
Dim X
Dim k
'Set the Conter for the Ammoritization
X=0
'Replace these with your variables
'Total of Loan Amount
P= CStr(Recordset1.Fields.Item("con_financiado".Value)
'Interest Rate
I=CStr(Recordset1.Fields.Item("con_apr".Value)
'Loan term in years
L=(Recordset1.Fields.Item("con_termino".Value)
'Calculate Monthly Interest
J=I/(12 * 100)
'Length of loan in Months
N=L
'Now the magic.....
M = P * ( J / (1 - (1 + J) ^ -N))
Response.Write "<B>Monthly Payment: " & Round(M, 2) & "</B><BR>"
Response.Write "<TABLE cellSpacing=1 cellPadding=1 width=""55%"" bgColor=silver border=0>"
Response.Write "<TD bgColor=#708090>Contrato ID</TD>"
Response.Write "<TD bgColor=#708090>Fecha de Pago</TD>"
Response.Write "<TD bgColor=#708090>Interes</TD>"
Response.Write "<TD bgColor=#708090>Principal </TD>"
Response.Write "<TD bgColor=#708090>Balance</TD>"
Response.Write "<TD bgColor=#708090>Pago</TD></TR>"
Response.Write "<TR>"
'Loop through And Get the Monthly Paymen
' ts for the length of the loan
Do While X < N
Response.Write "<TD bgColor=silver>" & (z.Fields.Item("contrato_id".Value) & "</TD>"
Response.Write "<TD bgColor=silver>" & dateadd("m",X,(z.Fields.Item("con_fecha".Value)) & "</TD>"
H=P*J
Response.Write "<TD bgColor=silver>" & Round(H, 2) & "</TD>"
C=M-H
Response.Write "<TD bgColor=silver>" & Round(C, 2) & "</TD>"
Q=P-C
Response.Write "<TD bgColor=silver>" & Round(Q, 2) & "</TD>"
P=Q
Response.Write "<TD bgColor=silver>" & Round(C+H,2) & "</TD></TR>"
X=X+1
Loop
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
INSERT INTO tableName(Field1, Field2, Field3) VALUES(C, Q, P)
Note: if field1 or any other fields are set to character, you should put ' ' in between like this:
strText = "character"
INSERT INTO tableName(Field1, Field2, Field3) VALUES ('strText',Q,P)
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_selectasystem_STRING
Command1.CommandText = "INSERT INTO con_pagare (pa_contrato_id,pa_interes) VALUES (2970," + Replace(Command1__objRs, "'", "''" + " "
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
Dim P 'Payment
Dim I 'Interest
Dim L 'Loan Term In Years
Dim J
Dim N
Dim M
Dim H
Dim C
Dim Q
Dim X
Dim k
'Set the Conter for the Ammoritization
X=0
'Replace these with your variables
'Total of Loan Amount
P= CStr(Recordset1.Fields.Item("con_financiado".Value)
'Interest Rate
I=CStr(Recordset1.Fields.Item("con_apr".Value)
'Loan term in years
L=(Recordset1.Fields.Item("con_termino".Value)
'Calculate Monthly Interest
J=I/(12 * 100)
'Length of loan in Months
N=L
'Now the magic.....
M = P * ( J / (1 - (1 + J) ^ -N))
Response.Write "<B>Monthly Payment: " & Round(M, 2) & "</B><BR>"
Response.Write "<TABLE cellSpacing=1 cellPadding=1 width=""55%"" bgColor=silver border=0>"
Response.Write "<TD bgColor=#708090>Contrato ID</TD>"
Response.Write "<TD bgColor=#708090>Fecha de Pago</TD>"
Response.Write "<TD bgColor=#708090>Interes</TD>"
Response.Write "<TD bgColor=#708090>Principal </TD>"
Response.Write "<TD bgColor=#708090>Balance</TD>"
Response.Write "<TD bgColor=#708090>Pago</TD></TR>"
Response.Write "<TR>"
'Loop through And Get the Monthly Paymen
' ts for the length of the loan
Do While X < N
Response.Write "<TD bgColor=silver>" & (z.Fields.Item("contrato_id".Value) & "</TD>"
Response.Write "<TD bgColor=silver>" & dateadd("m",X,(z.Fields.Item("con_fecha".Value)) & "</TD>"
H=P*J
Response.Write "<TD bgColor=silver>" & Round(H, 2) & "</TD>"
C=M-H
Response.Write "<TD bgColor=silver>" & Round(C, 2) & "</TD>"
Q=P-C
Response.Write "<TD bgColor=silver>" & Round(Q, 2) & "</TD>"
P=Q
Response.Write "<TD bgColor=silver>" & Round(C+H,2) & "</TD></TR>"
X=X+1
Loop
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
INSERT INTO tableName(Field1, Field2, Field3) VALUES(C, Q, P)
Note: if field1 or any other fields are set to character, you should put ' ' in between like this:
strText = "character"
INSERT INTO tableName(Field1, Field2, Field3) VALUES ('strText',Q,P)
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 05 Apr 2006 21:24:32
05 Apr 2006 21:24:32 micah santos replied:
what particular error are you getting from this scripts?
Replied 06 Apr 2006 16:17:21
06 Apr 2006 16:17:21 Ricky Cortes replied:
right now Im not getting any but the script is not working eather here is the entire code
@LANGUAGE="VBSCRIPT" CODEPAGE="1252"
--#include file="Connections/selectasystem.asp" -
Sub sAddpagare(pid, pinterest)
set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_selectasystem_STRING
Command1.CommandText = "INSERT INTO con_pagare (pa_contrato_id,pa_interes) VALUES (" & pid & ", " & pinterest & " "
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
End Sub
Dim P 'Payment
Dim I 'Interest
Dim L 'Loan Term In Years
Dim J
Dim N
Dim M
Dim H
Dim C
Dim Q
Dim X
Dim k
'Set the Conter for the Ammoritization
X=0
'Replace these with your variables
'Total of Loan Amount
P= 2000
'Interest Rate
I=25
'Loan term in years
L=10
'Calculate Monthly Interest
J=I/(12 * 100)
'Length of loan in Months
N=L
'Now the magic.....
M = P * ( J / (1 - (1 + J) ^ -N))
Response.Write "<B>Monthly Payment: " & Round(M, 2) & "</B><BR>"
Response.Write "<TABLE cellSpacing=1 cellPadding=1 width=""55%"" bgColor=silver border=0>"
Response.Write "<TD bgColor=#708090>Contrato ID</TD>"
Response.Write "<TD bgColor=#708090>Fecha de Pago</TD>"
Response.Write "<TD bgColor=#708090>Interes</TD>"
Response.Write "<TD bgColor=#708090>Principal </TD>"
Response.Write "<TD bgColor=#708090>Balance</TD>"
Response.Write "<TD bgColor=#708090>Pago</TD></TR>"
Response.Write "<TR>"
'Loop through And Get the Monthly Paymen
' ts for the length of the loan
Do While X < N
Response.Write "<TD bgColor=silver>" & 2770 & "</TD>"
Response.Write "<TD bgColor=silver>" & dateadd("m",X,3/1/2006) & "</TD>"
H=P*J
Response.Write "<TD bgColor=silver>" & Round(H, 2) & "</TD>"
C=M-H
Response.Write "<TD bgColor=silver>" & Round(C, 2) & "</TD>"
Q=P-C
Response.Write "<TD bgColor=silver>" & Round(Q, 2) & "</TD>"
P=Q
Response.Write "<TD bgColor=silver>" & Round(C+H,2) & "</TD></TR>"
X=X+1
Loop
@LANGUAGE="VBSCRIPT" CODEPAGE="1252"
--#include file="Connections/selectasystem.asp" -
Sub sAddpagare(pid, pinterest)
set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_selectasystem_STRING
Command1.CommandText = "INSERT INTO con_pagare (pa_contrato_id,pa_interes) VALUES (" & pid & ", " & pinterest & " "
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
End Sub
Dim P 'Payment
Dim I 'Interest
Dim L 'Loan Term In Years
Dim J
Dim N
Dim M
Dim H
Dim C
Dim Q
Dim X
Dim k
'Set the Conter for the Ammoritization
X=0
'Replace these with your variables
'Total of Loan Amount
P= 2000
'Interest Rate
I=25
'Loan term in years
L=10
'Calculate Monthly Interest
J=I/(12 * 100)
'Length of loan in Months
N=L
'Now the magic.....
M = P * ( J / (1 - (1 + J) ^ -N))
Response.Write "<B>Monthly Payment: " & Round(M, 2) & "</B><BR>"
Response.Write "<TABLE cellSpacing=1 cellPadding=1 width=""55%"" bgColor=silver border=0>"
Response.Write "<TD bgColor=#708090>Contrato ID</TD>"
Response.Write "<TD bgColor=#708090>Fecha de Pago</TD>"
Response.Write "<TD bgColor=#708090>Interes</TD>"
Response.Write "<TD bgColor=#708090>Principal </TD>"
Response.Write "<TD bgColor=#708090>Balance</TD>"
Response.Write "<TD bgColor=#708090>Pago</TD></TR>"
Response.Write "<TR>"
'Loop through And Get the Monthly Paymen
' ts for the length of the loan
Do While X < N
Response.Write "<TD bgColor=silver>" & 2770 & "</TD>"
Response.Write "<TD bgColor=silver>" & dateadd("m",X,3/1/2006) & "</TD>"
H=P*J
Response.Write "<TD bgColor=silver>" & Round(H, 2) & "</TD>"
C=M-H
Response.Write "<TD bgColor=silver>" & Round(C, 2) & "</TD>"
Q=P-C
Response.Write "<TD bgColor=silver>" & Round(Q, 2) & "</TD>"
P=Q
Response.Write "<TD bgColor=silver>" & Round(C+H,2) & "</TD></TR>"
X=X+1
Loop