469,590 Members | 2,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

Help with parameter passing please

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
Sep 12 '06 #1
3 4917
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
Sep 13 '06 #2

"Randy Birch" <rg************@mvps.orgwrote in message
news:45*********************@news.astraweb.com...
>
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
Oops, I think that last line should be
Set PickCardf = LoadPicture("J:\vb\IF\PlayingCardImages\" + CValue + ".gif")
Sep 13 '06 #3
Right -- oops. In my test app I had used hard-coded paths on a line below
the OPs line and didn't update the name of the function as used in the test
call. Thanks.

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.


"Steve Gerrard" <my********@comcast.netwrote in message
news:yI******************************@comcast.com. ..

"Randy Birch" <rg************@mvps.orgwrote in message
news:45*********************@news.astraweb.com...
>
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
Oops, I think that last line should be
Set PickCardf = LoadPicture("J:\vb\IF\PlayingCardImages\" + CValue +
".gif")
Sep 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by intrepid_dw | last post: by
1 post views Thread by phuker420 | last post: by
15 posts views Thread by Jay | last post: by
4 posts views Thread by =?Utf-8?B?QmlsbEF0V29yaw==?= | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.