943,568 Members | Top Members by Rank

Ad:
Jul 20th, 2008
0

Upload picture from file

Expand Post »
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:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Class Form1
  2. Dim headCount As Integer
  3. Dim tailCount As Integer
  4. Dim choice As Integer
  5.  
  6. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  7. lblHeadCt.Text = "Heads: " & Str(headCount)
  8. lblTailCt.Text = "Heads: " & Str(tailCount)
  9. End Sub
  10.  
  11. Private Sub cmdFlip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFlip.Click
  12. Randomize()
  13. choice = Int(Rnd() * 2)
  14.  
  15. If choice = 0 Then
  16. headCount = headCount + 1
  17. imgCoin = Image.FromFile()
  18. Else
  19. tailCount = tailCount + 1
  20. imgCoin =
  21. End If
  22.  
  23. End Sub
  24. End Class

Thank you
Last edited by Tekmaven; Jul 20th, 2008 at 3:57 pm. Reason: Code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sddproject is offline Offline
9 posts
since Feb 2008
Jul 21st, 2008
0

Re: Upload picture from file

Hi,
First, this is not VB6 code. It is VB.Net.
To load an image, you must code:
VBNET Syntax (Toggle Plain Text)
  1. Dim coinImage As Image
  2. Dim imagePath As String = ""
  3.  
  4. If choice = 0 Then
  5. headCount = headCount + 1
  6. imagePath = "Heads.gif"
  7. Else
  8. tailCount = tailCount + 1
  9. imagePath = "Tails.gif"
  10. End If
  11.  
  12. ' Here you have your image loaded in coinImage
  13. coinImage = New Bitmap(imagePath)

Then, if you want to put the image in a PictureBox, you must write:
VBNET Syntax (Toggle Plain Text)
  1. PictureBox1.Image = coinImage

Hope it helps
Last edited by dmf1978; Jul 21st, 2008 at 4:39 pm.
Reputation Points: 18
Solved Threads: 7
Junior Poster in Training
dmf1978 is offline Offline
51 posts
since Aug 2006
Jul 24th, 2008
0

Re: Upload picture from file

Hi,
Is your problem solved?
Reputation Points: 18
Solved Threads: 7
Junior Poster in Training
dmf1978 is offline Offline
51 posts
since Aug 2006
Jul 26th, 2008
0

Re: Upload picture from file

thank you!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sddproject is offline Offline
9 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Difficulty in reading data thru Com port
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Need to separate 16 bit binary to 4bit and 12 bit binary values





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC