Leerlingen.com Forum

Leerlingen.com Forum (https://forum.leerlingen.com/vbb/index.php)
-   Computers & Internet (https://forum.leerlingen.com/vbb/forumdisplay.php?f=23)
-   -   Visual Basic (https://forum.leerlingen.com/vbb/showthread.php?t=64936)

Hellblazer 29 May 2009 18:41

Visual Basic
 
Iemand hier ervaring met Visual Basic (6)?
Moet namelijk voor school een programma scrijven: Galgje. Ik zou alleen niet weten hoe ik kan kijken of zo'n letter goed is en die laten verschijnen.

Alvast bedankt :d

Deegbal 30 May 2009 13:40

Ik heb geen idee, sorry kerel.


Google?

the_darkness 30 May 2009 13:42

gewoon standaard met If en Else werken.

Hellblazer 30 May 2009 13:51

Ik heb al vanalles gezocht op google ;) Kon niets vinden :(

En dat If Else, dat wilde ik ook doen maar ik weet niet hoe.
Kijk, je voert een woord in bijv woord. Als je dan een letter in voert moet hij het woord controleren en als een letter klopt moet ie die schrijven.
Maar ik zou niet weten hoe hij alleen die letter kan doen plaatsen en eventueel extra letters erbij xD

the_darkness 30 May 2009 13:55

gewoon met values?
gewoon een if/else met een waarde waar goed=1 en fout=0 en een >/<.
its not that hard.
voor woord totaal een gelijk aan commando gecombineerd met een And?

Hellblazer 30 May 2009 14:03

Ik heb nu dat als je niets invult of spatie dat ie foutmelding geeft. Als er nog geen woord is geeft ie foutmelding Bij meerde letters of fout woord geeft ie ook een foutmelding. Bij goed woord laat hij het woord zien.
Bij een letter moeten we van die vent for i = 1 to len(woord$) doen. En dan heel woord$ controleren op die goede letter. En dan moet(en) die letter(s) op de goede plaats komen te staan.
Het probleem is dan, hoe kan ik zorgen dat ie onthoudt waar dat ie een letter moet plaatsen of een _ (voor nog niet ingevuld). En hoe kan ik dan zorgen dat ie bestaande letters dan al laat staan.
Dat lijkt me iets meer dan alleen meer if, else, and, < en >.

the_darkness 30 May 2009 14:06

even denken...
visual basic werkt met code strings right?

Hellblazer 30 May 2009 14:06

Voor zover ik weet wel.

the_darkness 30 May 2009 14:10

probeer dit eens.
er zitten wel een aantal errors in, maar het geeft je een begin.

Private allPuzzles(1, 0) As String
Private allClues(0, 1) As String
Private LastPuzzle As Short
Dim btnTestNumButtons(26) As Button
Dim lbldisplayletters(0) As Label
Dim hangmanWord As String
Dim correctcounter As Integer = 0
Dim hangmanstage As String = "START"
Dim incorrect = False

Private Sub btnTestNumButtons_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Click
If sender.name = "" Then
For iIndex = 0 To hangmanWord.Length - 1
If hangmanWord.Substring(iIndex, 1) = sender.Text Then
lbldisplayletters(iIndex).Text = sender.Text
correctcounter += 1
incorrect = True
End If
Next iIndex

If incorrect = False Then
drawHangman()
End If

incorrect = False

sender.Enabled = False
sender.visible = False
If correctcounter = hangmanWord.Length Then
lblresult.Text = "YOU WIN"
lblGamesWon.Text = CInt(lblGamesWon.Text) + 1
lblGamesPlayed.Text = CInt(lblGamesPlayed.Text) + 1
disableconrols()
End If
End If

End Sub



Private Sub LoadGameData()

Dim puzzleno As Integer = 0
Dim outstream As New StreamReader(My.Application.Info.DirectoryPath & "\HMPuzz.dat")
Dim lineText As String
Dim puzzle() As String

Do Until outstream.EndOfStream
ReDim Preserve allPuzzles(1, puzzleno)
lineText = outstream.ReadLine()
If lineText <> Nothing Then
puzzle = lineText.Split(",")
allPuzzles(0, puzzleno) = puzzle(0)
allPuzzles(1, puzzleno) = puzzle(1)
puzzleno += 1
End If
Loop

outstream = New StreamReader(My.Application.Info.DirectoryPath & "\LastPuzz.dat")
Do Until outstream.EndOfStream
LastPuzzle = CShort(outstream.ReadLine())
Loop
outstream.Close()

Dim intFileNbr As Short
intFileNbr = FreeFile()
FileOpen(intFileNbr, (My.Application.Info.DirectoryPath & "\LastPuzz.dat"), OpenMode.Output)
If puzzleno - 1 < LastPuzzle Then
WriteLine(intFileNbr, 1)
FileClose(intFileNbr)
Else
WriteLine(intFileNbr, LastPuzzle + 1)
FileClose(intFileNbr)
End If



End Sub

Private Sub CreateButtonArray()
Dim shtIndex As Integer
Dim position As Integer = 30
Dim position2 As Integer = 30
For shtIndex = 0 To 25
btnTestNumButtons(shtIndex) = New System.Windows.Forms.Button()
With btnTestNumButtons(shtIndex)
.Text() = Chr(shtIndex + 65).ToString
.Size() = New Size(40, 40)
.FlatStyle() = FlatStyle.Popup
.BackColor() = System.Drawing.Color.Red
AddHandler .Click, AddressOf Me.btnTestNumButtons_Click
If shtIndex < 13 Then
.Location = New System.Drawing.Point(position, 200)
position += 44
Else
.Location = New System.Drawing.Point(position2, 245)
position2 += 44
End If
End With
Next
Me.Controls.AddRange(btnTestNumButtons)
End Sub

Private Sub newGame()
Invalidate()
LoadGameData()
lblresult.Text = ""
lblGamesPlayed.Visible = True
lblGamesWon.Visible = True
rb_played.Visible = True
rb_gameswon.Visible = True
CreateButtonArray()
hangmanWord = allPuzzles(0, LastPuzzle - 1)
CreateLabelArray(hangmanWord.Length)
End Sub

Private Sub CreateLabelArray(ByVal length As Integer)
Dim position As Integer = 30
Dim position2 As Integer = 30
ReDim lbldisplayletters(length - 1)

For i = 0 To length - 1
lbldisplayletters(i) = New System.Windows.Forms.Label()
With lbldisplayletters(i)
If hangmanWord.Substring(i, 1) = " " Then
correctcounter += 1
.Visible = False
Else
.Visible = True
End If
.Text() = ""
.TextAlign = ContentAlignment.MiddleCenter
.Size() = New Size(40, 40)
.FlatStyle() = FlatStyle.Popup
.BackColor() = System.Drawing.Color.White
If i < 13 Then
.Location = New System.Drawing.Point(position, 50)
position += 44
Else
.Location = New System.Drawing.Point(position2, 95)
position2 += 44
End If
End With
Next
Me.Controls.AddRange(lbldisplayletters)
End Sub

Private Sub frmHangman_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
newGame()
End Sub


Private Sub drawHangman()
Dim hangman As Graphics = pict_hangman.CreateGraphics()
Dim pen As New Pen(Color.Black)


Select Case hangmanstage
Case "START"
pict_hangman.Refresh()
hangman.DrawLine(pen, 50, 200, 150, 200)
hangman.DrawLine(pen, 140, 20, 140, 200)
hangman.DrawLine(pen, 80, 20, 140, 20)
hangman.DrawLine(pen, 80, 20, 80, 40)
hangman.DrawLine(pen, 120, 20, 140, 40)
hangmanstage = "DRAW HEAD"
Case "DRAW HEAD"
hangman.DrawEllipse(pen, 70, 40, 20, 20)
hangmanstage = "DRAW BODY"
Case "DRAW BODY"
hangman.DrawLine(pen, 80, 60, 80, 110)
hangmanstage = "DRAW RIGHT HAND"
Case "DRAW RIGHT HAND"
hangman.DrawLine(pen, 80, 65, 100, 85)
hangmanstage = "DRAW LEFT HAND"
Case "DRAW LEFT HAND"
hangman.DrawLine(pen, 80, 65, 60, 85)
hangmanstage = "DRAW RIGHT LEG"
Case "DRAW RIGHT LEG"
hangman.DrawLine(pen, 80, 110, 100, 130)
hangmanstage = "DRAW LEFT LEG"
Case "DRAW LEFT LEG"
hangman.DrawLine(pen, 80, 110, 60, 130)
hangmanstage = "START"
lblresult.Text = "YOU LOOSE"
rb_played.Text = CInt(rb_played.Text) + 1
disableconrols()
End Select


End Sub

Private Sub cmdNewGame_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdNewGame.Click
Dim ctl As Control

For Each ctl In Me.Controls
ctl.Enabled = True
If ctl.GetType().Name = "Label" Then

If Not ctl.Name = "lblplayed" And Not ctl.Name = "lblwon" And Not ctl.Name = "lblGamesPlayed" And Not ctl.Name = "lblGamesWon" Then
ctl.Text = ""
ctl.Visible = False
End If
End If
Next
newGame()
End Sub
Private Sub disableconrols()
Dim ctl As Control

For Each ctl In Me.Controls
ctl.Enabled = False
Next
cmdNewGame.Enabled = True
End Sub

Private Sub Button_exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_exit.Click
Me.Close()
End Sub

Hellblazer 30 May 2009 14:14

Ik zal is kijken wat ik er mee kan ;)

~DoOsJ~ 30 May 2009 14:57

visual basic zuigt.. wij moesten mastermind maken en raad het getal.. ik ben nog nooit zo boos geworden op een leraar als toen :{

Microshit 31 May 2009 12:14

En dat was met de n00b versie van Visual Basic (VBA)

OT, just fucking Google it

Hellblazer 1 June 2009 12:50

Citaat:

Origineel gepost door Microshit (Bericht 1410433)

Dat zei ik al, heb ik al gedaan maar kom niks fatsoenlijks tegen.

En wat td postte is ook niet goed, moet met de dingen die wij in de les heben gehad, en dat zijn die niet :no:

Dus ik zal zelf nog maar wat proberen.


Alle tijden zijn GMT +1. De tijd is nu 18:29.

Forum software: vBulletin 3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.