Hi!

I'm trying to make a coin toss program using a random generator, but i'm not sure how to upload the image of the heads and tails from its file on my PC. Image names are Tails.gif and Heads.gif . Here's the code so far:

Public Class Form1
    Dim headCount As Integer
    Dim tailCount As Integer
    Dim choice As Integer
   
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblHeadCt.Text = "Heads: " & Str(headCount)
        lblTailCt.Text = "Heads: " & Str(tailCount)
    End Sub

    Private Sub cmdFlip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFlip.Click
        Randomize()
        choice = Int(Rnd() * 2)
      
        If choice = 0 Then
            headCount = headCount + 1
            imgCoin = Image.FromFile()
        Else
            tailCount = tailCount + 1
            imgCoin =
        End If
    
End Sub
End Class

Thank you

Hi,
First, this is not VB6 code. It is VB.Net.
To load an image, you must code:

Dim coinImage As Image
        Dim imagePath As String = ""

        If choice = 0 Then
            headCount = headCount + 1
            imagePath = "Heads.gif"
        Else
            tailCount = tailCount + 1
            imagePath = "Tails.gif"
        End If

        ' Here you have your image loaded in coinImage
        coinImage = New Bitmap(imagePath)

Then, if you want to put the image in a PictureBox, you must write:

PictureBox1.Image = coinImage

Hope it helps

Hi,
Is your problem solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.