declaring variable in Sub statement?

pkh

New Member
Joined
Nov 23, 2011
Messages
17
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
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,749
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])
 

pkh

New Member
Joined
Nov 23, 2011
Messages
17
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
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,323
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
No, 0 is the default. 1 is probably being passed when the sub is called.
 

pkh

New Member
Joined
Nov 23, 2011
Messages
17
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
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,323
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
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.
 

pkh

New Member
Joined
Nov 23, 2011
Messages
17
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
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,323
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Yes - that was a typo.
 

pkh

New Member
Joined
Nov 23, 2011
Messages
17
cool. thanks again guys. i'll probably be here again through various stages of the macro!
 

Forum statistics

Threads
1,081,691
Messages
5,360,647
Members
400,592
Latest member
katekoz

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top