Solved

changing images for each wrong guess in hangman

Posted on 2006-11-04
14
245 Views
Last Modified: 2011-09-20
here's the code I have to far......I can only change the image once: (


  Dim m As Image

        For Each m In ImageList1.Images



            If found = False Then


                btn.Visible = False
                Label2.Image = ImageList1.Images(1)

         


            End If





        Next m

shouldn't this code cycle to the next image is another incorrect guess is entered?
0
Comment
Question by:sethRnda
  • 7
  • 7
14 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17874151
what programming language are you using? looks like vb?

without a bit more of code I doubt we can tell you anything, but I guess (wildly) that you run this code when a choice has been made, but this will only set 1 image, always the same one.
you will have to control which of the images you have already displayed...

also, you do                
Label2.Image = ImageList1.Images(1)
and it should rather be like this:
Label2.Image = m

or probably better:
have a variable (n) that counts the number of wrong guesses, and simply get that image, without any loop:

Label2.Image = ImageList1.Images(n)




0
 

Author Comment

by:sethRnda
ID: 17874364
I've tried this

dim guess as integer

for img = 0 to val(strWord.length +2)

if found = false then

btn.visible = false
label2.image = imagelist1.images(img)

next img

but it doesn't cycle throught the imagelist

and yes I'm using vb.net
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17874372
why do you cycle through the list?
you "know" exactly which image you want to display...

simply do this line:
label2.image = imagelist1.images(val(strWord.length) +2)
0
 

Author Comment

by:sethRnda
ID: 17874446
 Dim m As Integer
        m = 1





        If found = False Then


            btn.Visible = False
            Label2.Image = ImageList1.Images(m)


            m = m + 1


        End If
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17874455
yes, that looks good...
0
 

Author Comment

by:sethRnda
ID: 17874466
it's not working though : (
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17874468
the variable m needs to be a member of the form, not the function you are calling to change the image...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:sethRnda
ID: 17874474
so i should declare it in the form load sub?
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 17874478
no, not in the form_sub, but on the form class level:

Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim m As Integer = 0

    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
        ....
    End Sub

    ...

End Class
0
 

Author Comment

by:sethRnda
ID: 17874485
thanks, it works, but could you explain why it needs to be declared there?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17874503
>thanks, it works, but could you explain why it needs to be declared there?
if you put it into the function, it will be "erased" from memory when the function is completed.
you can verify that from adding a watch on the variable, and see that it cannot be watched when you go out of the function.
also, when you get back into the function, you will notice that the variable gets recreated and reinitialized to null value ...

putting it at form level will prevent the variable to get out of scope, so keep the value between the function calls..
0
 

Author Comment

by:sethRnda
ID: 17874507
that makes sense...thankyou very much angel: )
0
 

Author Comment

by:sethRnda
ID: 17874943
hey angel...have you ever seen a function that would completely refresh a form....?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17875656
well, the function might, believe it or not, be named Refresh() ...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exe program is not a valid Win 32 application 15 103
array11 challenge 16 59
topping2 challenge 13 80
parse convert xml feed to text (python) 2 66
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now