При нажатии кнопки СТАРТ запоминай текущее время
А чтобы отображалось время в текстовом поле, используй таймер с интервалом 1 секунда и в его событии изменяй время в текстовом поле
Private Sub Timer1_Timer()
Text1.Text = Time$
End Sub
Option Explicit
'api
Private Const SM_CXFRAME As Long = 32
Private Const SM_CYCAPTION As Long = 4
Private Const SM_CYFRAME As Long = 33
Private Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long
'private
Private TARIFF As Single
Private nSeconds As Long
'controls
Dim WithEvents lblTime As Label
Dim WithEvents timTimer As Timer
Dim WithEvents cmdStart As CommandButton
Dim WithEvents cmdStop As CommandButton
Private Sub Form_Load()
'dynamically generate user interface
Set lblTime = Me.Controls.Add("VB.Label", "lblTime")
lblTime.Visible = True
lblTime.Caption = "00:00:00"
lblTime.AutoSize = True
Set timTimer = Me.Controls.Add("VB.Timer", "timTimer")
Set cmdStart = Me.Controls.Add("VB.CommandButton", "cmdStart")
Set cmdStop = Me.Controls.Add("VB.CommandButton", "cmdStop")
cmdStart.Visible = True
cmdStop.Visible = False
cmdStart.Top = lblTime.Top + lblTime.Height + 10
cmdStop.Top = cmdStart.Top
cmdStop.Left = cmdStart.Left
cmdStop.Caption = "Stop"
cmdStart.Caption = "Start"
Me.Width = cmdStop.Left + cmdStop.Width + _
2 * GetSystemMetrics(SM_CXFRAME) * Screen.TwipsPerPixelX
Me.Height = cmdStop.Top + cmdStop.Height + _
(GetSystemMetrics(SM_CYCAPTION) + 2 * _
GetSystemMetrics(SM_CYFRAME)) * Screen.TwipsPerPixelY
Me.Caption = "Demo"
timTimer.Enabled = False
timTimer.Interval = 1000
End Sub
'event handlers
Private Sub cmdStart_Click()
TARIFF = InputBox("Enter tariff value:", _
"Extremely Difficult Application", 2.5)
cmdStart.Visible = False
cmdStop.Visible = True
timTimer.Enabled = True
timTimer_Timer
End Sub
Private Sub cmdStop_Click()
timTimer.Enabled = False
cmdStart.Visible = True
cmdStop.Visible = False
MsgBox "You spent $" & Format(nSeconds * TARIFF, _
"##.##") & " on answering stupid questions on VBStreets Forum."
nSeconds = 0
End Sub
Private Sub timTimer_Timer()
Dim pSeconds As Long, pMinutes As Long, pHours As Long
nSeconds = nSeconds + 1
If nSeconds < 60 Then
pSeconds = nSeconds
Else
pMinutes = nSeconds \ 60
If pMinutes < 60 Then
pSeconds = nSeconds Mod 60
Else
pHours = nSeconds \ 3600
pMinutes = pMinutes Mod 60
pSeconds = nSeconds Mod 60
End If
End If
lblTime.Caption = Format(pHours, "00") & ":" & _
Format(pMinutes, "00") & ":" & Format(pSeconds, "00")
End Sub
hCORe писал(а):
- Код: Выделить всё
Option Explicit
'api
Private Const SM_CXFRAME As Long = 32
Private Const SM_CYCAPTION As Long = 4
Private Const SM_CYFRAME As Long = 33
Private Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long
'private
Private TARIFF As Single
Private nSeconds As Long
'controls
Dim WithEvents lblTime As Label
Dim WithEvents timTimer As Timer
Dim WithEvents cmdStart As CommandButton
Dim WithEvents cmdStop As CommandButton
Private Sub Form_Load()
'dynamically generate user interface
Set lblTime = Me.Controls.Add("VB.Label", "lblTime")
lblTime.Visible = True
lblTime.Caption = "00:00:00"
lblTime.AutoSize = True
Set timTimer = Me.Controls.Add("VB.Timer", "timTimer")
Set cmdStart = Me.Controls.Add("VB.CommandButton", "cmdStart")
Set cmdStop = Me.Controls.Add("VB.CommandButton", "cmdStop")
cmdStart.Visible = True
cmdStop.Visible = False
cmdStart.Top = lblTime.Top + lblTime.Height + 10
cmdStop.Top = cmdStart.Top
cmdStop.Left = cmdStart.Left
cmdStop.Caption = "Stop"
cmdStart.Caption = "Start"
Me.Width = cmdStop.Left + cmdStop.Width + _
2 * GetSystemMetrics(SM_CXFRAME) * Screen.TwipsPerPixelX
Me.Height = cmdStop.Top + cmdStop.Height + _
(GetSystemMetrics(SM_CYCAPTION) + 2 * _
GetSystemMetrics(SM_CYFRAME)) * Screen.TwipsPerPixelY
Me.Caption = "Demo"
timTimer.Enabled = False
timTimer.Interval = 1000
End Sub
'event handlers
Private Sub cmdStart_Click()
TARIFF = InputBox("Enter tariff value:", _
"Extremely Difficult Application", 2.5)
cmdStart.Visible = False
cmdStop.Visible = True
timTimer.Enabled = True
timTimer_Timer
End Sub
Private Sub cmdStop_Click()
timTimer.Enabled = False
cmdStart.Visible = True
cmdStop.Visible = False
MsgBox "You spent $" & Format(nSeconds * TARIFF, _
"##.##") & " on answering stupid questions on VBStreets Forum."
nSeconds = 0
End Sub
Private Sub timTimer_Timer()
Dim pSeconds As Long, pMinutes As Long, pHours As Long
nSeconds = nSeconds + 1
If nSeconds < 60 Then
pSeconds = nSeconds
Else
pMinutes = nSeconds \ 60
If pMinutes < 60 Then
pSeconds = nSeconds Mod 60
Else
pHours = nSeconds \ 3600
pMinutes = pMinutes Mod 60
pSeconds = nSeconds Mod 60
End If
End If
lblTime.Caption = Format(pHours, "00") & ":" & _
Format(pMinutes, "00") & ":" & Format(pSeconds, "00")
End Sub
Если разберешься в этом коде, создать и более сложные приложения для тебя не составит труда. Удачи!
Steel писал(а):!Viper! писал(а):Воспользоваться функцией Format например
Где можно посмотреть примеры функций?
Private Sub Start_Click()
Start.Visible = False
Stop.Visible = True
Time.Text = Time$
End Sub
Private Sub Stop_Click()
Start.Visible = True
Stop.Visible = False
End Sub
Private Sub Timer1_Timer()
Time.Text = Time$
End Sub
Private Sub cmdStart_Click()
cmdStart.Visible = False
cmdStop.Visible = True
txtTime.Text = Time$
End Sub
Private Sub cmdStop_Click()
cmdStart.Visible = True
cmdStop.Visible = False
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
txtTime.Text = Time$
End Sub
Роман-вб писал(а):Steel
Ну как можно писать Stop.Visible.
Private Sub Form_Load()
proStart.Enabled = True
proStop.Enabled = False
End Sub
Private Sub proStart_Click()
StartTime = Time
PriceBegin = "Введите цену сеанса:"
proPrice = InputBox(PriceBegin, "Цена сеанса")
proTimer.Enabled = True
proStart.Enabled = False
proStop.Enabled = True
UserTariff = Val(proTime.Caption)
End Sub
Private Sub proStop_Click()
StopTime = Time
proTimer.Enabled = False
MsgBox "Клиент должен: (здесь должно показывать скока клиент должен) руб.", , "Kompas"
proStart.Enabled = True
proStop.Enabled = False
proTime.Caption = "Сеанс окончен."
End Sub
Private Sub proTimer_Timer()
proTime.Caption = Format$(proPrice - StartTime, "hh:nn:ss")
End Sub
Function GetMoney(ByVal UserTime As Date, ByVal UserTarif As Currency) As Currency
GetMoney = ((Hour(UserTime) * 60) + Minute(UserTime)) + (Second(UserTime) / 60) * (UserTarif / 60)
End Function
НА какую кнопку? Из твоего кода сложно понять где у тебя кнопка, а где нет. Имя "кнопки" принято начинать с cmd (или btn).Почему после нажатия на кнопку таймер не идет? И как вывести скока должен клиент?
Private Sub proTimer_Timer()
proTime.Caption = Format$(proPrice - StartTime, "hh:nn:ss")
End Sub
Steel писал(а):
- Код: Выделить всё
Private Sub Form_Load()
proStart.Enabled = True
=============================
Function GetMoney(ByVal UserTime As Date, ByVal UserTarif As Currency) As Currency
GetMoney = ((Hour(UserTime) * 60) + Minute(UserTime)) + (Second(UserTime) / 60) * (UserTarif / 60)
End Function
Почему после нажатия на кнопку таймер не идет? И как вывести скока должен клиент?
Сейчас этот форум просматривают: SemrushBot и гости: 132