Van | : | Ronald Beuker | Datum | : | 19-09-2007 |
Aan | : | Allen | MsgID | : | 3563.1 |
Onderwerp | : | Tekst plakken in >1 textbox met VB6? | Forum | : | ws-nlcomputer |
Public Function MaakSerienummer() As String
Dim GetSerienummer As String
GetSerienummer = txtSN1.Text & "-" & txtSN2.Text & "-" & txtSN3.Text & "-" & txtSN4.Text & "-" & txtSN5.Text
MaakSerienummer = GetSerienummer
End Function
Alle textboxes hebben een MaxLength. Als een textbox helemaal gevuld is, gaat de focus naar de volgende txtbox:Private Sub txtSN1_Change()
Dim AantaltekensInTekstbox As Long
Dim MaxAantaltekensInTekstbox As Long
MaxAantaltekensInTekstbox = txtSN1.MaxLength
AantaltekensInTekstbox = Len(txtSN1.Text)
If AantaltekensInTekstbox >= MaxAantaltekensInTekstbox Then
txtSN2.SetFocus
End If
End Sub
Tot zover gaat alles ok. Maar nu zou ik er nog 1 ding aan willen toevoegen. Zo'n serienummer is natuurlijk wel heel erg lang, en daarom zou het ook makkelijk zijn als de gebruiker het serienummer kan kopiëren/plakken in de 1e textbox waarbij dan de andere 4 serienummer ook automagisch gevuld worden. Volgens mij moet er dan zoiets gebeuren:Van | : | Ronald Beuker | Datum | : | 19-09-2007 |
Aan | : | Allen | MsgID | : | 3563.2 |
Onderwerp | : | Tekst plakken in >1 textbox met VB6? | Forum | : | ws-nlcomputer |
Private Sub txtSN1_Change()
Dim AantaltekensInTekstbox As Long
Dim MaxAantaltekensInTekstbox As Long
Dim ClipText As String
MaxAantaltekensInTekstbox = txtSN1.MaxLength
AantaltekensInTekstbox = Len(txtSN1.Text)
ClipText = Clipboard.GetText
If AantaltekensInTekstbox >= MaxAantaltekensInTekstbox Then
If Left(ClipText, 2) = txtSN1.Text And Len(ClipText) = 30 Then 'er is zeer waarschijnlijk gekopieerd/geplakt!
txtSN2.Text = Mid(ClipText, 4, 6)
txtSN3.Text = Mid(ClipText, 11, 8)
txtSN4.Text = Mid(ClipText, 20, 6)
txtSN5.Text = Mid(ClipText, 27, 4)
cmdOK.SetFocus
Else
txtSN2.SetFocus
End If
End If
End Sub
Ik ben nog wel benieuwd of ik dit nu inderdaad handig doe, of dat het nog fout zou kunnen gaan?Van | : | Peter | Datum | : | 19-09-2007 |
Aan | : | Ronald Beuker | MsgID | : | 3563.3 |
Onderwerp | : | Tekst plakken in >1 textbox met VB6? | Forum | : | ws-nlcomputer |
Private Sub txtSN_Change(Index As Integer)
'er is een wijziging in 1 van de invoervelden
Dim AantaltekensInTekstbox As Long
Dim MaxAantaltekensInTekstbox As Long
Static ClipText As String
Static CopyFlag As Boolean
Static ValidSN As Boolean
'afhankelijk van de index het max. aantal tekens bepalen
Select Case Index
Case 1: MaxAantaltekensInTekstbox = 2
Case 2, 4: MaxAantaltekensInTekstbox = 6
Case 3: MaxAantaltekensInTekstbox = 8
Case 5: MaxAantaltekensInTekstbox = 4
End Select
txtSN(Index).MaxLength = MaxAantaltekensInTekstbox
AantaltekensInTekstbox = Len(txtSN(Index).Text)
If (Index = 1) Or CopyFlag Then
If Not CopyFlag Then
'index in 1e tekstbox OF copyflag al gezet
ClipText = Clipboard.GetText
'controleer het formaat van de cliptext: lengte en streepjes op de goede plek
If Len(ClipText) = 30 Then
If InStr(ClipText, "-") = 3 Then
If InStr(4, ClipText, "-") = 10 Then
If InStr(11, ClipText, "-") = 19 Then
If InStr(20, ClipText, "-") = 26 Then
ValidSN = True
End If
End If
End If
End If
End If
End If
If Left(ClipText, 2) = txtSN(1).Text And ValidSN Then
'cliptext is geldig, zet CopyFlag en vul de gegevens in
CopyFlag = True
'Letop, dit resulteerd in een aantal recursieve calls!
txtSN(2).Text = Mid(ClipText, 4, 6)
txtSN(3).Text = Mid(ClipText, 11, 8)
txtSN(4).Text = Mid(ClipText, 20, 6)
txtSN(5).Text = Mid(ClipText, 27, 4)
'invullen klaar:
'index naar laatste invoerveld en reset static variabelen
Index = 5
CopyFlag = False
ValidSN = False
End If
End If
If AantaltekensInTekstbox >= MaxAantaltekensInTekstbox Then
If Index < 5 Then
'focus naar volgende tekstbox
txtSN(Index + 1).SetFocus
Else
'schakel OK knop in en zet de focus erop
cmdOK.Enabled = True
cmdOK.SetFocus
End If
End If
End Sub
Verder is de MaakSerienummer() te vereenvoudigen:Public Function MaakSerienummer() As String
MaakSerienummer = txtSN(1).Text & "-" & txtSN(2).Text & "-" & txtSN(3).Text & "-" & txtSN(4).Text & "-" & txtSN(5).Text
End Function
In de Form_Load() event kun je nog Clipboard.Clear opnemen.Van | : | Ronald Beuker | Datum | : | 19-09-2007 |
Aan | : | Peter | MsgID | : | 3563.4 |
Onderwerp | : | Tekst plakken in >1 textbox met VB6? | Forum | : | ws-nlcomputer |
Van | : | Peter | Datum | : | 19-09-2007 |
Aan | : | Ronald Beuker | MsgID | : | 3563.5 |
Onderwerp | : | Tekst plakken in >1 textbox met VB6? | Forum | : | ws-nlcomputer |
Van | : | Ronald Beuker | Datum | : | 08-10-2007 |
Aan | : | Peter | MsgID | : | 3563.6 |
Onderwerp | : | Tekst plakken in >1 textbox met VB6? | Forum | : | ws-nlcomputer |
Van | : | Peter | Datum | : | 08-10-2007 |
Aan | : | Ronald Beuker | MsgID | : | 3563.7 |
Onderwerp | : | Tekst plakken in >1 textbox met VB6? | Forum | : | ws-nlcomputer |