質問編集履歴
1
全部
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,3 +3,205 @@
|
|
3
3
|
23時間以上表示するのにどのようにしたらよいか、教えてください。
|
4
4
|
|
5
5
|
現段階では、23:59:59のタイマーは作れています。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
Public Class Form3
|
10
|
+
|
11
|
+
Private strSt As String = "00:00:00"
|
12
|
+
|
13
|
+
Private strsy1 As String = strSt.Replace("00", strsy1)
|
14
|
+
|
15
|
+
Private strsy2 As String = strSt.Replace("00", strsy2)
|
16
|
+
|
17
|
+
Private strsy3 As String = strSt.Replace("00", strsy3)
|
18
|
+
|
19
|
+
Private dtmaaa As DateTime
|
20
|
+
|
21
|
+
Private dtmbb As DateTime
|
22
|
+
|
23
|
+
Private ccc As String
|
24
|
+
|
25
|
+
Private hhh As String
|
26
|
+
|
27
|
+
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
|
28
|
+
|
29
|
+
If dtmbb = Nothing Then 'dtmbbの中に何も数値がない時、btn1は押せない
|
30
|
+
|
31
|
+
Else
|
32
|
+
|
33
|
+
If btn1.Text = "スタート" Then 'btn1がスタートと表示されている時、スタートする
|
34
|
+
|
35
|
+
Timer1.Enabled = True
|
36
|
+
|
37
|
+
btn1.Text = "キャンセル" 'btn1がキャンセルと表示される
|
38
|
+
|
39
|
+
Me.btn2.Enabled = False
|
40
|
+
|
41
|
+
dtmaaa = Now
|
42
|
+
|
43
|
+
dtmbb = dtmaaa
|
44
|
+
|
45
|
+
dtmbb = dtmbb.AddHours(strsy1)
|
46
|
+
|
47
|
+
dtmbb = dtmbb.AddMinutes(strsy2)
|
48
|
+
|
49
|
+
dtmbb = dtmbb.AddSeconds(strsy3)
|
50
|
+
|
51
|
+
ccc = dtmbb.ToLongDateString()
|
52
|
+
|
53
|
+
hhh = dtmbb.ToString("HH時mm分ss秒")
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
lbl5.Text = "予定時刻" & ":" & " " & ccc & hhh '予定時刻がlbl5に表示される
|
58
|
+
|
59
|
+
Else btn1.Text = "キャンセル " 'btn2がキャンセルと表示されているとき、クリアされる
|
60
|
+
|
61
|
+
Timer1.Enabled = False
|
62
|
+
|
63
|
+
Me.btn2.Enabled = True
|
64
|
+
|
65
|
+
lbl4.Text = "00:00:00"
|
66
|
+
|
67
|
+
lbl5.Text = "予定時刻 : 0000年00月00日00時間00分00秒"
|
68
|
+
|
69
|
+
btn1.Text = "スタート"
|
70
|
+
|
71
|
+
dtmbb = Nothing
|
72
|
+
|
73
|
+
End If
|
74
|
+
|
75
|
+
End If
|
76
|
+
|
77
|
+
End Sub
|
78
|
+
|
79
|
+
Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
|
80
|
+
|
81
|
+
If Not txt1.Text = "" Or txt2.Text = "" Or txt3.Text = "" Then
|
82
|
+
|
83
|
+
dtmbb = Nothin
|
84
|
+
|
85
|
+
End If
|
86
|
+
|
87
|
+
strsy1 = Val(txt1.Text)
|
88
|
+
|
89
|
+
strsy2 = Val(txt2.Text)
|
90
|
+
|
91
|
+
strsy3 = Val(txt3.Text)
|
92
|
+
|
93
|
+
If strsy1 * 3600 + strsy2 * 60 + strsy3 >= 359999 Then 'もし、時間の合計が24時間を超えると、23:59:59とlbl4に表示される
|
94
|
+
|
95
|
+
MsgBox("エラー", 64)
|
96
|
+
|
97
|
+
txt1.Text = ""
|
98
|
+
|
99
|
+
txt2.Text = ""
|
100
|
+
|
101
|
+
txt3.Text = ""
|
102
|
+
|
103
|
+
lbl4.Text = "00:00:00"
|
104
|
+
|
105
|
+
Else
|
106
|
+
|
107
|
+
If txt1.Text = "" And txt2.Text = "" And txt3.Text = "" Then 'もしすべてのtxtが空の時、数字を入れてくださいと表示される
|
108
|
+
|
109
|
+
MsgBox("数字を入れて下さい。", 64)
|
110
|
+
|
111
|
+
Else
|
112
|
+
|
113
|
+
dtmbb = dtmbb.AddHours(strsy1)
|
114
|
+
|
115
|
+
dtmbb = dtmbb.AddMinutes(strsy2)
|
116
|
+
|
117
|
+
dtmbb = dtmbb.AddSeconds(strsy3)
|
118
|
+
|
119
|
+
If strsy1 * 3600 + strsy2 * 60 + strsy3 <= 1915199 Then
|
120
|
+
|
121
|
+
lbl4.Text = "0" & dtmbb
|
122
|
+
|
123
|
+
Else
|
124
|
+
|
125
|
+
lbl4.Text = dtmbb
|
126
|
+
|
127
|
+
End If
|
128
|
+
|
129
|
+
txt1.Text = ""
|
130
|
+
|
131
|
+
txt2.Text = ""
|
132
|
+
|
133
|
+
txt3.Text = ""
|
134
|
+
|
135
|
+
btn1.Enabled = True
|
136
|
+
|
137
|
+
End If
|
138
|
+
|
139
|
+
End If
|
140
|
+
|
141
|
+
End Sub
|
142
|
+
|
143
|
+
Dim TIME As Integer
|
144
|
+
|
145
|
+
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
|
146
|
+
|
147
|
+
Dim TimeLeft As TimeSpan
|
148
|
+
|
149
|
+
'残り時間の計算
|
150
|
+
|
151
|
+
TimeLeft = dtmbb - Now
|
152
|
+
|
153
|
+
'残り時間の表示
|
154
|
+
|
155
|
+
Dim ts1 As New TimeSpan(1, 0, 0, 0)
|
156
|
+
|
157
|
+
'
|
158
|
+
|
159
|
+
If TimeLeft > New TimeSpan(1, 0, 0, 0) Then
|
160
|
+
|
161
|
+
TIME = TimeLeft.ToString()
|
162
|
+
|
163
|
+
lbl4.Text = TimeLeft.ToString("mm\:ss")
|
164
|
+
|
165
|
+
lbl4.Text = TIME & ":" & lbl4.Text
|
166
|
+
|
167
|
+
Else
|
168
|
+
|
169
|
+
lbl4.Text = TimeLeft.ToString("hh\:mm\:ss")
|
170
|
+
|
171
|
+
End If
|
172
|
+
|
173
|
+
'lbl4.Text = gogo & ":" & lbl4.Text
|
174
|
+
|
175
|
+
'残り時間が1秒を切ったら終了
|
176
|
+
|
177
|
+
If TimeLeft < New TimeSpan(0, 0, 1) Then
|
178
|
+
|
179
|
+
Timer1.Enabled = False
|
180
|
+
|
181
|
+
MsgBox("時間です!", 64)
|
182
|
+
|
183
|
+
End If
|
184
|
+
|
185
|
+
End Sub
|
186
|
+
|
187
|
+
Private Sub txt1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txt3.KeyPress, txt2.KeyPress, txt1.KeyPress, MyBase.KeyPress
|
188
|
+
|
189
|
+
txt1.MaxLength = 2 'テキストボックスには三ケタまでしか入力できない
|
190
|
+
|
191
|
+
txt2.MaxLength = 4
|
192
|
+
|
193
|
+
txt3.MaxLength = 4
|
194
|
+
|
195
|
+
If (e.KeyChar < "0"c OrElse "9"c < e.KeyChar) AndAlso
|
196
|
+
|
197
|
+
e.KeyChar <> ControlChars.Back Then
|
198
|
+
|
199
|
+
'押されたキーが 0~9、backキーでない場合は、イベントをキャンセルする
|
200
|
+
|
201
|
+
e.Handled = True
|
202
|
+
|
203
|
+
End If
|
204
|
+
|
205
|
+
End Sub
|
206
|
+
|
207
|
+
End Class
|