 |
|
อบถามการใช้ Label ของVB2010 ให้แสดงผลเป็นตัวเลข2หลัก เช่น 00 ต้องทำยังไงครับ |
|
 |
|
|
 |
 |
|
ToString("00")
|
 |
 |
 |
 |
Date :
2017-02-05 00:02:08 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
time = Date.Now.ToString.Split(" ")(1)
Label1.Text$ = time
If i = 1 And time.Substring(0, time.Length - 3) = Label2.Text$ & ":" & Label4.Text$ And
time.Substring(time.Length - 2, 2) = "00" Then
Timer1.Stop()
My.Computer.Audio.Play(My.Resources.beep, AudioPlayMode.BackgroundLoop)
Me.WindowState = FormWindowState.Normal
Dim p As New Point
p.X = (Me.Width / 2) - (Label1.Width / 2)
p.Y = Label1.Top
If Not Label1.Text$ = vbNullString Then
Label1.Location = p
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label2.Text = TextBox1.Text
Label4.Text = TextBox2.Text + 1
If Button1.Text$ = "ENABLE" Then
Button1.Text$ = "DISABLE"
i = 1
Else
My.Computer.Audio.Stop()
TextBox1.Clear()
TextBox2.Clear()
Timer1.Start()
i = 0
Button1.Text$ = "ENABLE"
End If
If Label4.Text >= 60 Then
Label2.Text = Label2.Text + 1
Label4.Text = Label4.Text - 60
End If
End Sub
ต้องเพิ่มในส่วนใหนเหรอครับ
|
 |
 |
 |
 |
Date :
2017-02-05 00:27:58 |
By :
mogkung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim a, b As Integer
a = 2
b = 5
Label1.Text = (a + b).ToString("00")
End Sub
|
 |
 |
 |
 |
Date :
2017-02-05 00:30:00 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เกือบเข้าใจแหะ มันเป็น label4 มันเป็น 3 จริงๆต้องเป็น 03 ตั้งค่าให้ มีเสียงดังเหมือน label4ตรงกับ นาฬิกาอะครับ
ไม่รู้จะเอา Tostring ไปวา่งตรงใหนดี

ขอโทษจริงๆครับ พึ่งหัดทำครั้งแรก ฝึกตามYoutube มาล้วน :(
|
ประวัติการแก้ไข 2017-02-05 00:50:43
 |
 |
 |
 |
Date :
2017-02-05 00:47:35 |
By :
mogkung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
convert จาก Date.Now.ToString ก็ได้เช่นกัน
Code (VB.NET)
Date.Now.ToString("hh:mm:ss")
แต่ถ้าไม่สะดวก ก็คงต้อง convert String เป็น ตัวเลข แล้ว เอาตัวเลขมา convert ToString
Code (VB.NET)
Dim str = "6"
Label1.Text = Integer.Parse(str).ToString("00")
|
 |
 |
 |
 |
Date :
2017-02-05 01:05:56 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
time = Date.Now.ToString.Split(" ")(1)
Label1.Text$ = time
If i = 1 And time.Substring(0, time.Length - 3) = Label2.Text$ & ":" & Label4.Text$ And
time.Substring(time.Length - 2, 2) = "00" Then
Timer1.Stop()
My.Computer.Audio.Play(My.Resources.beep, AudioPlayMode.BackgroundLoop)
Me.WindowState = FormWindowState.Normal
Dim p As New Point
p.X = (Me.Width / 2) - (Label1.Width / 2)
p.Y = Label1.Top
If Not Label1.Text$ = vbNullString Then
Label1.Location = p
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label2.Text = TextBox1.Text
Label4.Text = TextBox2.Text + 1
If Button1.Text$ = "ENABLE" Then
Button1.Text$ = "DISABLE"
i = 1
Else
My.Computer.Audio.Stop()
TextBox1.Clear()
TextBox2.Clear()
Timer1.Start()
i = 0
Button1.Text$ = "ENABLE"
End If
If Label4.Text >= 60 Then
Label2.Text = Label2.Text + 1
Label4.Text = Label4.Text - 60
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer2.Start()
Dim Str = "6"
Label4.Text = Integer.Parse(Str).ToString("00")
End Sub
ผมลองใส่ไปแล้วแต่เป็นเหมือนเดิมเลยอะครับ ให้ Label4.Text +1 ไว้ด้วย มันไม่ออกเป็น03 อะครับ

|
 |
 |
 |
 |
Date :
2017-02-05 01:34:29 |
By :
mogkung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Dim str = Label4.Text
Label4.Text = Integer.Parse(str).ToString("00")
End Sub
ได้แล้วครับ ขอบคุณมากๆ

|
 |
 |
 |
 |
Date :
2017-02-05 01:51:06 |
By :
mogkung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
  
|
 |
 |
 |
 |
Date :
2017-02-05 07:13:17 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|