UNA MANO PARA PODER ENCONTRAR EL ERROR / ERROR TO VBS SCRIPT FUNCTION - Forum

Forum Navigation
You need to log in to create posts and topics.

UNA MANO PARA PODER ENCONTRAR EL ERROR / ERROR TO VBS SCRIPT FUNCTION

@luishp,@gaev,@vadimMediante IA construi este pequeño script vbs que tiene como finalidad a partir de una varible [fecha]  que contiene una fecha en formato dd/mm/aa
la transforme en una nueva variable que de como resultante  el numero del dia, el nombre del mes y el numero del año

El resultado es este

 

' Función para convertir la fecha
Function ConvertirFecha(fecha)
' Dividir la fecha en partes
Dim partesFecha
partesFecha = Split(fecha, "/")

' Asignar los valores a variables
Dim dia, mes, año
dia = partesFecha(0)
mes = partesFecha(1)
año = partesFecha(2)

' Array con los nombres de los meses
Dim nombresMeses
nombresMeses = Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre")

' Obtener el nombre del mes
Dim nombreMes
nombreMes = nombresMeses(mes - 1)

' Construir la cadena con el formato deseado
Dim fechaFormateada
fechaFormateada = dia & " de " & nombreMes & " de " & año

' Devolver la fecha formateada
ConvertirFecha = fechaFormateada
End Function

' Ejemplo de uso de la función
' Suponiendo que la variable de NeoBook que contiene la fecha se llama "Fecha"
Dim fechaNeoBook
fechaNeoBook = NeoBook.GetVar("Fecha")

' Convertir la fecha y establecer la variable de NeoBook con el resultado
NeoBook.SetVar "FechaFormateada", ConvertirFecha(fechaNeoBook)

pero cuando la ejecuto me dice que contiene caracteres no validos.... alguien me puede dar una mano para que funcione

Gracias

 

ENGLISH

Using AI I built this small vbs script whose purpose is to transform a variable [date] that contains a date in dd/mm/yy format into a new variable that results in the number of the day, the name of the month and the number of the year

The result is this

' Función para convertir la fecha
Function ConvertirFecha(fecha)
' Dividir la fecha en partes
Dim partesFecha
partesFecha = Split(fecha, "/")

' Asignar los valores a variables
Dim dia, mes, año
dia = partesFecha(0)
mes = partesFecha(1)
año = partesFecha(2)

' Array con los nombres de los meses
Dim nombresMeses
nombresMeses = Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre")

' Obtener el nombre del mes
Dim nombreMes
nombreMes = nombresMeses(mes - 1)

' Construir la cadena con el formato deseado
Dim fechaFormateada
fechaFormateada = dia & " de " & nombreMes & " de " & año

' Devolver la fecha formateada
ConvertirFecha = fechaFormateada
End Function

' Ejemplo de uso de la función
' Suponiendo que la variable de NeoBook que contiene la fecha se llama "Fecha"
Dim fechaNeoBook
fechaNeoBook = NeoBook.GetVar("Fecha")

' Convertir la fecha y establecer la variable de NeoBook con el resultado
NeoBook.SetVar "FechaFormateada", ConvertirFecha(fechaNeoBook)

Thank you

but when I run it it tells me that it contains invalid characters... can someone give me a hand to make it work

Thank you

@joferar333

Using AI I built this small vbs script

Why use vbs when there are native VisualNEOWin commands that will do it for you ?

Try this script attached to the click event of a Button ...

... transform a variable [date] that contains a date in dd/mm/yy format
... https://winhelp.visualneo.com/Control.html#DATETONUM

DateToNum "[date]" "d/m/y" "[numDate]"

... into a new variable that results in the number of the day
... https://winhelp.visualneo.com/Control.html#NUMTODATE

... if you want to see them as 1 to 31
SetVar "[numDayFormat]" "d"

... if you want to see them as 01 to 31
... SetVar "[numDayFormat]" "dd"

NumToDate "[numDate]" "[numDayFormat]" "[numDay]"

.................................
... the name of the month

SetVar "[nameMonthFormat]" "mmmm"
NumToDate "[numDate]" "[nameMonthFormat]" "[nameMonth]"

.................................
... the number of the year

... if you want to see them as 00 to 99
... SetVar "[numYearFormat]" "yy"

... if you want to see them as 0000 to 9999
SetVar  "[numYearFormat]" "yyyy"

NumToDate "[numDate]" "[numYearFormat]" "[numYear]"

.................................
... optional

SetVar "[desiredAnswer]" "[numDay] [nameMonth] [numYear]"

AlertBox "desiredAnswer" "[desiredAnswer]"

 

 

luishp, alangonzalez91 and danito have reacted to this post.
luishpalangonzalez91danito