-
Aug 4th, 2019, 03:08 PM
#1
Thread Starter
Fanatic Member
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
-
Aug 4th, 2019, 06:19 PM
#2
Re: Determining Row and Column
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. To all, peace and happiness.
-
Aug 4th, 2019, 07:06 PM
#3
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
-
Aug 4th, 2019, 07:19 PM
#4
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. To all, peace and happiness.
-
Aug 4th, 2019, 07:45 PM
#5
Thread Starter
Fanatic Member
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.
-
Aug 4th, 2019, 08:07 PM
#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:
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.
-
Aug 5th, 2019, 08:36 AM
#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
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. To all, peace and happiness.
-
Aug 5th, 2019, 10:28 AM
#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?"
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Aug 5th, 2019, 02:00 PM
#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.
-
Aug 5th, 2019, 03:03 PM
#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.
-
Aug 5th, 2019, 09:18 PM
#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.
-
Aug 5th, 2019, 09:22 PM
#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.
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. 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|