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

Upload picture from file

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

sddproject
Newbie Poster
9 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

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

dmf1978
Junior Poster in Training
51 posts since Aug 2006
Reputation Points: 18
Solved Threads: 7
 

Hi,
Is your problem solved?

dmf1978
Junior Poster in Training
51 posts since Aug 2006
Reputation Points: 18
Solved Threads: 7
 

thank you!

sddproject
Newbie Poster
9 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You