BJ,
ich habe mir eine Funktion gemacht, die mir einen Zahlenwert zurückgibt, wenn die Eingabe gültig ist, egal ob mit Komma oder Punkt.
Option Explicit
Private Declare Function GetSystemDefaultLCID Lib _
"kernel32" () As Long
Private Declare Function GetLocaleInfo Lib "kernel32" _
Alias "GetLocaleInfoA" (ByVal Locale As Long, _
ByVal LCType As Long, ByVal lpLCData As String, _
ByVal cchData As Long) As Long
Const LOCALE_SDECIMAL = &HE
Private Delimiter As String
Private Function GetEntry(ID&) As String
Dim LCID&, Result&, buffer$, Length&
LCID = GetSystemDefaultLCID()
Length = GetLocaleInfo(LCID, ID, buffer, 0) - 1
buffer = Space(Length + 1)
Result = GetLocaleInfo(LCID, ID, buffer, Length)
GetEntry = Left$(buffer, Length)
End Function
Private Sub GetDelimiter()
Delimiter = GetEntry(&HE)
End Sub
Public Function GetDoubleWE(ByVal sVal As String, ByRef dVal As Double) As Boolean
Dim d As Double
On Error GoTo ErrorHandler
sVal = Replace(sVal, ",", Delimiter)
sVal = Replace(sVal, ".", Delimiter)
d = CDbl(sVal)
dVal = d
GetDoubleWE = True
ErrorHandler:
End Function
Private Sub Form_Load()
Dim mDbl As Double
GetDelimiter
If GetDoubleWE(InputBox("Zahl eingeben", "Test", "3,14159"), mDbl) Then
MsgBox mDbl
Else
MsgBox "Kein gültiges Zahlenformat"
End If
End
End Sub
pablo
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP