Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 104
  • Last Modified:

Explain code written by another coder

Ihave code written by another coder that i don't understand
Textmatrix requires a row and column
Example:
On this line how does Recap.CompanyName produce a column
FlxGrd(2).TextMatrix(i + 1, Recap.CompanyName) = .CompanyName

Form declaration
Private Type Recap_UDT
  CompanyName  As Byte
  Estimator    As Byte
  sDate        As Byte
  BidAmount    As Byte
  BidMaterial  As Byte
  Bid2Amount   As Byte
  Bid2Material As Byte
  sqs          As Byte
  BusYrs       As Byte
End Type

Private Recap As Recap_UDT
End Form declaration

Private Function Populate_Grid()'should have been a sub not function
Dim i As Integer
Dim j As Integer
  FlxGrd(2).Rows = RoofCompanyTotal + 1
    For i = 0 To RoofCompanyTotal - 1
      With RoofCompany(i)
        For j = 0 To FlxGrd(2).Cols - 1
          FlxGrd(2).TextMatrix(i + 1, j) = vbNullString
        Next j
        FlxGrd(2).TextMatrix(i + 1, Recap.CompanyName) = .CompanyName
        FlxGrd(2).TextMatrix(i + 1, Recap.Estimator) = .Estimator
        FlxGrd(2).TextMatrix(i + 1, Recap.sDate) = .sDate
        FlxGrd(2).TextMatrix(i + 1, Recap.BidAmount) = .BidAmount
        FlxGrd(2).TextMatrix(i + 1, Recap.BidMaterial) = .BidMaterial
        FlxGrd(2).TextMatrix(i + 1, Recap.Bid2Amount) = .Bid2Amount
        FlxGrd(2).TextMatrix(i + 1, Recap.Bid2Material) = .Bid2Material
        FlxGrd(2).TextMatrix(i + 1, Recap.sqs) = .BusYrs
        'FlxGrd(2).TextMatrix(i + 1, Recap.BusYrs) = .BusYrs
      End With
    Next
    SetGridSize FlxGrd(2)
End Function

Open in new window

0
isnoend2001
Asked:
isnoend2001
1 Solution
 
vb_elmarCommented:
There's a bug in the code. Instead ...
      End With
    Next
    SetGridSize FlxGrd(2)
End Function
End Function
**.... it should be ....**
      Next
    End With
    SetGridSize FlxGrd(2)
End Function
End Function 

Open in new window

0
 
isnoend2001Author Commented:
Thanks vb_elmar, i see, but that does not answer my question
0
 
Martin LissRetired ProgrammerCommented:
FlxGrd(2).TextMatrix(i + 1, Recap.CompanyName) = .CompanyName
I'm not sure what you're asking but TextMatrix has two parameters, Row and Column, both of which need to be numbers., so let me ask you a question. What gets loaded into Recap.CompanyName? If it's a number then there's a much better way of referring to the TextMatrix column..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Neil RussellTechnical Development LeadCommented:
In code you have declared....

Private Recap As Recap_UDT
End Form declaration

So somewhere, before this function is called, Recap must be assigned data to it.  Recap.CompanyName will be whatever is assigned at that point, not in this function.
0
 
isnoend2001Author Commented:
don' understand i will post the project
Project-roof--update5-.zip
0
 
Martin LissRetired ProgrammerCommented:
Thanks. Also please try to restate your question since it isn't clear to me what it is that you don't understand.
0
 
Martin LissRetired ProgrammerCommented:
After looking at the project I see that Recap is filled with numbers by this code.

230         With Recap
240           .CompanyName = 0
250           .Estimator = 1
260           .sDate = 2
270           .BidAmount = 3
280           .BidMaterial = 4
290           .Bid2Amount = 5
300           .Bid2Material = 6
310           .Sqs = 7
320           .BusYrs = 8
330         End With

Open in new window

which is a poor way to do it. If you want to change it then please ask another question about it.

In any case your FlxGrd(2).TextMatrix(i + 1, Recap.CompanyName) = .CompanyName line now says
"The FlxGrd(2) cell with the column value equal to i+1 and row 0, is the value in RoffCompany.CompanyName"
0
 
isnoend2001Author Commented:
I dont understand how FlxGrd(2).TextMatrix(i + 1, Recap.CompanyName)
the column recap.companyname = a number
0
 
Martin LissRetired ProgrammerCommented:
I dont understand how FlxGrd(2).TextMatrix(i + 1, Recap.CompanyName)
the column recap.companyname = a number

FlxGrd(2).TextMatrix(i + 1, Recap.CompanyName) = .CompanyName

is the same as

FlxGrd(2).TextMatrix(i + 1, 0) = .CompanyName

because Recap.CompanyName is set to zero. And TextMatrix(i + 1, 0) are the coordinates of a cell.
0
 
isnoend2001Author Commented:
Thanks now i see didn't notice the
230         With Recap
240           .CompanyName = 0
250           .Estimator = 1
260           .sDate = 2
270           .BidAmount = 3
280           .BidMaterial = 4
290           .Bid2Amount = 5
300           .Bid2Material = 6
310           .Sqs = 7
320           .BusYrs = 8
330         End With
0
 
it_saigeDeveloperCommented:
Essentially what Martin is saying is this.  The method TextMatrix, takes a Row and Column index value as it's parameters.  The row part is easy because it is determined by the i value in the for loop.  The second value, which represents the column, is controlled by the Recap variable.  So you identify the row and column (which equates to a cell) in the matrix that you want to update.

So lets put it all together:
Private Function Populate_Grid()
Dim i As Integer
Dim j As Integer
  ' Set the number of rows in the grid equal to the number of roof companies + 1 (the plus one is for the header row)
  FlxGrd(2).Rows = RoofCompanyTotal + 1
    ' Let's loop through the RoofCompanyTotal value (subtracting one to avert an index out of bounds exception)
    For i = 0 To RoofCompanyTotal - 1
      ' With the current, i, RoofCompany; the first one will be 0 and the last one will be the RoofCompanyTotal - 1.
      With RoofCompany(i)
        ' Let's loop through the columns in the row + 1 (this way we skip the header row) and set each columns text equal 
        ' to a null string
        For j = 0 To FlxGrd(2).Cols - 1
          FlxGrd(2).TextMatrix(i + 1, j) = vbNullString
        Next j
        ' Recap.CompanyName tells us to write text into the column that has an index of 0, the text will equal the 
        ' current roofing company CompanyName.  We already know that row we are dealing with.
        FlxGrd(2).TextMatrix(i + 1, Recap.CompanyName) = .CompanyName
        ' Recap.Estimator tells us to write text into the column that has an index of 1, the text will equal the 
        ' current roofing company Estimator.  We already know that row we are dealing with.
        FlxGrd(2).TextMatrix(i + 1, Recap.Estimator) = .Estimator
        ' Recap.sDate tells us to write text into the column that has an index of 2, the text will equal the 
        ' current roofing company sDate.  We already know that row we are dealing with.
        FlxGrd(2).TextMatrix(i + 1, Recap.sDate) = .sDate
        ' Recap.BidAmount tells us to write text into the column that has an index of 3, the text will equal the 
        ' current roofing company BidAmount.  We already know that row we are dealing with.
        FlxGrd(2).TextMatrix(i + 1, Recap.BidAmount) = .BidAmount
        ' Recap.BidMaterial tells us to write text into the column that has an index of 4, the text will equal the 
        ' current roofing company BidMaterial.  We already know that row we are dealing with.
        FlxGrd(2).TextMatrix(i + 1, Recap.BidMaterial) = .BidMaterial
        ' Recap.Bid2Amount tells us to write text into the column that has an index of 5, the text will equal the 
        ' current roofing company Bid2Amount.  We already know that row we are dealing with.
        FlxGrd(2).TextMatrix(i + 1, Recap.Bid2Amount) = .Bid2Amount
        ' Recap.Bid2Material tells us to write text into the column that has an index of 6, the text will equal the 
        ' current roofing company Bid2Material.  We already know that row we are dealing with.
        FlxGrd(2).TextMatrix(i + 1, Recap.Bid2Material) = .Bid2Material
        ' Recap.sqs tells us to write text into the column that has an index of 7, the text will equal the 
        ' current roofing company sqs.  We already know that row we are dealing with.
        FlxGrd(2).TextMatrix(i + 1, Recap.sqs) = .BusYrs
        ' This is commented out so the column, if it exists, should have a null string value.
        'FlxGrd(2).TextMatrix(i + 1, Recap.BusYrs) = .BusYrs
      End With
    Next
    SetGridSize FlxGrd(2)
End Function

Open in new window


-saige-
0
 
Martin LissRetired ProgrammerCommented:
I note in your code that in the following code and several other places you refer to Employee and m_Employees, neither of which are defined in the code you posted. Is a module missing?

Private Sub ListEmployees()
Dim emp As Employee
Dim txt As String

    For Each emp In m_Employees
        txt = txt & emp.LastName & ", " & _
            emp.FirstName & vbCrLf
    Next emp
    txtEmployees.Text = txt
End Sub

Open in new window

0
 
isnoend2001Author Commented:
Thanks MartinLiss, i think the variables are unused and left from my first attempt to write this  using a collection
0
 
Martin LissRetired ProgrammerCommented:
If that's the case then you should get rid of them. To locate all occurrences you should try and compile the project,
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now