Three examples ....
Option Explicit
Dim TheSuit As Integer, TheCardNo As Integer, MyCard As Object
Private Sub Form_Load()
Randomize
End Sub
Private Sub Command1_Click()
Dim cp As StdPicture
'returning image as variable passed to sub
Call PickCard(TheSuit, TheCardNo, cp)
Picture1.Picture = cp
End Sub
Private Sub Command3_Click()
Dim cp As StdPicture
'returning image to variable from function
Set cp = PickCardf(TheSuit, TheCardNo)
Picture1.Picture = cp
End Sub
Private Sub Command2_Click()
'returning image directly to a pixbox from a function
Picture1.Picture = PickCardf(TheSuit, TheCardNo)
End Sub
Private Sub PickCard(ByRef CardSuit As Integer, ByRef CardNo As Integer,
CardPic As Object)
Dim CardValue As Integer
Dim CValue As String
CardSuit = Int(Rnd * 4 + 1)
CardNo = Int(Rnd * 13 + 1)
CardValue = 100 + (CardSuit - 1) * 13 + CardNo
CValue = LTrim(Str(CardValue))
Set CardPic = LoadPicture("J:\vb\IF\PlayingCardImages\" + CValue +
".gif")
End Sub
Private Function PickCardf(CardSuit As Integer, CardNo As Integer) As
StdPicture
Dim CardValue As Integer
Dim CValue As String
CardSuit = Int(Rnd * 4 + 1)
CardNo = Int(Rnd * 13 + 1)
CardValue = 100 + (CardSuit - 1) * 13 + CardNo
CValue = LTrim(Str(CardValue))
Set CardPic = LoadPicture("J:\vb\IF\PlayingCardImages\" + CValue + ".gif")
End Function
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
Please reply to the newsgroups so all can participate.
"Geoff" <gf****@freenetname.co.ukwrote in message
news:rO******************************@brightview.c om...
In this code I am trying to pass an image, as a parameter, out of the
procedure PickCard. The code will not support this. How do I pass an image
as a parameter?
Thanks again
Geoff
Dim TheSuit As Integer, TheCardNo As Integer, MyCard As Object
Private Sub PickCard(ByRef CardSuit As Integer, ByRef CardNo As Integer,
ByRef CardPic As Object)
Dim CardValue As Integer
Dim CValue As String
Randomize
CardSuit = Int(Rnd * 4 + 1)
CardNo = Int(Rnd * 13 + 1)
CardValue = 100 + (CardSuit - 1) * 13 + CardNo
CValue = LTrim(Str(CardValue))
CardPic.Picture = LoadPicture("J:\vb\IF\PlayingCardImages\" + CValue +
".gif")
End Sub
Private Sub ButDeal_Click()
Call PickCard(TheSuit, TheCardNo, MyCard)
End Sub