Upload picture from file

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2008
Posts: 9
Reputation: sddproject is an unknown quantity at this point 
Solved Threads: 0
sddproject sddproject is offline Offline
Newbie Poster

Upload picture from file

 
0
  #1
Jul 20th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 51
Reputation: dmf1978 is an unknown quantity at this point 
Solved Threads: 7
dmf1978's Avatar
dmf1978 dmf1978 is offline Offline
Junior Poster in Training

Re: Upload picture from file

 
0
  #2
Jul 21st, 2008
Hi,
First, this is not VB6 code. It is VB.Net.
To load an image, you must code:
  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:
  1. PictureBox1.Image = coinImage

Hope it helps
Last edited by dmf1978; Jul 21st, 2008 at 4:39 pm.
-- Martín
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 51
Reputation: dmf1978 is an unknown quantity at this point 
Solved Threads: 7
dmf1978's Avatar
dmf1978 dmf1978 is offline Offline
Junior Poster in Training

Re: Upload picture from file

 
0
  #3
Jul 24th, 2008
Hi,
Is your problem solved?
-- Martín
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 9
Reputation: sddproject is an unknown quantity at this point 
Solved Threads: 0
sddproject sddproject is offline Offline
Newbie Poster

Re: Upload picture from file

 
0
  #4
Jul 26th, 2008
thank you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC