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

This question has already been answered. Start a new discussion instead.