Visual Basic.NET - Convertir código de VBA a VB.NET

 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado su posición en 55 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Convertir código de VBA a VB.NET

Publicado por Orlando Villarreal (1 intervención) el 22/01/2020 18:27:52
Que tal por casualidad alguien podra traducirme un codigo de VBA estoy tratando de replicarlo en VB.net pero la verdad no entiendo mucho que es lo que hace la funcion

Esta es la funcion

Public Function CalcularProduccionMensual(strCelda As String) As Boolean
On Error GoTo ErrorCPM
Dim dbsArchivo As Database, rstProduccion As Recordset, rstTable1 As Recordset, rstDP As Recordset
Dim lngDp As Long, intDiasLab As Integer, intPlan As Long, strSql As String
Dim strNombreDeMes As String, strMesAnio As String, strAnio As String, strNumeroMes As String, datFechaInicial As Date, dblMonth1 As Double
Dim varMonth, varYear, intX As Integer, lngCantidad As Long

CalcularProduccionMensual = False

lngDp = 0: intPlan = 0: strSql = "": intDiasLab = 0
strNombreDeMes = "": strMesAnio = "": strAnio = "": strNumeroMes = "": intX = 0: lngCantidad = 0

strSql = "SELECT * FROM [Produccion2 Query] WHERE [Celda] = '" & strCelda & "';"
Set dbsArchivo = CurrentDb
Set rstProduccion = dbsArchivo.OpenRecordset(strSql, dbOpenSnapshot)
If rstProduccion.EOF = True Then
MostrarMensaje "No se encontr� producci�n de la celda especificada."
GoTo SalidaCPM
End If

Set rstDP = dbsArchivo.OpenRecordset("SELECT * FROM [DemandaPlaneada Query] WHERE [Celda] = '" & strCelda & "';", dbOpenSnapshot)
If rstDP.EOF = True Then
MensajeCr "No se han establecido las demandas planeadas por mes de la celda " & strCelda & "."
GoTo SalidaCPM
End If

Set rstTable1 = dbsArchivo.OpenRecordset("GraficaMetaProduccionMensual", dbOpenDynaset)

Do While rstTable1.EOF = False
rstTable1.Delete
rstTable1.MoveNext
Loop

varYear = Year(Date) - 1
varMonth = Month(Date)

With rstProduccion
For intX = 1 To 13
strAnio = Trim(Str(varYear))
strNumeroMes = varMonth
dblMonth1 = Val(strNumeroMes)
datFechaInicial = DateValue(strNumeroMes & "/1/" & strAnio)

strSql = "[yeardl] = " & strAnio & " AND [monthdl] = " & strNumeroMes
rstDP.FindFirst strSql
If rstDP.NoMatch = True Then
lngDp = 0
Else
lngDp = Nz(rstDP!DemandaPlaneada, 0)
End If

intDiasLab = DiasLaborales(datFechaInicial, dblMonth1)

strSql = "[anio] = " & strAnio & " AND [mes] = " & strNumeroMes
.FindFirst strSql
If .EOF = True Then
lngCantidad = 0
Else
lngCantidad = Nz(!Cantidad, 0)
End If

rstTable1.AddNew
rstTable1!Celda = strCelda
rstTable1!mesanio = datFechaInicial
rstTable1!Plan = lngDp * intDiasLab
rstTable1!real = Nz(!Cantidad, 0)
rstTable1!DemandaPlaneada = lngDp
rstTable1!DiasLaborales = intDiasLab
rstTable1.Update

varMonth = varMonth + 1
If varMonth = 13 Then
varMonth = 1
varYear = varYear + 1
End If
Next intX
End With

CalcularProduccionMensual = True

SalidaCPM:
On Error Resume Next
rstTable1.Close
rstProduccion.Close
rstDP.Close
dbsArchivo.Close
Exit Function

ErrorCPM:
MensajeCr Err.Number & ".- " & Err.DESCRIPTION
Resume SalidaCPM

End Function
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder