Anzeige
Archiv - Navigation
212to216
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
212to216
212to216
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Datumseingabe TTMMJJJJ - Ausgabe in TT.MM.JJJJ

Datumseingabe TTMMJJJJ - Ausgabe in TT.MM.JJJJ
01.02.2003 18:21:00
Anna
Hallo Spezialisten,
ich schaffe es nicht, den folgenden Code (Hier wird die Jahrszahl nur zweistellig eingeben) so umzuschreiben, dass das Eingabedatum in der Form TTMMJJJJ (Jahreszahl vierstellig!) erfolgen muss und das Ausgabedatum dann in der Form TT.MM.JJJJ erscheint. Wer kann helfen.

Private Sub txtAntrag_Change()
Dim dteEingabe As Date
Dim iDay As Integer, iMonth As Integer, iYear As Integer
If txtAntrag.Text = "" Then Exit Sub
If Not IsNumeric(Right(txtAntrag.Text, 1)) Then
Beep
txtAntrag.SelStart = Len(txtAntrag.Text) - 1
txtAntrag.SelLength = 1
lblAusgabe.Caption = "Nur Ziffern erlaubt!"
Exit Sub
Else
lblAusgabe.Caption = ""
End If
iDay = CInt(Left(txtAntrag.Text, 2))
Select Case Len(txtAntrag.Text)
Case 0
Case 1
If iDay > 3 Then
Beep
txtAntrag.SelStart = 0
txtAntrag.SelLength = 1
lblAusgabe.Caption = "Maximal 31 Tage"
Else
lblAusgabe.Caption = ""
End If
Case 2
If iDay > 31 Then
Beep
txtAntrag.SelStart = 0
txtAntrag.SelLength = 2
lblAusgabe.Caption = "Maximal 31 Tage"
Else
lblAusgabe.Caption = ""
End If
Case 3
iMonth = CInt(Right(txtAntrag.Text, 1))
If iMonth > 1 Then
Beep
txtAntrag.SelStart = 2
txtAntrag.SelLength = 1
lblAusgabe.Caption = "Maximal 12 Monate"
Else
lblAusgabe.Caption = ""
End If
Case 4
iMonth = CInt(Right(txtAntrag.Text, 2))
If iMonth > 12 Then
Beep
txtAntrag.SelStart = 2
txtAntrag.SelLength = 2
lblAusgabe.Caption = "Maximal 12 Monate"
Else
lblAusgabe.Caption = ""
End If
Select Case iMonth
Case 2
If iDay > 29 Then
Beep
txtAntrag.SelStart = 0
txtAntrag.SelLength = 4
lblAusgabe.Caption = "Maximal 29 Tage"
Else
lblAusgabe.Caption = ""
End If
Case 4, 6, 9, 11
If iDay > 30 Then
Beep
txtAntrag.SelStart = 0
txtAntrag.SelLength = 4
lblAusgabe.Caption = "Maximal 30 Tage"
Else
lblAusgabe.Caption = ""
End If
End Select
Case 6
iMonth = CInt(Mid(txtAntrag.Text, 3, 2))
iYear = CInt(Right(txtAntrag.Text, 2))
If iYear Mod 4 > 0 And iMonth = 2 And iDay = 29 Then
Beep
txtAntrag.SelStart = 0
txtAntrag.SelLength = 6
lblAusgabe.Caption = "Maximal 28 Tage"
Else
txtAntrag.Text = DateSerial(iYear, iMonth, iDay)
dteEingabe = DateSerial(iYear, iMonth, iDay)
'lblAusgabe.Caption = dteEingabe & vbLf & Format(dteEingabe, "dddd")
txtAntrag.SelStart = 0
txtAntrag.SelLength = 6
'End If
txtFaelligkeit.SetFocus
txtFaelligkeit.SelStart = 0
txtFaelligkeit.SelLength = Len(txtFaelligkeit.Text)
End If
End Select
End Sub

Ich danke Euch.
Liebe Grüße aus Würzburg


4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
Re: Datumseingabe TTMMJJJJ - Ausgabe in TT.MM.JJJJ
01.02.2003 19:28:40
ch

DO
DO
DO
datum = InputBox("Bitte geben Sie das Datum in der Form DDMMJJJJ ein!")
tag = Left(datum,2)
IF tag > 31 OR tag < 0 THEN
MsgBox "Bitte gültigen Tag eingeben!",,""
ELSE
EXIT DO
END IF
LOOP
monat = Left(tag,2)
IF monat > 0 OR monat > 12 THEN
MsgBox "Bitte gültigen Monat eingeben!",,""
ELSE
EXIT DO
END IF
LOOP
jahr = Right(datum,4)
realdat = tag & "." & monat & "." & jahr
LOOP

Danke, aber ...
01.02.2003 20:45:43
Ánna

Danke, aber der Code als solcher soll erhalten bleiben. Nur wie erreiche ich es, dass erst nach der Eingabe von 8 Zeichen und nicht wie jetzt schon nach 6 Zeichen abgebrochen wird?
Liebe Grüße
Anna

Anzeige
Re: Danke, aber ...
01.02.2003 21:15:13
Nepumuk

Hallo Anna,
winzige Änderung:

Private Sub txtAntrag_Change()
Dim dteEingabe As Date
Dim iDay As Integer, iMonth As Integer, iYear As Integer
If txtAntrag.Text = "" Then Exit Sub
If Not IsNumeric(Right(txtAntrag.Text, 1)) Then
Beep
txtAntrag.SelStart = Len(txtAntrag.Text) - 1
txtAntrag.SelLength = 1
lblAusgabe.Caption = "Nur Ziffern erlaubt!"
Exit Sub
Else
lblAusgabe.Caption = ""
End If
iDay = CInt(Left(txtAntrag.Text, 2))
Select Case Len(txtAntrag.Text)
Case 0
Case 1
If iDay > 3 Then
Beep
txtAntrag.SelStart = 0
txtAntrag.SelLength = 1
lblAusgabe.Caption = "Maximal 31 Tage"
Else
lblAusgabe.Caption = ""
End If
Case 2
If iDay > 31 Then
Beep
txtAntrag.SelStart = 0
txtAntrag.SelLength = 2
lblAusgabe.Caption = "Maximal 31 Tage"
Else
lblAusgabe.Caption = ""
End If
Case 3
iMonth = CInt(Right(txtAntrag.Text, 1))
If iMonth > 1 Then
Beep
txtAntrag.SelStart = 2
txtAntrag.SelLength = 1
lblAusgabe.Caption = "Maximal 12 Monate"
Else
lblAusgabe.Caption = ""
End If
Case 4
iMonth = CInt(Right(txtAntrag.Text, 2))
If iMonth > 12 Then
Beep
txtAntrag.SelStart = 2
txtAntrag.SelLength = 2
lblAusgabe.Caption = "Maximal 12 Monate"
Else
lblAusgabe.Caption = ""
End If
Select Case iMonth
Case 2
If iDay > 29 Then
Beep
txtAntrag.SelStart = 0
txtAntrag.SelLength = 4
lblAusgabe.Caption = "Maximal 29 Tage"
Else
lblAusgabe.Caption = ""
End If
Case 4, 6, 9, 11
If iDay > 30 Then
Beep
txtAntrag.SelStart = 0
txtAntrag.SelLength = 4
lblAusgabe.Caption = "Maximal 30 Tage"
Else
lblAusgabe.Caption = ""
End If
End Select
Case 8 '<============================================ Hier geändert von 6 auf 8
iMonth = CInt(Mid(txtAntrag.Text, 3, 2))
iYear = CInt(Right(txtAntrag.Text, 2))
If iYear Mod 4 > 0 And iMonth = 2 And iDay = 29 Then
Beep
txtAntrag.SelStart = 0
txtAntrag.SelLength = 6
lblAusgabe.Caption = "Maximal 28 Tage"
Else
txtAntrag.Text = DateSerial(iYear, iMonth, iDay)
dteEingabe = DateSerial(iYear, iMonth, iDay)
'lblAusgabe.Caption = dteEingabe & vbLf & Format(dteEingabe, "dddd")
txtAntrag.SelStart = 0
txtAntrag.SelLength = 6
'End If
txtFaelligkeit.SetFocus
txtFaelligkeit.SelStart = 0
txtFaelligkeit.SelLength = Len(txtFaelligkeit.Text)
End If
End Select
End Sub

Gruß
Nepumuk


Anzeige
Danke, Nepumuk, wie war das mit dem Wald ... o.T.
01.02.2003 21:38:18
Anna



306 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige