Help with parameter passing please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff

    #1

    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(CardV alue))

    CardPic.Picture = LoadPicture("J: \vb\IF\PlayingC ardImages\" + CValue +
    ".gif")



    End Sub





    Private Sub ButDeal_Click()



    Call PickCard(TheSui t, TheCardNo, MyCard)



    End Sub


  • Randy Birch

    #2
    Re: Help with parameter passing please

    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(TheSui t, TheCardNo, cp)
    Picture1.Pictur e = cp

    End Sub

    Private Sub Command3_Click( )

    Dim cp As StdPicture

    'returning image to variable from function
    Set cp = PickCardf(TheSu it, TheCardNo)
    Picture1.Pictur e = cp

    End Sub

    Private Sub Command2_Click( )

    'returning image directly to a pixbox from a function
    Picture1.Pictur e = PickCardf(TheSu it, 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(CardV alue))

    Set CardPic = LoadPicture("J: \vb\IF\PlayingC ardImages\" + CValue +
    ".gif")

    End Sub

    Private Function PickCardf(CardS uit 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(CardV alue))

    Set CardPic = LoadPicture("J: \vb\IF\PlayingC ardImages\" + CValue + ".gif")

    End Function

    --

    Randy Birch
    MS MVP Visual Basic


    Please reply to the newsgroups so all can participate.




    "Geoff" <gfriar@freenet name.co.ukwrote in message
    news:rO-dnZgA3oBKhZrYnZ 2dnUVZ8qGdnZ2d@ brightview.com. ..
    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(CardV alue))

    CardPic.Picture = LoadPicture("J: \vb\IF\PlayingC ardImages\" + CValue +
    ".gif")



    End Sub





    Private Sub ButDeal_Click()



    Call PickCard(TheSui t, TheCardNo, MyCard)



    End Sub


    Comment

    • Steve Gerrard

      #3
      Re: Help with parameter passing please


      "Randy Birch" <rgb_removethis @mvps.orgwrote in message
      news:450753d2$0 $9389$c3e8da3@n ews.astraweb.co m...
      >
      Private Function PickCardf(CardS uit 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(CardV alue))
      >
      Set CardPic = LoadPicture("J: \vb\IF\PlayingC ardImages\" + CValue + ".gif")
      >
      End Function
      >
      Oops, I think that last line should be
      Set PickCardf = LoadPicture("J: \vb\IF\PlayingC ardImages\" + CValue + ".gif")


      Comment

      • Randy Birch

        #4
        Re: Help with parameter passing please

        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


        Please reply to the newsgroups so all can participate.




        "Steve Gerrard" <mynamehere@com cast.netwrote in message
        news:yIOdna51Uo T8_ZrYnZ2dnUVZ_ sidnZ2d@comcast .com...

        "Randy Birch" <rgb_removethis @mvps.orgwrote in message
        news:450753d2$0 $9389$c3e8da3@n ews.astraweb.co m...
        >
        Private Function PickCardf(CardS uit 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(CardV alue))
        >
        Set CardPic = LoadPicture("J: \vb\IF\PlayingC ardImages\" + CValue +
        ".gif")
        >
        End Function
        >
        Oops, I think that last line should be
        Set PickCardf = LoadPicture("J: \vb\IF\PlayingC ardImages\" + CValue +
        ".gif")


        Comment

        Working...