Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/08/2008, 12:57
fenix111
 
Fecha de Ingreso: agosto-2008
Mensajes: 1
Antigüedad: 15 años, 9 meses
Puntos: 0
como puedo optimizar este codigo

CLSOPERACIONES-------------------------------------------------------------

Dim cn As New ADODB.Connection
Dim rstipo As New ADODB.Recordset
Dim rspago As New ADODB.Recordset
Dim rstotal As New ADODB.Recordset
Dim daniel As String

Private Sub Class_Initialize()

cn.CursorLocation = adUseClient
cn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="
cn.Open ("D:\VISUALBASIC\SQLBASIC\data\bd1.mdb")


End Sub

Public Function PAGORC(daniel2 As String) As Double

Dim daniel3 As String
Dim nombre As String
Dim daniel As String
nombre = daniel2
daniel = "select count(pago)as total from clientes WHERE nombre =" + "'" + nombre + "'" + "and " + "pago='credito'"
Set rstipo = cn.Execute(daniel)
daniel3 = "select count(tipo)as totaltipo from clientes WHERE nombre =" + "'" + nombre + "'" + "and " + " tipo ='regular'"
Set rspago = cn.Execute(daniel3)

p = MsgBox(rstipo.Fields("total").Value, vbOKCancel, "CREDITOS Q TIENE")
o = MsgBox(rspago.Fields("totaltipo").Value, vbOKCancel, "LOS TIPOS DE PAGO REGULAR")

PAGORC = rspago.Fields("totaltipo").Value / rstipo.Fields("total").Value

End Function
Public Function PAGOCV(DENTRA As String) As Double
Dim daniel3 As String
Dim nombre As String
Dim daniel As String

nombre = DENTRA
daniel = "select count(pago)as total from clientes WHERE nombre =" + "'" + nombre + "'" + "and " + "pago='credito'"
Set rstipo = cn.Execute(daniel)
daniel3 = "select count(tipo)as totaltipo from clientes WHERE nombre =" + "'" + nombre + "'" + "and " + " tipo ='regular'"
Set rspago = cn.Execute(daniel3)

p = MsgBox(rstipo.Fields("total").Value, vbOKCancel, "SOLO CREDITOS Q TIENE")
o = MsgBox(rspago.Fields("totaltipo").Value, vbOKCancel, "SOLO REGULARES")

PAGOCV = rstipo.Fields("total").Value / rspago.Fields("totaltipo").Value

End Function

Public Function PAGOCVC(DENTRA As String) As Double

Dim daniel3 As String
Dim nombre As String
Dim daniel As String
Dim daniel4 As String
Dim total As Integer
Dim rest As Integer

nombre = DENTRA

daniel4 = "select count(nombre) as totaln from clientes WHERE nombre =" + "'" + nombre + "'"
Set rstotal = cn.Execute(daniel4)

daniel = "select count(pago)as total from clientes WHERE nombre =" + "'" + nombre + "'" + "and " + "tipo='regular'"
Set rstipo = cn.Execute(daniel)

daniel3 = "select count(tipo)as totaltipo from clientes WHERE nombre=" + "'" + nombre + "'" + "and " + "pago='credito'" + "and tipo not like 'regular'"
Set rspago = cn.Execute(daniel3)

If rspago.Fields("totaltipo").Value >= rstipo.Fields("total").Value Then
rest = rspago.Fields("totaltipo").Value + rstipo.Fields("total").Value
End If

p = MsgBox(rstipo.Fields("total").Value, vbOKCancel, "SOLO SI ES REGULAR ")
o = MsgBox(rspago.Fields("totaltipo").Value, vbOKCancel, "SOLO SI ES CREDITO")

PAGOCVC = rest / rstotal.Fields("totaln").Value

End Function




CMDCALCULAR---------------------------------------------------------------------------------------------------------------

Dim vneg As New pryoperaciones.clsoperaciones

Private Sub cmd1_Click()
Dim cadena As String
cadena = nombre.Text
If Combo1.Text = "A" Then
txtresultado.Text = vneg.PAGORC(cadena)
Else
If Combo1.Text = "B" Then

txtresultado.Text = Round(vneg.PAGOCV(cadena), 4)
Else
txtresultado.Text = Round(vneg.PAGOCVC(cadena), 4)
End If
End If

End Sub