ABOUT Visual Basic Programmieren Programmierung Download Downloads Tips & Tricks Tipps & Tricks Know-How Praxis VB VBA Visual Basic for Applications VBS VBScript Scripting Windows ActiveX COM OLE API ComputerPC Microsoft Office Microsoft Office 97 Office 2000 Access Word Winword Excel Outlook Addins ASP Active Server Pages COMAddIns ActiveX-Controls OCX UserControl UserDocument Komponenten DLL EXE
Diese Seite wurde zuletzt aktualisiert am 16.01.2003

Diese Seite wurde zuletzt aktualisiert am 16.01.2003
Aktuell im ABOUT Visual Basic-MagazinGrundlagenwissen und TechnologienKnow How, Tipps und Tricks rund um Visual BasicActiveX-Komponenten, Controls, Klassen und mehr...AddIns für die Visual Basic-IDE und die VBA-IDEVBA-Programmierung in MS-Office und anderen AnwendungenScripting-Praxis für den Windows Scripting Host und das Scripting-ControlTools, Komponenten und Dienstleistungen des MarktesRessourcen für Programmierer (Bücher, Job-Börse)Dies&Das...

Themen und Stichwörter im ABOUT Visual Basic-Magazin
Code, Beispiele, Komponenten, Tools im Überblick, Shareware, Freeware
Ihre Service-Seite, Termine, Job-Börse
Melden Sie sich an, um in den vollen Genuss des ABOUT Visual Basic-Magazins zu kommen!
Informationen zum ABOUT Visual Basic-Magazin, Kontakt und Impressum

Zurück...

Grenzen ziehen

Zurück...


Anzeige

(-hg) mailto:hg_inbetween@aboutvb.de

Die Prüfung, ob ein gegebener Wert innerhalb eines gegebenen Wertebereichs liegt, ist eigentlich trivial:

Select Case Value
  Case Min To Max
    ' Wert liegt innerhalb des Wertebereichs
End Select

Die Variante, ob ein gegebener Wert innerhalb von gegebenen Grenzwerten liegt, also nicht auf einen der beiden Grenzwerte fällt, ist ähnlich einfach:

Select Case Value
  Case Is < Min, Is > Max
  Case Else
    ' Wert liegt innerhalb der Grenzwerte
End Select

Und schließlich gibt es noch die Variante, die einen gegebenen Wert auf einen gegebenen Wertebereich reduziert. Dabei wird ein Wert unterhalb des unteren Grenzwertes durch diesen, und ein Wert oberhalb des oberen Grenzwerts durch letzteren ersetzt:

Select Case Value
  Case Is < Min
    Value = Min
  Case Min To Max
    ' Wert bleibt unverändert
  Case Is < Max
    Value = Max
End Select

Wenn Sie die folgenden Hilfsfunktionen verwenden, sparen Sie die (immer wiederkehrende) Eingabe der oben gezeigten Code-Zeilen. Die Parameter (und Rückgabewerte) der Funktionen sind den verschiedenen Datentypen (Integer, Long, Single, Double, Byte, Currency, Date, Variant und String) entsprechend deklariert.

Beim Datentyp Variant kann die Prüfung natürlich nur erfolgreich verlaufen, wenn als Wert und Grenzwerte vergleichbare Datentypen übergeben werden. Außerdem gibt es beim Datentyp Variant noch die Variante für den direkten Vergleich von Werten des Variant-Unterdatentyps Decimal. Die Funktionen für den Datentyp String bieten zusätzlich die Option der exakten (Voreinstellung) oder der von Groß-/Kleinschreibung unabhängigen Prüfung.

Public Function InBetweenInt(ByVal Value As Integer, _
 ByVal Min As Integer, ByVal Max As Integer) As Boolean

  Select Case Value
    Case Min To Max
      InBetweenInt = True
  End Select
End Function

Public Function InBetweenNInt(ByVal Value As Integer, _
 ByVal Min As Integer, ByVal Max As Integer) As Boolean

  Select Case Value
    Case Is < Min, Is > Max
    Case Else
      InBetweenNInt = True
  End Select
End Function

Public Function InBetweenFixInt(ByVal Value As Integer, _
 ByVal Min As Integer, ByVal Max As Integer) As Integer

  Select Case Value
    Case Is < Min
      InBetweenFixInt = Min
    Case Min To Max
      InBetweenFixInt = Value
    Case Is < Max
      InBetweenFixInt = Max
  End Select
End Function

Public Function InBetweenLng(ByVal Value As Long, _
 ByVal Min As Long, ByVal Max As Long) As Boolean

  Select Case Value
    Case Min To Max
      InBetweenLng = True
  End Select
End Function

Public Function InBetweenNLng(ByVal Value As Long, _
 ByVal Min As Long, ByVal Max As Long) As Boolean

  Select Case Value
    Case Is < Min, Is > Max
    Case Else
      InBetweenNLng = True
  End Select
End Function

Public Function InBetweenFixLng(ByVal Value As Long, _
 ByVal Min As Long, ByVal Max As Long) As Long

  Select Case Value
    Case Is < Min
      InBetweenFixLng = Min
    Case Min To Max
      InBetweenFixLng = Value
    Case Is < Max
      InBetweenFixLng = Max
  End Select
End Function

Public Function InBetweenSng(ByVal Value As Single, _
 ByVal Min As Single, ByVal Max As Single) As Boolean

  Select Case Value
    Case Min To Max
      InBetweenSng = True
  End Select
End Function

Public Function InBetweenNSng(ByVal Value As Single, _
 ByVal Min As Single, ByVal Max As Single) As Boolean

  Select Case Value
    Case Is < Min, Is > Max
    Case Else
      InBetweenNSng = True
  End Select
End Function

Public Function InBetweenFixSng(ByVal Value As Single, _
 ByVal Min As Single, ByVal Max As Single) As Single

  Select Case Value
    Case Is < Min
      InBetweenFixSng = Min
    Case Min To Max
      InBetweenFixSng = Value
    Case Is < Max
      InBetweenFixSng = Max
  End Select
End Function

Public Function InBetweenDbl(ByVal Value As Double, _
 ByVal Min As Double, ByVal Max As Double) As Boolean

  Select Case Value
    Case Min To Max
      InBetweenDbl = True
  End Select
End Function

Public Function InBetweenNDbl(ByVal Value As Double, _
 ByVal Min As Double, ByVal Max As Double) As Boolean

  Select Case Value
    Case Is < Min, Is > Max
    Case Else
      InBetweenNDbl = True
  End Select
End Function

Public Function InBetweenFixDbl(ByVal Value As Double, _
 ByVal Min As Double, ByVal Max As Double) As Double

  Select Case Value
    Case Is < Min
      InBetweenFixDbl = Min
    Case Min To Max
      InBetweenFixDbl = Value
    Case Is < Max
      InBetweenFixDbl = Max
  End Select
End Function

Public Function InBetweenByte(ByVal Value As Byte, _
 ByVal Min As Byte, ByVal Max As Byte) As Boolean

  Select Case Value
    Case Min To Max
      InBetweenByte = True
  End Select
End Function

Public Function InBetweenNByte(ByVal Value As Byte, _
 ByVal Min As Byte, ByVal Max As Byte) As Boolean

  Select Case Value
    Case Is < Min, Is > Max
    Case Else
      InBetweenNByte = True
  End Select
End Function

Public Function InBetweenFixByte(ByVal Value As Byte, _
 ByVal Min As Byte, ByVal Max As Byte) As Byte

  Select Case Value
    Case Is < Min
      InBetweenFixByte = Min
    Case Min To Max
      InBetweenFixByte = Value
    Case Is < Max
      InBetweenFixByte = Max
  End Select
End Function

Public Function InBetweenCur(ByVal Value As Currency, _
 ByVal Min As Currency, ByVal Max As Currency) As Boolean

  Select Case Value
    Case Min To Max
      InBetweenCur = True
  End Select
End Function

Public Function InBetweenNCur(ByVal Value As Currency, _
 ByVal Min As Currency, ByVal Max As Currency) As Boolean

  Select Case Value
    Case Is < Min, Is > Max
    Case Else
      InBetweenNCur = True
  End Select
End Function

Public Function InBetweenFixCur(ByVal Value As Currency, _
 ByVal Min As Currency, ByVal Max As Currency) As Currency

  Select Case Value
    Case Is < Min
      InBetweenFixCur = Min
    Case Min To Max
      InBetweenFixCur = Value
    Case Is < Max
      InBetweenFixCur = Max
  End Select
End Function

Public Function InBetweenDate(ByVal Value As Date, _
 ByVal Min As Date, ByVal Max As Date) As Boolean

  Select Case Value
    Case Min To Max
      InBetweenDate = True
  End Select
End Function

Public Function InBetweenNDate(ByVal Value As Date, _
 ByVal Min As Date, ByVal Max As Date) As Boolean

  Select Case Value
    Case Is < Min, Is > Max
    Case Else
      InBetweenNDate = True
  End Select
End Function

Public Function InBetweenFixDate(ByVal Value As Date, _
 ByVal Min As Date, ByVal Max As Date) As Date

  Select Case Value
    Case Is < Min
      InBetweenFixDate = Min
    Case Min To Max
      InBetweenFixDate = Value
    Case Is < Max
      InBetweenFixDate = Max
  End Select
End Function

Public Function InBetweenVar(ByVal Value As Variant, _
 ByVal Min As Variant, ByVal Max As Variant) As Boolean

  Select Case Value
    Case Min To Max
      InBetweenVar = True
  End Select
End Function

Public Function InBetweenNVar(ByVal Value As Variant, _
 ByVal Min As Variant, ByVal Max As Variant) As Boolean

  Select Case Value
    Case Is < Min, Is > Max
    Case Else
      InBetweenNVar = True
  End Select
End Function

Public Function InBetweenFixVar(ByVal Value As Variant, _
 ByVal Min As Variant, ByVal Max As Variant) As Variant

  Select Case Value
    Case Is < Min
      InBetweenFixVar = Min
    Case Min To Max
      InBetweenFixVar = Value
    Case Is < Max
      InBetweenFixVar = Max
  End Select
End Function

Public Function InBetweenDec(ByVal Value As Variant, _
 ByVal Min As Variant, ByVal Max As Variant) As Boolean

  Select Case Value
    Case CDec(Min) To CDec(Max)
      InBetweenDec = True
  End Select
End Function

Public Function InBetweenNDec(ByVal Value As Variant, _
 ByVal Min As Variant, ByVal Max As Variant) As Boolean

  Select Case Value
    Case Is < CDec(Min), Is > CDec(Max)
    Case Else
      InBetweenNDec = True
  End Select
End Function

Public Function InBetweenFixDec(ByVal Value As Variant, _
 ByVal Min As Variant, ByVal Max As Variant) As Variant

  Select Case Value
    Case Is < Min
      InBetweenFixDec = CDec(Min)
    Case CDec(Min) To CDec(Max)
      InBetweenFixDec = Value
    Case Is < Max
      InBetweenFixDec = CDec(Max)
  End Select
End Function

Public Function InBetweenStr(Value As String, Min As String, _
 Max As String, _
 Optional ByVal CaseSensitive As Boolean = True) As Boolean

  If CaseSensitive Then
    Select Case Value
      Case Min To Max
        InBetweenStr = True
    End Select
  Else
    Select Case LCase$(Value)
      Case LCase$(Min) To LCase$(Max)
        InBetweenStr = True
    End Select
  End If
End Function

Public Function InBetweenNStr(Value As String, Min As String, _
 Max As String, _
 Optional ByVal CaseSensitive As Boolean = True) As Boolean

  If CaseSensitive Then
    Select Case Value
      Case Is < Min, Is > Max
      Case Else
        InBetweenNStr = True
    End Select
  Else
    Select Case LCase$(Value)
      Case Is < LCase$(Min), Is > LCase$(Max)
      Case Else
        InBetweenNStr = True
    End Select
  End If
End Function

Public Function InBetweenFixStr(Value As String, Min As String, _
 Max As String, _
 Optional ByVal CaseSensitive As Boolean = True) As String

  If CaseSensitive Then
    Select Case Value
      Case Is < Min
        InBetweenFixStr = Min
      Case Min To Max
        InBetweenFixStr = Value
      Case Is < Max
        InBetweenFixStr = Max
    End Select
  Else
    Select Case LCase$(Value)
      Case Is < LCase$(Min)
        InBetweenFixStr = Min
      Case LCase$(Min) To LCase$(Max)
        InBetweenFixStr = Value
      Case Is < LCase$(Max)
        InBetweenFixStr = Max
    End Select
  End If
End Function

Modul modInBetween (inbetween.zip - ca. 1,2 KB)


Artikel
Zum Download-Bereich dieses Artikel
Mail an den Autor dieses Artikels

KnowHow
Zur KnowHow-Übersicht

KnowHow-Themen
Themen - Allgemeines
Themen - Entwicklungsumgebung (VB-IDE)
Themen - Forms
Themen - Steuerelemente (Controls)
Themen - Grafik
Themen - Dateien
Themen - UserControls
Themen - Einsteiger-Tipps
Themen - Wussten Sie...?

Übersicht nach Titeln in alphabetischer Reihenfolge
Übersicht nach Erscheinungsdatum

Schnellsuche




Zum Seitenanfang

Copyright © 1999 - 2017 Harald M. Genauck, ip-pro gmbh  /  Impressum

Zum Seitenanfang

Zurück...

Zurück...

Download Internet Explorer