Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

como puedo optimizar este codigo

Estas en el tema de como puedo optimizar este codigo en el foro de Visual Basic clásico en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 20/08/2008, 12:57
 
Fecha de Ingreso: agosto-2008
Mensajes: 1
Antigüedad: 15 años, 8 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
  #2 (permalink)  
Antiguo 22/08/2008, 13:07
Avatar de GeoAvila
Colaborador
 
Fecha de Ingreso: diciembre-2003
Ubicación: Antigua Guatemala
Mensajes: 4.032
Antigüedad: 20 años, 4 meses
Puntos: 53
Respuesta: como puedo optimizar este codigo

Se me vienen un par de ideas a la mente, por ejemplo las variables

Daniel y Daniel 3 les seteas el mismo valor dos veces... o más veces.. para eso mejor crea las variables generales para el form

he aqui un ejemplito de lo que digo

Código:
Private Variable As Integer
Private Sub Command1_Click()
Variable = 150
MostrarDato
End Sub
Private Sub MostrarDato()
MsgBox Variable
End Sub
probá eso en un form en blanco con un botón agregado, y aplicalo para todas las varialbes que declarás más de una vez con el mismo valor..

nos vemos..
__________________
* Antes de preguntar lee las FAQ, y por favor no hagas preguntas en las FAQ
Sitio http://www.geoavila.com twitter: @GeoAvila
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:02.