Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [VB 2008] Formattare textbox per l'input di date

    Ciao a tutti,

    ho un problema nella formattazione di una textbox. Io vorrei che mi aggiungesse automaticamente le barre quando inserisco una data. Vi faccio un esempio: se io voglio inserire ad esempio 01/01/2000 le barre le devo mettere io manualmente, mentre vorrei che fosse una cosa automatica.
    Girovagando su google ho trovato questo codice:

    codice:
    Public Function TextBoxDateFormat(ByVal DAscii As Integer, ByVal txtData As TextBox)
            'Set error trapping on
            On Error GoTo ErrorHandler
    
            'Inserts '/' into date
            TextBoxDateFormat = DAscii
    
            'Check code
            If IsNumeric(Chr(DAscii)) Then
    
                'Format
                If ((Len(txtData .Text) = 2) Or (Len(txtData .Text) = 5)) And (IsNumeric(Chr(DAscii))) Then
    
                    'Add a /
                    DTBox.Text = DTBox.Text + "/"
                    txtData.SelectionStart = Len(dtbox.Text)
    
                ElseIf Len(DTBox.Text) = 7 Then
    
                    'Format
                    dtbox.Text = Format(txtData + Chr(DAscii), "dd/mm/yyyy")
                    TextBoxDateFormat = 0
                    txtData.SelectionStart = 10
                End If
    
            ElseIf DAscii <> 8 Then
    
                'Do not allow the keystroke
                TextBoxDateFormat = 0
            End If
    
            'Exit
            Exit Function
    
    ErrorHandler:
    
            'Process error
            'WriteToErrorLog "ModHelperRoutines", "TextBoxDateFormat", Err.Number, Err.Description
            Resume Next
    
        End Function
    però mi da errore su questa istruzione:

    codice:
    txtData + Chr(DAscii)
    dicendomi che l'operatore + non è definito per i tipi 'system.windows.forms.textbox' e 'char'

    Qual'è quindi l'errore che mi trovo a dover fronteggiare?
    Errare è umano, ma per fare veramente casino ci vuole la password di root

  2. #2
    Utente di HTML.it L'avatar di alpynet
    Registrato dal
    Mar 2010
    Messaggi
    123
    Ciao, prova con: txtData & Chr(DAscii)

  3. #3

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.