Visual Basic 6

10 kleine Helferlein

Hilfsfunktionen, die das Leben erleichtern

In fast jedem VB-Projekt gibt es ein Modul "Tools" o.ä., das kleine Hilfsfunktionen enthält, die meist nur wenige Zeilen lang sind, aber das abdecken, was Microsoft "vergessen" hat oder was unter das Thema "Code-Redundanz" fällt.

Ein Beispiel hierfür ist die dann doch so nützliche Funktion nz, die zwar im VBA-Sprachumfang vorhanden ist, aber eben nicht in Visual Basic 6. In diesem Artikel habe ich mal 10 solcher Mini-Funktionen zusammengefasst.

Nz

Diese Funktion gibt bei positiver Prüfung der Eingangsvariable auf NULL oder <leer> die Ersetzunsgvariable zurück.

Public Function nz(varValue As Variant, varReplace As Variant)
As Variant

   If IsNull(varValue) Or varValue = "" Then
      nz = varReplace
   Else
      nz = varValue
   End If

End Function

SleepAWhile

Diese Funktion nötigt das System, eine Anzahl von Sekunden die Arbeit einzustellen, um zum Beispiel sicherzustellen, dass eine SQL-Transaktion abgearbeitet wurde.

Deklarationen:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Funktion:

Public Function SleepAWhile(intSeconds As Integer)
   Call Sleep(intSeconds * 1000)
End Function

SelectText

Benutzer sind es gewohnt, dass der Text in einem Textfeld komplett markiert ist, wenn das Textfeld den Focus erhält. Mit VB-Bordmitteln ist dies nicht zu bewerkstelligen, aber mit dieser Funktion, wenn Sie in das GotFocus-Ereignis des Textfelds eingestellt wird.

Public Function SelectText()

   On Error Resume Next

   Screen.ActiveControl.SelStart = 0
   Screen.ActiveControl.SelLength = Len(Screen.ActiveControl.Text)

End Function

IsFormLoaded

Diese Funktion überprüft, ob ein bestimmtes Formular bereits geladen wurde.

Public Function IsFormLoaded(ByVal strFormName As String) As Boolean

   Dim i As Integer

   For i = 0 To Forms.Count
      IsFormLoaded = Forms(i).Name = strFormName
      Exit Function
   Next

End Function

IsInIDE

Diese Funktion überprüft, ob das Programm über die VB6-IDE oder als kompilierte EXE gestartet wurde.

Deklaration:

Private Declare Function GetModuleFileName Lib "kernel32" _
   Alias "GetModuleFileNameA" ( _
   ByVal hModule As Long, _
   ByVal lpFileName As String, _
   ByVal nSize As Long) As Long

Funktion:

Public Function IsInIDE() As Boolean

   Dim strFileName As String
   Dim lngCount As Long

   strFileName = String(255, 0)
   lngCount = GetModuleFileName(App.hInstance, strFileName, 255)
   strFileName = Left(strFileName, lngCount)

   If UCase(Right(strFileName, 7)) = "VB6.EXE" Then
      IsInIDE = True
   End If

End Function

SplitEx

Die normale Split-Funktion zerlegt einen String anhand eines Delimiters. Diese Funktion hier zerlegt ihn anhand einer Schrittweite. Der Rückgabewert ist, wie beim Original, ein Array.

Public Function SplitEx( _
   ByVal strIn As String, _
   ByVal intCharCount As Integer) As String()

   Dim arr() As String
   Dim i As Integer
   Dim j As Integer

   ReDim arr(0)

   For i = 1 To Len(strIn) Step intCharCount
      arr(j) = Mid(strIn, i, intCharCount)
      ReDim Preserve arr(UBound(arr) + 1)
      j = j + 1
   Next

   ReDim Preserve arr(UBound(arr) - 1)

   SplitEx = arr

End Function

TrimNull

Viele API-Funktionen geben Strings fester Länge zurück, wobei der nicht benötigte Platz mit NullChars aufgefüllt sind. Diese Funktion schneidet diese NullChars wieder ab.

Public Function TrimNull(strValue As String) As String

   Dim arr() As String

   arr = Split(strValue, vbNullChar)
   TrimNull = arr(0)

End Function

String2Date

Manchmal kann es vorkommen, gerade im Umgang mit Datenbanken, dass ein Datum ohne Trennzeichen zurückgeliefert wird. Diese Funktion setzt sie wieder ein.

Public Function String2Date(ByVal strIn As String) As String

   If Len(strIn) = 6 Then
      String2Date = Left(strIn, 2) & "." & Mid(strIn, 3,2) & "." & Right(strIn, 2)
   ElseIf Len(strIn) = 8 Then
      String2Date = Left(strIn, 2) & "." & Mid(strIn, 3,2) & "." & Right(strIn, 4)
   ElseIf Len(strIn) = 10 Then
      String2Date = strIn
   End If

End Function

AscEx

Die ASC-Funktion schlägt fehl, wenn der übergebene String leer ist. Diese Funktion behebt das Problem.

Public Function AscEx(ByVal strChar As String)

   If strChar = "" Then
      AscEx = 0
   Else
      AscEx = Asc(strChar)
   End If

End Function

ValueGreaterNull

Verstecken sich Zahlen in String-Variablen, kann man mit dieser Funktion überprüfen, ob der Wert numerisch größer Null ist.

Public Function ValueGreaterNull(ByVal strValue As String) As
Boolean

   If Len(Trim$(strValue)) > 0 Then
      If IsNumeric(strValue) Then
         If CDbl(strValue) > 0 Then
             ValueGreaterNull = True
         End If
      End If
   End If

End Function
kick it on dotnet-kicks.de AddThis Trackback-Url...

Verwandte Artikel

VB-Programm als Dienst starten

Schlagworte

56 Kommentare bislang...

  • s, relatives, boyfriend even if they can Replica Tiffany Jewelrysee all these people every day. A lot of women instead love to receive presents they can use every day orReplica Tiffany even better wear.Clothes, bags, shoes, underwear are always a must, these presents will always make a woman happy. It pandora beads charmsis clear that first of all you need to understand whichThomas Sabo Charmsone your girlfriend would prefer. ThiTiffany Pendants could be quite easy of you just stop fortresor paris braceletssome seconds to listen to the signals she's sending you. Because a wotresor braceletman is always sending some signals, even if her man is listening or not. And despite the gift you will buy for her, nothingbuddha to buddha bracelet will make her happier than knowing you are listening and understanding her, even when she is not speaking plainly.Of course, just dividing women replica shoesin two so wide categocheap shoesries is too reductive, limits oftcheap shoes onlineen are not so clear but extremelyBuddha Buddha braceletfluid. They depend on situations, on the occasion, on her mood. Given this, you could still have nFreshwater Pearlso idea about what give to youpearl earringr girlfriend. Don't panic, it is pearl necklaceabsolutely normal. But the aCheap Pandora Beadslternatives are really nutresor parismerous. You can go from jewelery to clothes, to any kind of clothing accessories. If you are noBuddha bracelett sure to meet her taste, it is better tCheap Pandora Beadso turn down on other thinks, like for examle a parfum.But you can also consideCheap Pandorar electonic goods, such as iPod orPandora Beads iPod accessories. OrThomas Sabo Charm maybe some game console, tcharms thomas sabohat lately have addressed thepandora jewelrymselves to attract also the femal sector with new colors and new games that cpandora braceletould entertain also girls. If pandora jewelleryshe is very sportive, you have a widepandora beads charmsrange of choice in thePearl Jewelry sportwear sector or in Pearl Earringsthe sport equipment sector.In the end, it is not clearly an imposPearl Ringssible task, just thinking about for some time you can easily
    bring it to a close as every year. a pearl necklaceAnd if you really can't find anything tfreshwater pearl necklacehat can satisfy you, you can still write down for her
    the most romantic pearl ringOr cooking for her a romantic dinner. If you don't want to cook, pack your clothes and go take a trip somewhere even just a freshwater pearl earringsfew days together will make your love shine and win over everything!
    56
    fred : Montag, 16. Januar 2012 17:45
  • <p class="MsoNormal" /><p class="MsoNormal" /><p class="MsoNormal" /><p class="MsoNormal" /><p class="MsoNormal" /><p class="MsoNormal" /><p class="MsoNormal" /><p class="MsoNormal" /><p class="MsoNormal" /><p class="MsoNormal"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; ">s, relatives, boyfriend even if they can </span><a href="http://www.rtjewelry.com/tiffany-necklaces66-c-27.html">Replica Tiffany
    Jewelry</a><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; ">see all these people every day. A lot of women instead love to
    receive presents they can use every day or</span><a href="http://www.rtjewelry.com/tiffany-pendant228-c-26.html">Replica Tiffany</a><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; "> even better wear.Clothes, bags, shoes, underwear are always a
    must, these presents will always make a woman happy. It </span><a href="http://www.rtjewelry.com/pandora-beadsglass-c-55.html"><b>pandora beads</b>
    charms</a><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; ">is clear that first of all you need to understand which</span><a href="http://www.rtjewelry.com/thomas-sabo-charms-538-c-11.html">Thomas Sabo Charms</a><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; ">one your girlfriend would prefer. Thi</span><a href="http://www.rtjewelry.com/tiffany-pendant228-c-26.html">Tiffany Pendant</a><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; ">s could be quite easy of you just stop for</span><a href="http://www.rtjewelry.com/tresor-paris-bracelet145-c-12.html"><b>tresor
    paris</b> bracelets</a><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; ">some seconds to listen to the
    signals she's sending you. Because a wo</span><a href="http://www.rtjewelry.com/tresor-paris-bracelet145-c-12.html">tresor
    bracelet</a><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; ">man is always sending some signals, even if her man is listening
    or not. And despite the gift you will buy for her, nothing</span><a href="http://www.rtjewelry.com/buddha-to-buddha-bracelet20-c-46.html"><b><span style="font-size: 9pt; line-height: 115%; font-family: Arial, sans-serif; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; ">buddha to buddha bracelet</span></b></a><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; "> will make her happier than knowing you are listening and
    understanding her, even when she is not speaking plainly.Of<span class="apple-converted-space"> </span></span><a href="http://goarticles.com/article/Gift-for-your-girlfriend/1460604/"><span class="klink"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; text-decoration: none; ">course</span></span></a><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans-serif; ">, just dividing women </span><a href="http://www.clreplicas.com/">replica
    shoes</a><span style="font-size: 10pt; line-height: 115%; font-family: Verdana, sans
    55
    fred : Montag, 16. Januar 2012 17:43
  • It is a authentic idea that your style necklaces is actually typically the most popular items not merely on the list of aging population females but in addition involving a lot of girls. It can meet what's needed regarding both the odd quality and a sophisticated choice, hence despite what type you'll choose to, there will probably be described as a right one for you.
    Luxury Louis Vuitton
    Tiffany Jewelry
    Pandora Charm Bracelet
    Pandora Bracelets Sale
    Pandora Bracelets On Sale
    54
    gaibianziji : Donnerstag, 12. Januar 2012 04:02
  • It is a authentic idea that your style necklaces is actually typically the most popular items not merely on the list of aging population females but in addition involving a lot of girls. It can meet what's needed regarding both the odd quality and a sophisticated choice, hence despite what type you'll choose to, there will probably be described as a right one for you.
    <a href="http://www.louisvuittonoutlethero.com/">Louis Vuitton Outlet</a>
    <a href="http://www.tiffanystorer.com/">Tiffany Store</a>
    <a href="http://www.pandorabraceletsr.com/">Pandora Bracelets</a>
    <a href="http://www.pandorabraceletssaler.com/">Pandora Bracelets</a>
    <a href="http://www.pandorabraceletsonsaler.com/">Pandora Bracelets sale</a>
    53
    gaibianziji : Donnerstag, 12. Januar 2012 04:00
  • It is a authentic idea that your style necklaces is actually typically the most popular items not merely on the list of aging population females but in addition involving a lot of girls. It can meet what's needed regarding both the odd quality and a sophisticated choice, hence despite what type you'll choose to, there will probably be described as a right one for you.
    52
    gaibianziji : Donnerstag, 12. Januar 2012 03:50

Dein Kommentar hierzu...


Kommentar-Feed für diesen Beitrag
Gravatare werden unterstützt .:. eMail-Adressen werden nicht veröffentlicht
 

RSS-Feed

Die URL des Standard-Newsfeed von zerbit.de lautet:

http://www.zerbit.de/rssfeed.aspx

Login


 

 

Statistik



kürzlich kommentiert

Artikel 10

  • Datum: 16.02.2005
    Kategorie: Visual Basic 6
    Zugriffe: 3.064
    Kommentare: 56
    Trackbacks: 0

Letzte Beiträge

Kategorien

Buttons & More

Blog-Roll

Banner Piraten-Partei