+ Reply to Thread
Results 1 to 2 of 2

How To Pass Value Using "ByRef"

  1. #1
    JimFor
    Guest

    How To Pass Value Using "ByRef"

    Hi,
    I am trying to change the counter position in a program from what it would
    normally be if the program followed its original logic and I am trying to use
    the ByRef method to do this. Can't find too much written about this in the VBA
    books I looked at but it looks rather simple. I'm missing something because
    it does not work.

    I have a main program called Dog() which moves a cell counter by one and uses
    the name "Count" to point to a cell Cell (Count, 1). Dog has several
    "subprograms" which perform tasks and return to Dog. One of the subprogram's
    tasks is to change the cell pointer from what it would be if followed the 'i= 1
    to 100... Count = Count +...next i" method of looping used in Dog. A certain
    cell value causes a subprogram in Dog, say Sub Cat, to perform another
    calculation and change the Count value by one. If the next value of Count when
    Dog is performed would be, say, 6, Cat changes to it 7. I need to tell Dog the
    new value of Count is 7. I tried passing the new count value from Cat to Dog
    with the line Dog(ByRef Count) and I keep getting error messages of "Expected
    Expression" and "Syntax Error." Can anyone tell me how to pass a changed
    counter value using the ByRef technique and what I am doing wrong?

    Thanks


  2. #2
    Norman Jones
    Guest

    Re: How To Pass Value Using "ByRef"

    Hi JimFor,

    By way of example:

    Sub Dog()
    Dim MyCount As Long

    For MyCount = 1 To 30
    Two MyCount
    MsgBox MyCount
    Next
    End Sub

    Sub Two(ByRef aCount As Long)
    aCount = aCount + 4
    End Sub


    If you still experience problems, post your code.

    ---
    Regards,
    Norman



    "JimFor" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    > I am trying to change the counter position in a program from what it would
    > normally be if the program followed its original logic and I am trying to
    > use
    > the ByRef method to do this. Can't find too much written about this in the
    > VBA
    > books I looked at but it looks rather simple. I'm missing something
    > because
    > it does not work.
    >
    > I have a main program called Dog() which moves a cell counter by one and
    > uses
    > the name "Count" to point to a cell Cell (Count, 1). Dog has several
    > "subprograms" which perform tasks and return to Dog. One of the
    > subprogram's
    > tasks is to change the cell pointer from what it would be if followed the
    > 'i= 1
    > to 100... Count = Count +...next i" method of looping used in Dog. A
    > certain
    > cell value causes a subprogram in Dog, say Sub Cat, to perform another
    > calculation and change the Count value by one. If the next value of Count
    > when
    > Dog is performed would be, say, 6, Cat changes to it 7. I need to tell
    > Dog the
    > new value of Count is 7. I tried passing the new count value from Cat to
    > Dog
    > with the line Dog(ByRef Count) and I keep getting error messages of
    > "Expected
    > Expression" and "Syntax Error." Can anyone tell me how to pass a
    > changed
    > counter value using the ByRef technique and what I am doing wrong?
    >
    > Thanks
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1