Función Mid de String

(1/1)

Lain0x:
Hola estoy haciendo un programa que muestra la fecha, y después captura el día, mes y año y los imprime en textbox por separado al momento de presionar un botón.
El programa hace lo que quiero, pero muestra algunas excepciones abajo.

Código del botón:

Código:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     
        Dim c As String
        c = Date.Today
        T1.Text = c
        T2.Text = Mid(c, 1, Len(c) - 8)
        T3.Text = Mid(c, 4, Len(c) - 8)
        T4.Text = Mid(c, 7, Len(c) - 6)
       
    End Sub

Se ejecuta perfecto pero muestra esto abajo:

A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

raul338:
Ese codigo es de visual basic .net

Fijate bien que tengas bien en cuenta el tamaño del string, en lugar de usar Len, pon el numero exacto.

Aunque tiene mejores formas de hacer eso

$Edu$:
Fijate en que formato te da la fecha, si es del tipo "06/02/12" solo tienes que usar la funcion Split(), busca sobre ella.

Keyen Night:
Mid es una vieja función de vb6, en su lugar en .Net tienes String.SubString, si quieres trabajar con cadenas, pero si el fin es unicamente mostrar en un TextBox día, mes y año, están esas mismas propiedades en Today, Today.Month, Today.Year, Today.Day.

También se puede hacer con expresiones regulares pero ya eso es otro tema más extenso.

Lain0x:
Como puede haberme complicado pensando como capturar la fecha, si bastaba con ocupar un par de funciones como today.day. HAHA.

Navegación

[0] Índice de Mensajes