declaring variable in Sub statement?

pkh

New Member
Joined
Nov 23, 2011
Messages
21
Hi,

I am trying to make sense of quite an elaborate macro built by someone else. This has the following line of code

Code:
Public Sub readOperation(rowNumber As Integer)
    Dim rowOff As Integer
    rowOff = rowNumber - 1
 
'other arguments and conditions
 
End Sub

What I am buggered about is that I cannot see the the variable rowNumber being declared anywhere but it seems to have a value of 1. I should mention that Operation is a class and I am very new to classes. Any help greatly appreciated.

pkh
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
What I am buggered about is that I cannot see the the variable rowNumber being declared anywhere

Hi

I see the variable declared in the Sub statement:


Code:
Public Sub readOperation([COLOR=red][B]rowNumber As Integer[/B][/COLOR])
 
Upvote 0
pgc

thanks for your reply. well, i thought that might be the case but wasn't sure. on to the next bit of my doubt - is 1 the default value for any integer variable?

pkh
 
Upvote 0
No, 0 is the default. 1 is probably being passed when the sub is called.
 
Upvote 0
Rorya
This is the sub that gets read prior to the sub in question. Do you suppose there si anything in here that is setting the value to the rowNumber variable to be 1?

Code:
Sub read_operations()
    Dim count As Integer, a As Integer
    
    count = 1
    
    For a = 1 To 10 '10 rows of operations
        ReDim Preserve Operations(1 To count) As operation
        Set Operations(count) = New operation
        Operations(count).readOperation (a)
        If Operations(count).hasData Then
            'Operations(count).showOperation
            count = count + 1
        Else
            Set Operations(count) = Nothing
        End If
    Next a
       
    If Operations(count) Is Nothing Then ReDim Preserve Operations(1 To count - 1) As operation
       
End Sub


This bit of the code gets read after the line
Set Operations(count) = New operation
and is locate within the class module.

Code:
Private opName As String
Private fiveBi As Double
Private fiveEl As Double
Private tenBi As Double
Private tenEl As Double
 
Private Sub Class_Initialize()
    opName = ""
    fiveBi = False
    fiveEl = 0
    tenBi = 0
    tenEl = 0
End Sub


Thanks,

pkh
 
Upvote 0
Code:
Operations(count).readOperation (a)
this line is passing the value of a to the sub, so it will start with 1 and increment to 100.
 
Upvote 0
ah. so thats it. thanks a lot guys. btw, you meant "will start with 1 and increment to" 10, right? or am i missing something else?

pkh
 
Upvote 0
Yes - that was a typo.
 
Upvote 0
cool. thanks again guys. i'll probably be here again through various stages of the macro!
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top