dcsimg
Results 1 to 14 of 14

Thread: This is a strange problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    80

    This is a strange problem

    OK, I have a program that is used for analysing records of predators that compete for the food and also kill our native bird the Kiwi.

    I am trying to add a Yearly Totals page to the program, but have run into some problems.

    I have made a short video that explains it better that words can. The video has been uploaded to you-tube. It is not a long video.

    If anyone can help I would be most grateful.
    Thank you.

    The you-tube link is: https://youtu.be/1CwA5A22Y2Y

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: This is a strange problem

    You need to post the relevant code. Can't analyze the code from the video, your constantly moving all over the place.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    80

    Re: This is a strange problem

    Ok, sorry, here are relevant code sections:

    This is the section that doesn't work,

    Code:
     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim YR2 As Integer = "2002"
            Dim Stoat1 As Integer = 0
            Dim Rat1 As Integer = 0
            Dim Cat1 As Integer = 0
            Dim Weasel1 As Integer = 0
            Dim Possum1 As Integer = 0
            Dim Hedgehog1 As Integer = 0
            Dim Ferret1 As Integer = 0
    
    
            Me.FIxLastTimeTableAdapter.BETWEENDates(Me.NewFixedDBDataSet.FIxLastTime, "01/01/2002", "31/12/2002")
    
    
    
    
            'RATS RATS                        'FIxLastTimeDataGridView 
            For Each row As DataGridViewRow In FIxLastTimeDataGridView.Rows
                If row.Cells(2).FormattedValue = "Rat" Then
    
                    Rat1 += row.Cells(3).Value
    
                End If
            Next
            MsgBox(Rat1)
    This section is from the part that Does work:

    Code:
      Dim RatsGone As Integer
    
            For Each row As DataGridViewRow In FIxLastTimeDataGridView.Rows
                If row.Cells(4).FormattedValue = "Rat" Then
    
                    RatsGone += row.Cells(5).Value
                End If
            Next
    Look forward to any advice (clues) as to why this is not working.
    Thanks

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: This is a strange problem

    A couple of things,

    Check how many records are loaded into the datatable?
    Code:
    Dim retCount as integer
    
    retCount = Me.FIxLastTimeTableAdapter.BETWEENDates(Me.NewFixedDBDataSet.FIxLastTime, "01/01/2002", "31/12/2002")
    
    MessageBox.Show(retCount.ToString)
    You fill the Me.NewFixedDBDataSet.FIxLastTime datatable but you don't do anything with it. I have no idea whats in FIxLastTimeDataGridView, unlerss you've already setup bindings.

    Why are you checking the FormattedValue?

    btw - you really should set a break point on this line to check the retCount value. The MessageBox will work in this case but it's a bad habit and in certain case cause problem.
    Code:
    retCount = Me.FIxLastTimeTableAdapter.BETWEENDates(Me.NewFixedDBDataSet.FIxLastTime, "01/01/2002", "31/12/2002")
    Last edited by wes4dbt; Aug 3rd, 2019 at 05:36 PM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    80

    Re: This is a strange problem

    Ok,

    The (lefthand Datagrid) displays the records for the year that I have selected using the "Between dates" statement

    I used your code to check how many records for the year 2002 are displayed in the datagrid and it matches the number for the year "2002" = 24, so that's correct. It's doing what it is supposed to do.
    As for the righthand (unbound) datagrid I have not written the code that will add the results from each year as at the moment as it's coming up with a 0 (zero) for Rat1 variable.

    As for the formatted value that's just to tidy up the display of the returned value on the main page of the program.
    Hope clarifies your questions.

    See Inset Picture:

    Name:  Summary.jpg
Views: 33
Size:  25.2 KB

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: This is a strange problem

    No it doesn't answer my questions. I still have no idea whats in FIxLastTimeDataGridView. That's what your using to count Rat, if that's empty then there is nothing to count. How many records does that grid display?

    Don't know if it's even related but the picture you posted show "Rats" but your checking for Rat.

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: This is a strange problem

    If you want to coount the records with Rat then just

    Code:
    For Each row as DataGridViewRow In Me.NewFixedDBDataSet.FIxLastTime.Rows
        If row("fieldname").ToString = "Rat" Then
            'do what ever
        End If
    Next
    I just free typed this so there might be errors

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    80

    Re: This is a strange problem

    OK, well the FIxLastTimeDataGridView ( if I didn't use the Between dates statement), would just show all the records from the being to the end, it would not isolate the year that I wanted to display.

    Don't know if it's even related but the picture you posted show "Rats" but your checking for Rat. That's unrelated as it is just a title label.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    80

    Re: This is a strange problem

    It's not that I want to know how many records there are for rat in a given year it's the count (kills, or number of kills), that I want.

  10. #10
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: This is a strange problem

    So how many records are in the DGV when you do the count? Also, I did notice that yout using different Cell numbers,

    Code:
    If row.Cells(2).FormattedValue = "Rat" Then
    If row.Cells(4).FormattedValue = "Rat" Then

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    80

    Re: This is a strange problem

    Quote Originally Posted by wes4dbt View Post
    So how many records are in it what you do the count? Also, I did notice that yout using different Cell numbers,

    Code:
    If row.Cells(2).FormattedValue = "Rat" Then
    If row.Cells(4).FormattedValue = "Rat" Then
    OK, that's because;

    'RATS RATS 'FIxLastTimeDataGridView
    For Each row As DataGridViewRow In FIxLastTimeDataGridView.Rows
    If row.Cells(2).FormattedValue = "Rat" Then

    Rat1 += row.Cells(3).Value

    End If
    Next
    MsgBox(Rat1)

    This line looks for records with "Rat" : If row.Cells(2).FormattedValue = "Rat" Then

    and this line gets the value of the QTY: Rat1 += row.Cells(3).Value

    row.cell(3) contains the value.


    Hope that explains

  12. #12
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: This is a strange problem

    That's not what I'm talking about,

    You say this works,
    Code:
      Dim RatsGone As Integer
    
            For Each row As DataGridViewRow In FIxLastTimeDataGridView.Rows
                If row.Cells(4).FormattedValue = "Rat" Then
    
                    RatsGone += row.Cells(5).Value
                End If
            Next
    You check the value in Cell 4

    You say this doesn't work
    Code:
            For Each row As DataGridViewRow In FIxLastTimeDataGridView.Rows
                If row.Cells(2).FormattedValue = "Rat" Then
    
                    Rat1 += row.Cells(3).Value
    
                End If
            Next
    You check thec value in Cell 2.

    Also, you still haven't said how many records are displayed in the DGV when you make the count.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    80

    Re: This is a strange problem

    OK, the difference between the cell numbers is, on the main search page the user need to see all the fields, there are 7 from memory. On the Year History page I only need three fields, they are (Date, Critter (which holds the quantity of (Rat/s) killed).
    Cell 2 only is used to get the records with Rat.

    Yes this works

    Code:
    Dim RatsGone As Integer
    
            For Each row As DataGridViewRow In FIxLastTimeDataGridView.Rows
                If row.Cells(4).FormattedValue = "Rat" Then
    
                    RatsGone += row.Cells(5).Value
                End If
            Next
    and this does not:

    Code:
    For Each row As DataGridViewRow In FIxLastTimeDataGridView.Rows
                If row.Cells(2).FormattedValue = "Rat" Then
    
                    Rat1 += row.Cells(3).Value
    
                End If
            Next
    Name:  Left Datagrid.jpg
Views: 32
Size:  104.4 KB


    Weird

  14. #14
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,153

    Re: This is a strange problem

    Unless you have some columns that aren't visible, Cell(2) is the QTY field.

    If you want to find out what's going on when you cycle through the DGV then put a break point at this line,
    Code:
    If row.Cells(2).FormattedValue = "Rat" Then
    And check the value of Cell(2).

    Personally I would use the DataTable and not the DGV,

    Code:
    For Each row as DataRow In Me.NewFixedDBDataSet.FIxLastTime.Rows
        If row("Critter").ToString.ToUpper = "RAT" Then
            'total the qantity
        End If
    Next

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width