954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VB 2008 help in displaying images

Public Class Form1

Dim coin As New Random
Dim heads, tails, outcome As Integer
Dim totals As Double

Dim frequency As Decimal

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

heads = 0
tails = 0
totals = 0

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


If Flip() Then
heads = heads + 1
THeads.Text = heads
Else
tails = tails + 1
Ttails.Text = tails
End If

totals = totals + 1

Ttotal.Text = totals

End Sub

Function Flip() As Boolean
Return CBool(coin.Next(0, 2))

End Function

End Class


I have two images in my Resource file - coin1.jpg and coin2.jpg

one for heads and one for tails.

How do make them display along with the results of the toss

when heads comes up a head appears

when tails comes up a tail appears.

HELP!!!

rickbill
Newbie Poster
8 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Add this to your loop.

Imports System.Drawing

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Flip() Then
            heads = heads + 1
            THeads.Text = heads
            PictureBox1.Image = New Bitmap("c:\coin1.jpg")
        Else
            tails = tails + 1
            Ttails.Text = tails
            PictureBox1.Image = New Bitmap("c:\coin2.jpg")
        End If

    End Sub
End Class
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

Public Class Form1

Dim coin As New Random
Dim heads, tails, outcome As Integer
Dim totals As Double

Dim frequency As Decimal

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

heads = 0
tails = 0
totals = 0

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


If Flip() Then
heads = heads + 1
THeads.Text = heads
coinPictureBox1.Image = New Bitmap("c:\coin1.jpg")
Else
tails = tails + 1
Ttails.Text = tails
coinPictureBox1.Image = New Bitmap("c:\coin2.jpg")
End If

totals = totals + 1

Ttotal.Text = totals

End Sub

Function Flip() As Boolean
Return CBool(coin.Next(0, 2))

End Function

End Class


Adding this doesn't do it. don't I need a DisplayCoin() subroutine or something I am so mixed up Help!!!!!

rickbill
Newbie Poster
8 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

This is what I ran and it worked fine.

Public Class Form1
    Dim heads As Integer = 0
    Dim tails As Integer = 0
    Dim totals As Integer = 0
    Dim coin As New Random

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Flip() Then
            heads = heads + 1
            THeads.Text = heads.ToString & ""
            coinPictureBox1.Image = New Bitmap("c:\graphics\refresh.jpg")
        Else
            tails = tails + 1
            Ttails.Text = tails
            coinPictureBox1.Image = New Bitmap("c:\graphics\stop.jpg")
        End If
        totals = totals + 1
        Ttotal.Text = totals
    End Sub

    Function Flip() As Boolean
        Return CBool(coin.Next(0, 2))
    End Function

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

Now I didn't have your graphics so I just picked two from my images. All my graphics is in one folder called "graphics" so you will have to change the path to your graphics.

waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

thank you this worked just fine

rickbill
Newbie Poster
8 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

thank you this worked just find

rickbill
Newbie Poster
8 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You