Hallo zusammen,
ich habe hier im forum untenstehenden Code gefunden welcher eine Fortschritts-anzeige darstellt. Da ich nicht immer genau weiß wie lange eine Aktion dauert kommt mir dieser gerade recht da er von links nach rechts und wieder zurück wandert, bis das Ereignis abgeschlossen ist. Ich habe nun in mein makro an der Stelle wo die Progressbar loslaufen soll den Text vom Startbutton plaziert "Showwaitbar Me.hwnd,25" - bekomme nun die Fehlermeldung "ungültige Verwendung des Schlüsselwortes Me"!!!
Wahrscheinlich zu einfach gewesen - für mich jedenfalls. Hat jemand eine Idee wie ich dies zum laufen bekomme!!??
Quirin
Private Sub Form_Load()
' WaitBar initialisieren
InitWaitBar Me, picwaitbar
End Sub
Private Sub cmdStart_Click()
' WaitBar starten
ShowWaitBar Me.hWnd, 25
End Sub
Private Sub cmdStop_Click()
' WaitBar ausblenden
StopWaitBar Me.hWnd
End Sub Option Explicit
' Benötigte API's für die Timer-Steuerung
Private Declare Function SetTimer Lib "user32" ( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimer As Long) As Long
Private Declare Function KillTimer Lib "user32" ( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long) As Long
Private Const MY_NID = 88
' Legt fest, in welchen Schritten der
' Balken bewegt werden soll
Private Const nStep = 1
Private m_lblControl As Control
' WaitBar erstellen
Public Sub InitWaitBar(oForm As Form, _
picContainer As Control, _
Optional ByVal nBackColor As OLE_COLOR = &HFFC0C0)
' Label-Control nur erstellen, falls
' nicht schon erstellt.
Dim bExists As Boolean
Dim oControl As Control
For Each oControl In oForm.Controls
If oControl.Name = "lblWaitBar" Then
Set m_lblControl = oControl
bExists = True: Exit For
End If
Next
' ScaleMode auf Pixel setzen
picContainer.ScaleMode = vbPixels
If Not bExists Then
' Label erstellen
Set m_lblControl = oForm.Controls.Add("VB.Label", _
"lblWaitBar", picContainer)
End If
m_lblControl.Caption = ""
m_lblControl.BackColor = nBackColor
End Sub
' WaitBar starten
Public Sub ShowWaitBar(ByVal hWnd As Long, _
Optional ByVal nInterval = 15)
Dim nResult As Long
If Not m_lblControl Is Nothing Then
With m_lblControl
' Label zunächst ganz nach links setzen
.Move -.Width, 0, .Width, .Container.ScaleHeight
.Visible = True
' Timer starten
nResult = SetTimer(hWnd, MY_NID, nInterval, AddressOf WaitBar_TimerEvent)
End With
End If
End Sub
' Timer-Event!
Private Sub WaitBar_TimerEvent( _
ByVal hWnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long)
Dim nLeft As Single
With m_lblControl
' aktuelle Position
nLeft = .Left
If .Tag <> "back" Then
' Vorwärts! (nach rechts bewegen)
nLeft = .Left + nStep
If nLeft + .Width > .Container.ScaleWidth Then
.Tag = "back"
nLeft = .Container.ScaleWidth - .Width
End If
Else
' Rückwärts! (nach links bewegen)
nLeft = .Left - nStep
If nLeft < 0 Then .Tag = "": nLeft = 0
End If
' Label positionieren
.Left = nLeft
End With
End Sub
' WaitBar stoppen
Public Sub StopWaitBar(ByVal hWnd As Long)
' Timer stoppen
KillTimer hWnd, MY_NID
' Label wieder unsichtbar machen
If Not m_lblControl Is Nothing Then
m_lblControl.Visible = False
End If
End Sub |