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

    Completamento automatico vettore di caselle di testo

    Tempo fa su questo forum mi hanno postato la seguente classe per il completamento automatico di una casella di testo:

    codice:
    Option Explicit
    Private WithEvents m_txtComplete As TextBox
    Private m_strDelimeter As String
    Private m_strList As String
    Private Sub m_txtComplete_KeyUp(KeyCode As Integer, Shift As Integer)
    
    Dim i As Integer
    Dim strSearchText As String
    Dim intDelimented As Integer
    Dim intLength As Integer
    Dim varArray As Variant
    With m_txtComplete
    If KeyCode <> vbKeyBack And KeyCode > 48 Then
    If InStr(1, m_strList, .Text, vbTextCompare) <> 0 Then
    varArray = Split(m_strList, m_strDelimeter)
    For i = 0 To UBound(varArray)
    strSearchText = Trim(varArray(i))
    If InStr(1, strSearchText, .Text, vbTextCompare) And
    (Left$(.Text, 1) = Left$(strSearchText, 1)) And
    .Text <> "" Then
    .SelText = ""
    .SelLength = 0
    intLength = Len(.Text)
    .Text = .Text & Right$(strSearchText, Len(strSearchText) - Len(.Text))
    .SelStart = intLength
    .SelLength = Len(.Text)
    Exit Sub
    End If
    Next i
    End If
    End If
    End With
    End Sub
    
    Public Property Get CompleteTextbox() As TextBox
    Set CompleteTextbox = m_txtComplete
    End Property
    
    Public Property Set CompleteTextbox(ByRef txt As TextBox)
    Set m_txtComplete = txt
    End Property
    
    Public Property Get SearchList() As String
    SearchList = m_strList
    End Property
    
    Public Property Let SearchList(ByVal str As String)
    m_strList = str
    End Property
    
    Public Property Get Delimeter() As String
    Delimeter = m_strDelimeter
    End Property
    
    Public Property Let Delimeter(ByVal str As String)
    m_strDelimeter = str
    End Property
    e per utilizzarla ho scritto nel form principale il seguente codice:

    codice:
    Option Explicit
    
    Private m_objAutoCompleteUser As clsAutoComplete
    
    Private Sub Form_Unload(Cancel As Integer)
    Set m_objAutoCompleteUser = Nothing
    End Sub
    
    Private Sub Form_Load()
    Set m_objAutoCompleteUser = New clsAutoComplete
    With m_objAutoCompleteUser
    .SearchList = "prova,ciao"
    Set .CompleteTextbox = txtUser
    .Delimeter = ","
    End With
    End Sub
    se adesso anziché ad una sola casella di testo txtUser volessi applicare la classe a un vettore di caselle di testo txtUser(), quale parte del codice dovrei modificare?

    Scusate l'ingnoranza ma sono un principiante e non ho grande dimestichezza con le classi e gli oggetti

  2. #2
    nessuno? io volevo solo sapere perché se anziché scrivere nel form principale

    codice:
    Set .CompleteTextbox = txtUser
    dichiaro un vettore di controlli txtUser() e poi passo un dato elemento, così:

    codice:
    Set .CompleteTextbox = txtUser(1)
    ho un errore. tutto qua.

  3. #3
    oggi hai aperto la terza discussione sull'argomento http://forum.html.it/forum/showthrea...hreadid=542390; in ogni caso chiudo questa xchè le motivazioni che hai addotto nell'altra mi sembrano più interessanti

    05.08.2005 - by alka
    Auguri all'angelo custode dei moderatori.

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.