User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 427,939 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,886 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 762 | Replies: 3 | Solved
Reply
Join Date: Feb 2008
Posts: 9
Reputation: sddproject is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sddproject sddproject is offline Offline
Newbie Poster

Upload picture from file

  #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:

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
Last edited by Tekmaven : Jul 20th, 2008 at 2:57 pm. Reason: Code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Location: Argentina
Posts: 51
Reputation: dmf1978 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 7
dmf1978's Avatar
dmf1978 dmf1978 is offline Offline
Junior Poster in Training

Re: Upload picture from file

  #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 3:39 pm.
-- Martín
Reply With Quote  
Join Date: Aug 2006
Location: Argentina
Posts: 51
Reputation: dmf1978 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 7
dmf1978's Avatar
dmf1978 dmf1978 is offline Offline
Junior Poster in Training

Re: Upload picture from file

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

Re: Upload picture from file

  #4  
Jul 26th, 2008
thank you!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 6:31 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC