1. 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. Re: Determining Row and Column

A nested loop.

3. Re: Determining Row and Column

Why does this need a nested loop?

4. Re: Determining Row and Column

Code:
```
Option Explicit

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
```

5. Re: Determining Row and Column

Row = Number \ NumCols
Col = Number Mod NumCols

I tried this and it appears to work

6. Re: Determining Row and Column

Originally Posted by Code Dummy
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:

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

Good luck.

Edit:

Edit2:

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).

7. 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

8. Re: Determining Row and Column

Originally Posted by Elroy
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?"

9. Re: Determining Row and Column

Originally Posted by Code Dummy
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. 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. 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. Re: Determining Row and Column

Originally Posted by passel
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.

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