|
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
กระทู้ #3321 [Vb] (จาก IP: 118.172.109.17)
vb6 รบกวนดูโค้ดทอยลูกเต๋า ทีค่ะ
จากโค้ดนี้อ่ะค่ะ มันทำได้แค่สุ่มเลขสูงต่ำค่ะอยากใส่แบบค่าเงินได้ด้วยอะค่ะ เริ่มเงินให้100เล่นตาละ10เงินหมดจะออกจากเกมอะค่ะ
Private Sub Form1_Load() End Sub Option Explicit Dim simbol As Integer
Private Sub Command1_Click() If Option1.Value = False And Option2.Value = False And Option3.Value = False Then MsgBox "กรุณาเลือก สูง กลาง ต่ำ ", vbInformation End If Randomize Timer1.Enabled = True Command1.Enabled = False Command2.Enabled = True Do While Timer1.Enabled DoEvents Timer1_Timer Loop End Sub
Private Sub Command2_Click() Timer1.Enabled = False Command1.Enabled = True Command2.Enabled = False End Sub
Private Sub Command3_Click() End End Sub
Private Sub Form_Load() Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2 Timer1.Interval = 1000 Timer1.Enabled = False Command1.Enabled = True Command2.Enabled = False End Sub
Private Sub Timer1_Timer() Label1 = Int(Rnd() * 6) + 1 Label2 = Int(Rnd() * 6) + 1 Label3 = Int(Rnd() * 6) + 1 Text1.Text = Int(Label1) + Int(Label2) + Int(Label3) Select Case True Case Option1.Value = True If Int(Text1.Text) > 11 Then Text2.Text = "ถูก" Else Text2.Text = "ผิด" End If Case Option2.Value = True If Int(Text1.Text) = 11 Then Text2.Text = "ถูก" Else Text2.Text = "ผิด" End If Case Option3.Value = True If Int(Text1.Text) < 11 Then Text2.Text = "ถูก" Else Text2.Text = "ผิด" End If End Select End Sub
|
จากคุณ
:
aom / aom_hookang@hotmail.com [2012-07-09 19:24:22]
|
|
ความคิดเห็น #28651 (จาก IP: 101.108.25.138)
เอาหลักการไปศึกษาเองดีกว่า ให้คนอื่นเขียนให้มันได้งานส่ง แต่มันไม่ได้คิด เริ่ม 1.ศึกษากระบวนการของโค้ดที่ได้มา ว่าแต่ละบรรทัดทำเพื่ออะไร มีลำดับการทำงานจากไหนไปไหน และทำอย่างไร 2.ประกาศตัวแปรเก็บเงิน ไว้ 1 ตัว (ควรจะเป็น ตัวแปรจำนวนเต็ม) 3.หาตำแหน่งที่จะวางโค้ดเข้าไปว่า เล่นชนะเพิ่มเงิน เล่นแพ้ลบเงิน เหลือเงินเท่าไหร่อาจนำไปเข้าเงื่อนไขอีกว่าจะจบเกมส์เลยหรือเปล่า |
จากคุณ
:
การเขียนโปรแกรมเป็นทักษะถ้าไม่ขยันก็ไม่เป็น [2012-07-10 00:47:21]
|
|
ความคิดเห็น #28652 (จาก IP: 118.172.109.17)
ลองทำแล้วมันได้แค่นี้ จิงๆ |
จากคุณ
:
aom / aom_hookang@hotmail.com [2012-07-10 03:34:56]
|
|
ความคิดเห็น #28653 (จาก IP: 101.108.6.211)
ถ้าโค้ดด้านบนคุณเขียนเองจริงๆ การที่เพิ่มตัวแปรและทำเพิ่มมันง่ายๆมากๆครับ |
จากคุณ
:
การเขียนโปรแกรมเป็นทักษะถ้าไม่ขยันก็ไม่เป็น [2012-07-10 21:34:01]
|
|
ความคิดเห็น #28654 (จาก IP: 223.204.12.188)
นำโค้ดไปวางใน Notepad และบันทึกเป็น นามสกุลเป็น .FRM
VERSION 5.00 Begin VB.Form Form1 BorderStyle = 1 'Fixed Single Caption = "Form1" ClientHeight = 2745 ClientLeft = 45 ClientTop = 330 ClientWidth = 5970 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 2745 ScaleWidth = 5970 StartUpPosition = 3 'Windows Default Begin VB.Frame Frame3 Caption = "Frame3" Height = 2535 Left = 3480 TabIndex = 19 Top = 120 Width = 2415 End Begin VB.TextBox Text4 Height = 285 Left = 2520 TabIndex = 18 Text = "Text4" Top = 2250 Width = 855 End Begin VB.Frame Frame2 Caption = "เต็งเลข" Height = 1815 Left = 2520 TabIndex = 11 Top = 120 Width = 855 Begin VB.OptionButton Teng6 Caption = "6" Height = 255 Left = 120 TabIndex = 17 Top = 1440 Width = 615 End Begin VB.OptionButton Teng5 Caption = "5" Height = 255 Left = 120 TabIndex = 16 Top = 1200 Width = 615 End Begin VB.OptionButton Teng4 Caption = "4" Height = 255 Left = 120 TabIndex = 15 Top = 960 Width = 615 End Begin VB.OptionButton Teng3 Caption = "3" Height = 255 Left = 120 TabIndex = 14 Top = 720 Width = 615 End Begin VB.OptionButton Teng2 Caption = "2" Height = 255 Left = 120 TabIndex = 13 Top = 480 Width = 615 End Begin VB.OptionButton Teng1 Caption = "1" Height = 255 Left = 120 TabIndex = 12 Top = 240 Width = 615 End End Begin VB.Frame Frame1 Caption = "แทง สูง/ต่ำ" Height = 1095 Left = 120 TabIndex = 8 Top = 120 Width = 1335 Begin VB.OptionButton Option1 Caption = "สูง" Height = 375 Left = 120 TabIndex = 10 Top = 240 Width = 975 End Begin VB.OptionButton Option2 Caption = "ต่ำ" Height = 375 Left = 120 TabIndex = 9 Top = 600 Width = 975 End End Begin VB.TextBox Text3 Height = 285 Left = 2520 TabIndex = 4 Text = "Text3" Top = 1920 Width = 855 End Begin VB.TextBox Text2 BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 420 Left = 1560 TabIndex = 3 Text = "Text2" Top = 240 Width = 855 End Begin VB.TextBox Text1 Height = 375 Left = 1560 TabIndex = 2 Text = "Text1" Top = 720 Width = 855 End Begin VB.CommandButton Command2 Caption = "เปิด" BeginProperty Font Name = "MS Sans Serif" Size = 14.25 Charset = 222 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 1080 TabIndex = 1 Top = 1920 Width = 975 End Begin VB.CommandButton Command1 Caption = "ทอย" BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 222 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 120 TabIndex = 0 Top = 1920 Width = 975 End Begin VB.Timer Timer1 Left = 2040 Top = 2160 End Begin VB.Label Label3 Alignment = 2 'Center BorderStyle = 1 'Fixed Single Caption = "X" BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 222 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 1560 TabIndex = 7 Top = 1320 Width = 615 End Begin VB.Label Label2 Alignment = 2 'Center BorderStyle = 1 'Fixed Single Caption = "X" BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 222 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 840 TabIndex = 6 Top = 1320 Width = 615 End Begin VB.Label Label1 Alignment = 2 'Center BorderStyle = 1 'Fixed Single Caption = "X" BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 222 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 120 TabIndex = 5 Top = 1320 Width = 615 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False
Private Sub Form1_Load() End Sub Option Explicit Dim simbol As Integer
Private Sub Command1_Click() If Option1.Value = False And Option2.Value = False Then MsgBox "กรุณาเลือก สูง ต่ำ ", vbInformation End If Randomize Timer1.Enabled = True Command1.Enabled = False Command2.Enabled = True Do While Timer1.Enabled DoEvents Timer1_Timer Loop End Sub
Private Sub Command2_Click() Timer1.Enabled = False Command1.Enabled = True Command2.Enabled = False Select Case True Case Option1.Value = True If Int(Text1.Text) >= 11 Then Text2.Text = "ถูก" Else Text2.Text = "ผิด" End If Case Option2.Value = True If Int(Text1.Text) < 11 Then Text2.Text = "ถูก" Else Text2.Text = "ผิด" End If End Select Select Case True Case Teng1.Value = True Text3.Text = IIf(Label1.Caption = 1, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 1, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 1, 1, 0) Case Teng2.Value = True Text3.Text = IIf(Label1.Caption = 2, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 2, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 2, 1, 0) Case Teng3.Value = True Text3.Text = IIf(Label1.Caption = 3, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 3, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 3, 1, 0) Case Teng4.Value = True Text3.Text = IIf(Label1.Caption = 4, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 4, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 4, 1, 0) Case Teng5.Value = True Text3.Text = IIf(Label1.Caption = 5, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 5, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 5, 1, 0) Case Teng6.Value = True Text3.Text = IIf(Label1.Caption = 6, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 6, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 6, 1, 0) End Select If Text3.Text = 0 Then Text4.Text = Text4.Text - 10 If Text4.Text <= 0 Then MsgBox "Game Over": End Else Text4.Text = Text4.Text + (Text3.Text * 10) MsgBox "เต็งถูก" End If End Sub
Private Sub Command3_Click() End End Sub
Private Sub Form_Load() Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2 Timer1.Interval = 1000 Timer1.Enabled = False Command1.Enabled = True Command2.Enabled = False Text3.Text = 0 Text4.Text = 100 Option1.Value = True Teng1.Value = True End Sub
Private Sub Timer1_Timer() Label1.Caption = Int(Rnd() * 6) + 1 Label2.Caption = Int(Rnd() * 6) + 1 Label3.Caption = Int(Rnd() * 6) + 1 Text1.Text = Int(Label1) + Int(Label2) + Int(Label3) End Sub |
จากคุณ
:
แคทอาย / patomchet@hotmail.com [2012-07-13 13:16:03]
|
|
ความคิดเห็น #28655 (จาก IP: 223.204.12.188)
เอาใหม่...ของน้อง...ขอบอกว่า...เขียนโปรแกรม แบบเอาตัวแปร...ใส่ไว้ในโค้ด...เช่นตัวถ่วงเวลา ซึ่งกำหนดผ่านโค้ด...ทำให้โปรแกรมของพี่ทำงาน แบบตัวอย่างไม่ได้...และใส่ Loop ให้ Timer อีก...ซึ่งมันไม่ต้องใส่...อ่ะ...เอาไปใหม่...
คัดลอกลง Notepad และบันทึกในนามสกุล .FRM
VERSION 5.00 Begin VB.Form Form1 BorderStyle = 1 'Fixed Single Caption = "Form1" ClientHeight = 2745 ClientLeft = 45 ClientTop = 330 ClientWidth = 5970 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 2745 ScaleWidth = 5970 StartUpPosition = 3 'Windows Default Begin VB.Frame Frame3 Caption = "Frame3" Height = 2535 Left = 3480 TabIndex = 19 Top = 120 Width = 2415 End Begin VB.TextBox Text4 Height = 285 Left = 2520 TabIndex = 18 Text = "Text4" Top = 2250 Width = 855 End Begin VB.Frame Frame2 Caption = "เต็งเลข" Height = 1815 Left = 2520 TabIndex = 11 Top = 120 Width = 855 Begin VB.OptionButton Teng6 Caption = "6" Height = 255 Left = 120 TabIndex = 17 Top = 1440 Width = 615 End Begin VB.OptionButton Teng5 Caption = "5" Height = 255 Left = 120 TabIndex = 16 Top = 1200 Width = 615 End Begin VB.OptionButton Teng4 Caption = "4" Height = 255 Left = 120 TabIndex = 15 Top = 960 Width = 615 End Begin VB.OptionButton Teng3 Caption = "3" Height = 255 Left = 120 TabIndex = 14 Top = 720 Width = 615 End Begin VB.OptionButton Teng2 Caption = "2" Height = 255 Left = 120 TabIndex = 13 Top = 480 Width = 615 End Begin VB.OptionButton Teng1 Caption = "1" Height = 255 Left = 120 TabIndex = 12 Top = 240 Width = 615 End End Begin VB.Frame Frame1 Caption = "แทง สูง/ต่ำ" Height = 1095 Left = 120 TabIndex = 8 Top = 120 Width = 1335 Begin VB.OptionButton Option1 Caption = "สูง" Height = 375 Left = 120 TabIndex = 10 Top = 240 Width = 975 End Begin VB.OptionButton Option2 Caption = "ต่ำ" Height = 375 Left = 120 TabIndex = 9 Top = 600 Width = 975 End End Begin VB.TextBox Text3 Height = 285 Left = 2520 TabIndex = 4 Text = "Text3" Top = 1920 Width = 855 End Begin VB.TextBox Text2 BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 222 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 420 Left = 1560 TabIndex = 3 Text = "Text2" Top = 240 Width = 855 End Begin VB.TextBox Text1 Height = 375 Left = 1560 TabIndex = 2 Text = "Text1" Top = 720 Width = 855 End Begin VB.CommandButton Command2 Caption = "เปิด" BeginProperty Font Name = "MS Sans Serif" Size = 14.25 Charset = 222 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 1080 TabIndex = 1 Top = 1920 Width = 975 End Begin VB.CommandButton Command1 Caption = "ทอย" BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 222 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 615 Left = 120 TabIndex = 0 Top = 1920 Width = 975 End Begin VB.Timer Timer1 Interval = 10 Left = 2040 Top = 2040 End Begin VB.Label Label3 Alignment = 2 'Center BorderStyle = 1 'Fixed Single Caption = "0" BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 222 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 1560 TabIndex = 7 Top = 1320 Width = 615 End Begin VB.Label Label2 Alignment = 2 'Center BorderStyle = 1 'Fixed Single Caption = "0" BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 222 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 840 TabIndex = 6 Top = 1320 Width = 615 End Begin VB.Label Label1 Alignment = 2 'Center BorderStyle = 1 'Fixed Single Caption = "0" BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 222 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 120 TabIndex = 5 Top = 1320 Width = 615 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False
Private Sub Form1_Load() End Sub Option Explicit Dim simbol As Integer
Private Sub Command1_Click() If Option1.Value = False And Option2.Value = False Then MsgBox "กรุณาเลือก สูง ต่ำ ", vbInformation End If Randomize Timer1.Enabled = True Command1.Enabled = False Command2.Enabled = True End Sub
Private Sub Command2_Click() Timer1.Enabled = False Command1.Enabled = True Command2.Enabled = False Text3.Text = 0 Select Case True Case Teng1.Value = True Text3.Text = IIf(Label1.Caption = 1, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 1, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 1, 1, 0) Case Teng2.Value = True Text3.Text = IIf(Label1.Caption = 2, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 2, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 2, 1, 0) Case Teng3.Value = True Text3.Text = IIf(Label1.Caption = 3, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 3, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 3, 1, 0) Case Teng4.Value = True Text3.Text = IIf(Label1.Caption = 4, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 4, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 4, 1, 0) Case Teng5.Value = True Text3.Text = IIf(Label1.Caption = 5, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 5, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 5, 1, 0) Case Teng6.Value = True Text3.Text = IIf(Label1.Caption = 6, 1, 0) Text3.Text = Text3.Text + IIf(Label2.Caption = 6, 1, 0) Text3.Text = Text3.Text + IIf(Label3.Caption = 6, 1, 0) End Select If Text3.Text = 0 Then Text4.Text = Text4.Text - 10 If Text4.Text <= 0 Then MsgBox "Game Over": End Else Text4.Text = Text4.Text + (Text3.Text * 10) MsgBox "เต็งถูก" End If End Sub
Private Sub Command3_Click() End End Sub
Private Sub Form_Load() Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2 Timer1.Enabled = False Command1.Enabled = True Command2.Enabled = False Text4.Text = 100 Option1.Value = True Teng1.Value = True End Sub
Private Sub Timer1_Timer() Label1.Caption = Trim(Str(Int(Rnd() * 6) + 1)) Label2.Caption = Trim(Str(Int(Rnd() * 6) + 1)) Label3.Caption = Trim(Str(Int(Rnd() * 6) + 1)) Text1.Text = Int(Label1) + Int(Label2) + Int(Label3) Select Case True Case Option1.Value = True If Int(Text1.Text) >= 11 Then Text2.Text = "ถูก" Else Text2.Text = "ผิด" End If Case Option2.Value = True If Int(Text1.Text) < 11 Then Text2.Text = "ถูก" Else Text2.Text = "ผิด" End If End Select
End Sub |
จากคุณ
:
แคทอาย / patomchet@hotmail.com [2012-07-13 13:56:38]
|
|
ความคิดเห็น #28656 (จาก IP: 223.204.12.188)
555 นึก...ว่า...เป็นที่ Timer ที่แท้.... มันไม่ง่ายอย่างที่คิด แฮะ....เงื่อนไขการ เต็ง เปลี่ยนคำสั่ง command2 เป็น ตัวนี้... อัลกอลิทึม....ยากกว่าที่คิด แฮะ....
Private Sub Command2_Click() Dim Teng As Integer Timer1.Enabled = False Command1.Enabled = True Command2.Enabled = False Select Case True Case Teng1.Value = True Teng = 1 Case Teng2.Value = True Teng = 2 Case Teng3.Value = True Teng = 3 Case Teng4.Value = True Teng = 4 Case Teng5.Value = True Teng = 5 Case Teng6.Value = True Teng = 6 End Select
If Label1.Caption = Teng And Label1.Caption = Label2.Caption And _ Label2.Caption = Label3.Caption Then Text3.Text = 3 ElseIf Label1.Caption = Teng And Label2.Caption = Teng Or _ Label1.Caption = Teng And Label3.Caption = Teng Or _ Label2.Caption = Teng And Label3.Caption = Teng Then Text3.Text = 2 ElseIf Label1.Caption = Teng Or Label2.Caption = Teng Or Label3.Caption = Teng Then Text3.Text = 1 Else Text3.Text = 0 End If
If Text3.Text = 0 Then Text4.Text = Text4.Text - 10 If Text4.Text <= 0 Then MsgBox "Game Over": End Else Text4.Text = Text4.Text + (Text3.Text * 10) MsgBox "àµçÙ¡" End If End Sub |
จากคุณ
:
แคทอาย / patomchet@hotmail.com [2012-07-13 14:23:59]
|
|
ความคิดเห็น #28657 (จาก IP: 118.172.98.89)
ขอบคุณทุกกระทู้ที่มาตอบให้มากมายค่ะ |
จากคุณ
:
aom / aom_hookang@hotmail.com [2012-07-13 17:19:40]
|
|
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
|
|