Hello,
I'm a student at a university in Leeuwarden(Netherlands) and just started with programming.
I'm stuck at my last assignment and i thought maybe you could help me.
I program in vb 2010 express.
I have to program the game hangman. I got the following problem:
-Can't manage to replace the * by the correct letter. (textbox2 have to replace '*' to the correct letter)
I googled and found some information about substrings. I don't know how to use a substring. I tried but i didn't solved my problem.
Code:
Public Class Form1
Dim Woord As String
Dim Gekozenwoord As String
Dim Keuzewoord(10) As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Woord = ""
Call Keuzewoorden()
Randomize()
Gekozenwoord = Keuzewoord((CInt(Int((10 * Rnd()) + 1))))
Call Sterreninvoegen()
TextBox2.Text = Woord
ListBox1.Items.Clear()
TextBox1.Enabled = True
TextBox1.Select()
Button1.Text = "Herstart"
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Hide()
End Sub
Private Sub Keuzewoorden()
Keuzewoord(1) = "Kat"
Keuzewoord(2) = "Hond"
Keuzewoord(3) = "Fietsen"
Keuzewoord(4) = "Hokken"
Keuzewoord(5) = "Nietjes"
Keuzewoord(6) = "Penceel"
Keuzewoord(7) = "Autoband"
Keuzewoord(8) = "Kussens"
Keuzewoord(9) = "Aaien"
Keuzewoord(10) = "Mobiel"
End Sub
Private Sub Sterreninvoegen()
Dim IntTeller As Integer
Dim IntWoordLgth As Integer
IntWoordLgth = Gekozenwoord.Length
Do While IntTeller < IntWoordLgth
IntTeller += 1
Woord = Woord + "*"
Loop
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Letter As String
Letter = TextBox1.Text
ListBox1.Items.Add(Letter)
If Letter Like "*[1-1000000000000000000000000000]" Then
MsgBox("Je kan alleen letters invullen")
ElseIf Letter.Length > 1 Then
MsgBox("Je mag maar 1 letter invoeren")
ElseIf Letter = " " Then
MsgBox("Voer een letter in, geen invoer ontvangen")
End If
If Letter = Woord.Substring("1") Then
TextBox2.Show()
End If
End Sub
End Class
Greetings,
Raymon
I'm a student at a university in Leeuwarden(Netherlands) and just started with programming.
I'm stuck at my last assignment and i thought maybe you could help me.
I program in vb 2010 express.
I have to program the game hangman. I got the following problem:
-Can't manage to replace the * by the correct letter. (textbox2 have to replace '*' to the correct letter)
I googled and found some information about substrings. I don't know how to use a substring. I tried but i didn't solved my problem.
Code:
Public Class Form1
Dim Woord As String
Dim Gekozenwoord As String
Dim Keuzewoord(10) As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Woord = ""
Call Keuzewoorden()
Randomize()
Gekozenwoord = Keuzewoord((CInt(Int((10 * Rnd()) + 1))))
Call Sterreninvoegen()
TextBox2.Text = Woord
ListBox1.Items.Clear()
TextBox1.Enabled = True
TextBox1.Select()
Button1.Text = "Herstart"
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Hide()
End Sub
Private Sub Keuzewoorden()
Keuzewoord(1) = "Kat"
Keuzewoord(2) = "Hond"
Keuzewoord(3) = "Fietsen"
Keuzewoord(4) = "Hokken"
Keuzewoord(5) = "Nietjes"
Keuzewoord(6) = "Penceel"
Keuzewoord(7) = "Autoband"
Keuzewoord(8) = "Kussens"
Keuzewoord(9) = "Aaien"
Keuzewoord(10) = "Mobiel"
End Sub
Private Sub Sterreninvoegen()
Dim IntTeller As Integer
Dim IntWoordLgth As Integer
IntWoordLgth = Gekozenwoord.Length
Do While IntTeller < IntWoordLgth
IntTeller += 1
Woord = Woord + "*"
Loop
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Letter As String
Letter = TextBox1.Text
ListBox1.Items.Add(Letter)
If Letter Like "*[1-1000000000000000000000000000]" Then
MsgBox("Je kan alleen letters invullen")
ElseIf Letter.Length > 1 Then
MsgBox("Je mag maar 1 letter invoeren")
ElseIf Letter = " " Then
MsgBox("Voer een letter in, geen invoer ontvangen")
End If
If Letter = Woord.Substring("1") Then
TextBox2.Show()
End If
End Sub
End Class
Greetings,
Raymon






