dcsimg
Results 1 to 12 of 12

Thread: Determining Row and Column

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    550

    Determining Row and Column

    I have an array of (0 to 49, 0 To 99) and if I know a certain number how do I determine which row and column it is in

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,663

    Re: Determining Row and Column

    A nested loop.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,098

    Re: Determining Row and Column

    Why does this need a nested loop?
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,663

    Re: Determining Row and Column

    Code:
    
    Option Explicit
    
    Private Sub Form_Load()
    
    
        Dim MyArray(0 To 49, 0 To 99) As Long
        Dim iRow As Long
        Dim iCol As Long
    
        ' Do something that populates the array.
    
        Dim iSearchValue As Long
        Dim bFound As Boolean
    
        iSearchValue = 1234
    
        bFound = False
        For iRow = 0 To 49              ' Nested loop first level.
            For iCol = 0 To 99          ' Nested loop second level.
                If MyArray(iRow, iCol) = iSearchValue Then
                    bFound = True
                    Exit For
                End If
            Next
            If bFound Then Exit For
        Next
        If Not bFound Then
            iRow = -1
            iCol = -1
        End If
    
    
        Debug.Print iRow, iCol
    
    
    End Sub
    
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    550

    Re: Determining Row and Column

    Row = Number \ NumCols
    Col = Number Mod NumCols

    I tried this and it appears to work
    Last edited by Code Dummy; Aug 4th, 2019 at 07:51 PM.

  6. #6
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    790

    Re: Determining Row and Column

    Quote Originally Posted by Code Dummy View Post
    I have an array of (0 to 49, 0 To 99) and if I know a certain number how do I determine which row and column it is in
    A "certain number" means what, exactly? Like Elroy, I assumed you were talking about a number that is stored as a value somewhere in the 2D array. After your last post, it is clear that you weren't talking about a value stored in the array, but there was no way to know that based on the minimal effort and detail you put in to your post.

    I would suggest you at least make semblance of effort when making threads to explain what it is you are looking for. Like you did here:

    http://www.vbforums.com/showthread.p...61#post5385261

    Where, by the way, you basically asked the exact same question as you did in this thread.

    Good luck.

    Edit:

    Also, http://www.vbforums.com/showthread.p...67-Array-issue

    Edit2:

    Also, http://www.vbforums.com/showthread.p...81#post5383081

    And I'll throw this one in too, since it is in the same ballpark http://www.vbforums.com/showthread.p...-Shape-control

    Do yourself a favor, spend a few minutes with pen and paper and draw out some grids with row numbers, column numbers, and the "certain numbers", get familiar with MOD, and with \ (integer divide).
    Last edited by OptionBase1; Aug 4th, 2019 at 08:31 PM.

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,663

    Re: Determining Row and Column

    Ahhh, yes, I totally misunderstood what you meant by "certain number". I think OptionBase1 did an excellent job of outlining my frustration, so I won't say more.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  8. #8
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,098

    Re: Determining Row and Column

    Quote Originally Posted by Elroy View Post
    Ahhh, yes, I totally misunderstood what you meant by "certain number". I think OptionBase1 did an excellent job of outlining my frustration, so I won't say more.

    Good Luck,
    Elroy
    Indeed. That's precisely why I questioned the nested loop; I had already recognised this as a recurring question. It's a good thing this isn't an electrician's forum: "What's the red wire for, again?"
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  9. #9
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,333

    Re: Determining Row and Column

    Quote Originally Posted by Code Dummy View Post
    Row = Number \ NumCols
    Col = Number Mod NumCols

    I tried this and it appears to work
    It seems apparently you don't know why it works though.
    You've asked this question a number of times over the last several months, and you've been using this code to convert linear number into row and column in several programs as a result. Now, apparently, you're starting another similar version of the program and have the same need, but feel you have to ask the question again rather than use what you've used several times before.

    I guess I have to have some empathy for your struggles as it seems you have difficulty retaining what you learn from your experiences. That would seem to make programming a more difficult challenge for you than it already is for the majority of practitioners.

    Happy programming and best wishes.

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,422

    Re: Determining Row and Column

    As difficult a time as these threads have been... you haven't seen anything if you haven't looked at Python forums and SO questions on Python. Almost as bad as PHP scripting questions. There is a new Low Rent District out there these days.

  11. #11
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,333

    Re: Determining Row and Column

    While there may be those who don't care to program, but only do it because it is a school requirement so would prefer stuff just handed to them, and others who might be intrigued by programming but are lazy, I think there is a small group of programmers I've seen that have a passion for it, and do work at it over many years, but don't have the innate ability to match their desire or may have other challenges that make learning, retaining, and using what they're exposed to in the pursuit of their passion an additional challenge beyond the realm of the typical devotee.

    That these few individuals genuinely pursue this hobby despite these challenges for years, and often have to deal with derision on top of these challenges from those of us whom much of these basic skills have come relatively easily by comparison, has been quite impressive to me, although I have let myself succumbed to frustration with other's challenges myself from time to time. I can't understand the uphill battle that some of these hard-pressed aficionados face, but should admire the persistent and genuine effort they employ, in spite of the personal obstacles.

  12. #12
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,663

    Re: Determining Row and Column

    Quote Originally Posted by passel View Post
    While there may be those who don't care to program, but only do it because it is a school requirement so would prefer stuff just handed to them, and others who might be intrigued by programming but are lazy, I think there is a small group of programmers I've seen that have a passion for it, and do work at it over many years, but don't have the innate ability to match their desire or may have other challenges that make learning, retaining, and using what they're exposed to in the pursuit of their passion an additional challenge beyond the realm of the typical devotee.

    That these few individuals genuinely pursue this hobby despite these challenges for years, and often have to deal with derision on top of these challenges from those of us whom much of these basic skills have come relatively easily by comparison, has been quite impressive to me, although I have let myself succumbed to frustration with other's challenges myself from time to time. I can't understand the uphill battle that some of these hard-pressed aficionados face, but should admire the persistent and genuine effort they employ, in spite of the personal obstacles.

    *laughs* Thanks for keeping us on the righteous path, Passel.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

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