Code Snippets

  

Visual Basic Source Code


Welcome to Dream.In.Code
Become a VB Expert!

Join 149,620 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,912 people online right now. Registration is fast and FREE... Join Now!





Hangman

Simple hangman game, with gui.

Submitted By: m2s87
Actions:
Rating:
Views: 6,119

Language: Visual Basic

Last Modified: January 5, 2007
Instructions: Save the following code as alus.frm.

Snippet


  1. VERSION 5.00
  2. Begin VB.Form alus
  3.    Caption         =   "Poomine"
  4.    ClientHeight    =   3090
  5.    ClientLeft      =   60
  6.    ClientTop       =   450
  7.    ClientWidth     =   4680
  8.    BeginProperty Font
  9.       Name            =   "Arial"
  10.       Size            =   9.75
  11.       Charset         =   0
  12.       Weight          =   400
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    ScaleHeight     =   3090
  19.    ScaleWidth      =   4680
  20.    StartUpPosition =   3  'Windows Default
  21.    Begin VB.PictureBox Pilt
  22.       Appearance      =   0  'Flat
  23.       BackColor       =   &H80000005&
  24.       ForeColor       =   &H80000008&
  25.       Height          =   1575
  26.       Left            =   3120
  27.       ScaleHeight     =   1545
  28.       ScaleWidth      =   1425
  29.       TabIndex        =   36
  30.       Top             =   840
  31.       Width           =   1455
  32.       Begin VB.Line Line9
  33.          X1              =   840
  34.          X2              =   840
  35.          Y1              =   480
  36.          Y2              =   240
  37.       End
  38.       Begin VB.Line Line8
  39.          X1              =   840
  40.          X2              =   960
  41.          Y1              =   960
  42.          Y2              =   1080
  43.       End
  44.       Begin VB.Line Line7
  45.          X1              =   840
  46.          X2              =   960
  47.          Y1              =   720
  48.          Y2              =   840
  49.       End
  50.       Begin VB.Line Line6
  51.          X1              =   840
  52.          X2              =   720
  53.          Y1              =   720
  54.          Y2              =   840
  55.       End
  56.       Begin VB.Line Line5
  57.          X1              =   840
  58.          X2              =   720
  59.          Y1              =   960
  60.          Y2              =   1080
  61.       End
  62.       Begin VB.Line Line4
  63.          X1              =   840
  64.          X2              =   840
  65.          Y1              =   720
  66.          Y2              =   960
  67.       End
  68.       Begin VB.Shape Shape1
  69.          BackColor       =   &H80000000&
  70.          BorderColor     =   &H8000000C&
  71.          Height          =   255
  72.          Left            =   795
  73.          Shape           =   2  'Oval
  74.          Top             =   480
  75.          Width           =   255
  76.       End
  77.       Begin VB.Line Line1
  78.          BorderWidth     =   4
  79.          X1              =   240
  80.          X2              =   240
  81.          Y1              =   240
  82.          Y2              =   1320
  83.       End
  84.       Begin VB.Line Line2
  85.          BorderWidth     =   4
  86.          X1              =   960
  87.          X2              =   240
  88.          Y1              =   240
  89.          Y2              =   240
  90.       End
  91.    End
  92.    Begin VB.CommandButton Uus
  93.       Caption         =   "Uus"
  94.       Height          =   375
  95.       Left            =   3120
  96.       TabIndex        =   33
  97.       Top             =   2520
  98.       Width           =   1455
  99.    End
  100.    Begin VB.CommandButton nupp
  101.       Caption         =   "Y"
  102.       Height          =   375
  103.       Index           =   31
  104.       Left            =   2640
  105.       TabIndex        =   32
  106.       Top             =   2520
  107.       Width           =   375
  108.    End
  109.    Begin VB.CommandButton nupp
  110.       Caption         =   "X"
  111.       Height          =   375
  112.       Index           =   30
  113.       Left            =   2280
  114.       TabIndex        =   31
  115.       Top             =   2520
  116.       Width           =   375
  117.    End
  118.    Begin VB.CommandButton nupp
  119.       Caption         =   "Ü"
  120.       Height          =   375
  121.       Index           =   29
  122.       Left            =   1920
  123.       TabIndex        =   30
  124.       Top             =   2520
  125.       Width           =   375
  126.    End
  127.    Begin VB.CommandButton nupp
  128.       Caption         =   "Ö"
  129.       Height          =   375
  130.       Index           =   28
  131.       Left            =   1560
  132.       TabIndex        =   29
  133.       Top             =   2520
  134.       Width           =   375
  135.    End
  136.    Begin VB.CommandButton nupp
  137.       Caption         =   "Ä"
  138.       Height          =   375
  139.       Index           =   27
  140.       Left            =   1200
  141.       TabIndex        =   28
  142.       Top             =   2520
  143.       Width           =   375
  144.    End
  145.    Begin VB.CommandButton nupp
  146.       Caption         =   "Õ"
  147.       Height          =   375
  148.       Index           =   26
  149.       Left            =   840
  150.       TabIndex        =   27
  151.       Top             =   2520
  152.       Width           =   375
  153.    End
  154.    Begin VB.CommandButton nupp
  155.       Caption         =   "W"
  156.       Height          =   375
  157.       Index           =   25
  158.       Left            =   480
  159.       TabIndex        =   26
  160.       Top             =   2520
  161.       Width           =   375
  162.    End
  163.    Begin VB.CommandButton nupp
  164.       Caption         =   "V"
  165.       Height          =   375
  166.       Index           =   24
  167.       Left            =   120
  168.       TabIndex        =   25
  169.       Top             =   2520
  170.       Width           =   375
  171.    End
  172.    Begin VB.CommandButton nupp
  173.       Caption         =   "U"
  174.       Height          =   375
  175.       Index           =   23
  176.       Left            =   2640
  177.       TabIndex        =   24
  178.       Top             =   2160
  179.       Width           =   375
  180.    End
  181.    Begin VB.CommandButton nupp
  182.       Caption         =   "T"
  183.       Height          =   375
  184.       Index           =   22
  185.       Left            =   2280
  186.       TabIndex        =   23
  187.       Top             =   2160
  188.       Width           =   375
  189.    End
  190.    Begin VB.CommandButton nupp
  191.       Caption         =   "Ž"
  192.       Height          =   375
  193.       Index           =   21
  194.       Left            =   1920
  195.       TabIndex        =   22
  196.       Top             =   2160
  197.       Width           =   375
  198.    End
  199.    Begin VB.CommandButton nupp
  200.       Caption         =   "Z"
  201.       Height          =   375
  202.       Index           =   20
  203.       Left            =   1560
  204.       TabIndex        =   21
  205.       Top             =   2160
  206.       Width           =   375
  207.    End
  208.    Begin VB.CommandButton nupp
  209.       Caption         =   "Å "
  210.       Height          =   375
  211.       Index           =   19
  212.       Left            =   1200
  213.       TabIndex        =   20
  214.       Top             =   2160
  215.       Width           =   375
  216.    End
  217.    Begin VB.CommandButton nupp
  218.       Caption         =   "S"
  219.       Height          =   375
  220.       Index           =   18
  221.       Left            =   840
  222.       TabIndex        =   19
  223.       Top             =   2160
  224.       Width           =   375
  225.    End
  226.    Begin VB.CommandButton nupp
  227.       Caption         =   "R"
  228.       Height          =   375
  229.       Index           =   17
  230.       Left            =   480
  231.       TabIndex        =   18
  232.       Top             =   2160
  233.       Width           =   375
  234.    End
  235.    Begin VB.CommandButton nupp
  236.       Caption         =   "Q"
  237.       Height          =   375
  238.       Index           =   16
  239.       Left            =   120
  240.       TabIndex        =   17
  241.       Top             =   2160
  242.       Width           =   375
  243.    End
  244.    Begin VB.CommandButton nupp
  245.       Caption         =   "P"
  246.       Height          =   375
  247.       Index           =   15
  248.       Left            =   2640
  249.       TabIndex        =   16
  250.       Top             =   1800
  251.       Width           =   375
  252.    End
  253.    Begin VB.CommandButton nupp
  254.       Caption         =   "O"
  255.       Height          =   375
  256.       Index           =   14
  257.       Left            =   2280
  258.       TabIndex        =   15
  259.       Top             =   1800
  260.       Width           =   375
  261.    End
  262.    Begin VB.CommandButton nupp
  263.       Caption         =   "N"
  264.       Height          =   375
  265.       Index           =   13
  266.       Left            =   1920
  267.       TabIndex        =   14
  268.       Top             =   1800
  269.       Width           =   375
  270.    End
  271.    Begin VB.CommandButton nupp
  272.       Caption         =   "M"
  273.       Height          =   375
  274.       Index           =   12
  275.       Left            =   1560
  276.       TabIndex        =   13
  277.       Top             =   1800
  278.       Width           =   375
  279.    End
  280.    Begin VB.CommandButton nupp
  281.       Caption         =   "L"
  282.       Height          =   375
  283.       Index           =   11
  284.       Left            =   1200
  285.       TabIndex        =   12
  286.       Top             =   1800
  287.       Width           =   375
  288.    End
  289.    Begin VB.CommandButton nupp
  290.       Caption         =   "K"
  291.       Height          =   375
  292.       Index           =   10
  293.       Left            =   840
  294.       TabIndex        =   11
  295.       Top             =   1800
  296.       Width           =   375
  297.    End
  298.    Begin VB.CommandButton nupp
  299.       Caption         =   "J"
  300.       Height          =   375
  301.       Index           =   9
  302.       Left            =   480
  303.       TabIndex        =   10
  304.       Top             =   1800
  305.       Width           =   375
  306.    End
  307.    Begin VB.CommandButton nupp
  308.       Caption         =   "I"
  309.       Height          =   375
  310.       Index           =   8
  311.       Left            =   120
  312.       TabIndex        =   9
  313.       Top             =   1800
  314.       Width           =   375
  315.    End
  316.    Begin VB.CommandButton nupp
  317.       Caption         =   "H"
  318.       Height          =   375
  319.       Index           =   7
  320.       Left            =   2640
  321.       TabIndex        =   8
  322.       Top             =   1440
  323.       Width           =   375
  324.    End
  325.    Begin VB.CommandButton nupp
  326.       Caption         =   "G"
  327.       Height          =   375
  328.       Index           =   6
  329.       Left            =   2280
  330.       TabIndex        =   7
  331.       Top             =   1440
  332.       Width           =   375
  333.    End
  334.    Begin VB.CommandButton nupp
  335.       Caption         =   "F"
  336.       Height          =   375
  337.       Index           =   5
  338.       Left            =   1920
  339.       TabIndex        =   6
  340.       Top             =   1440
  341.       Width           =   375
  342.    End
  343.    Begin VB.CommandButton nupp
  344.       Caption         =   "E"
  345.       Height          =   375
  346.       Index           =   4
  347.       Left            =   1560
  348.       TabIndex        =   5
  349.       Top             =   1440
  350.       Width           =   375
  351.    End
  352.    Begin VB.CommandButton nupp
  353.       Caption         =   "D"
  354.       Height          =   375
  355.       Index           =   3
  356.       Left            =   1200
  357.       TabIndex        =   4
  358.       Top             =   1440
  359.       Width           =   375
  360.    End
  361.    Begin VB.CommandButton nupp
  362.       Caption         =   "C"
  363.       Height          =   375
  364.       Index           =   2
  365.       Left            =   840
  366.       TabIndex        =   3
  367.       Top             =   1440
  368.       Width           =   375
  369.    End
  370.    Begin VB.CommandButton nupp
  371.       Caption         =   "B"
  372.       Height          =   375
  373.       Index           =   1
  374.       Left            =   480
  375.       TabIndex        =   2
  376.       Top             =   1440
  377.       Width           =   375
  378.    End
  379.    Begin VB.CommandButton nupp
  380.       Caption         =   "A"
  381.       Height          =   375
  382.       Index           =   0
  383.       Left            =   120
  384.       TabIndex        =   1
  385.       Top             =   1440
  386.       Width           =   375
  387.    End
  388.    Begin VB.Label Kaotand
  389.       Caption         =   "Kaotus:"
  390.       Height          =   255
  391.       Left            =   120
  392.       TabIndex        =   35
  393.       Top             =   1080
  394.       Width           =   2895
  395.    End
  396.    Begin VB.Label Punkte
  397.       Caption         =   "Punkte:"
  398.       Height          =   255
  399.       Left            =   120
  400.       TabIndex        =   34
  401.       Top             =   840
  402.       Width           =   2895
  403.    End
  404.    Begin VB.Label Tekst
  405.       Caption         =   "Poomine"
  406.       BeginProperty Font
  407.          Name            =   "Tahoma"
  408.          Size            =   24
  409.          Charset         =   0
  410.          Weight          =   700
  411.          Underline       =   0   'False
  412.          Italic          =   0   'False
  413.          Strikethrough   =   0   'False
  414.       EndProperty
  415.       Height          =   615
  416.       Left            =   120
  417.       TabIndex        =   0
  418.       Top             =   120
  419.       Width           =   4455
  420.    End
  421. End
  422. Attribute VB_Name = "alus"
  423. Attribute VB_GlobalNameSpace = False
  424. Attribute VB_Creatable = False
  425. Attribute VB_PredeclaredId = True
  426. Attribute VB_Exposed = False
  427. Dim s6na$, t2hestik$, kord%, kaotus%, pt%
  428. Private Sub Uus_Click(): kaotus = kaotus + 1: pt = pt - 10: Call Loo_Uus: End Sub
  429. Private Sub Form_Load()
  430.     Call Loo_Uus
  431. End Sub
  432. Private Sub poo()
  433.     Select Case kord
  434.         Case 2: Me.Line2.Visible = True
  435.         Case 3: Me.Shape1.Visible = True
  436.         Case 4: Me.Line4.Visible = True
  437.         Case 5: Me.Line5.Visible = True
  438.         Case 6: Me.Line6.Visible = True
  439.         Case 7: Me.Line7.Visible = True
  440.         Case 8: Me.Line8.Visible = True
  441.         Case 9: Me.Line9.Visible = True
  442.     End Select
  443. End Sub
  444. Private Sub nupp_Click(Index As Integer)
  445.     Me.Pilt.SetFocus
  446.     Me.nupp(Index).Enabled = False
  447.     k = Split(t2hestik, ",")
  448.     k(Index) = "|"
  449.     t2hestik = Join(k, ",")
  450.     saal = Me.Tekst.Caption
  451.     Me.Tekst.Caption = algolek()
  452.    
  453.     If s6na = Me.Tekst.Caption Then
  454.         pt = pt + (9 - kord) * 5
  455.         Call Loo_Uus
  456.     Else
  457.         If saal = Me.Tekst.Caption Then kord = kord + 1
  458.         If kord = 9 Then Call l2bi
  459.         Me.Caption = "Poomine ( " & kord & " / 9 )"
  460.         Call poo
  461.     End If
  462. End Sub
  463. Sub l2bi()
  464.     For i = 0 To 31
  465.         Me.nupp(i).Enabled = False
  466.     Next i
  467. End Sub
  468. Sub Loo_Uus()
  469.     t2hestik = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P," _
  470.              & "Q,R,S,Ã… ,Z,Ž,T,U,V,W,Ć?,Ć?,Ć?,Ć?,X,Y"
  471.              
  472.     For i = 0 To 31
  473.         Me.nupp(i).Enabled = True
  474.     Next i
  475.    
  476.     kord = 1
  477.     s6na = loo_uus_s6na
  478.     Me.Line2.Visible = False:    Me.Shape1.Visible = False
  479.     Me.Line4.Visible = False:    Me.Line5.Visible = False
  480.     Me.Line6.Visible = False:    Me.Line7.Visible = False
  481.     Me.Line8.Visible = False:    Me.Line9.Visible = False
  482.     Me.Punkte.Caption = "Punkte: " & pt
  483.     Me.Kaotand.Caption = "Kaotus: " & kaotus
  484.     Me.Tekst.Caption = algolek()
  485.     Me.Caption = "Poomine ( " & kord & " / 9 )"
  486. End Sub
  487. Function algolek()
  488.     z = Split(t2hestik, ",")
  489.     x = s6na
  490.    
  491.     For i = 0 To UBound(z)
  492.         x = vaheta(x, z(i))
  493.     Next i
  494.    
  495.     algolek = Left(s6na, 1) & Mid(x, 2, Len(x) - 1)
  496. End Function
  497. Function vaheta(s6na, t2ht)
  498.     vaheta = Replace(s6na, t2ht, "_")
  499. End Function
  500. Private Function loo_uus_s6na() As String
  501.     Randomize
  502.     'add the word you want to guess here
  503.     s6nad = "bulb,onion,potato,beet,fish,chicken,computer"
  504.     ms6na = Split(s6nad, ",")
  505.  
  506.     loo_uus_s6na = StrConv(ms6na(Rnd() * (UBound(ms6na) - 1)), vbUpperCase)
  507. End Function
  508.  

Copy & Paste