By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,750 Members | 1,090 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,750 IT Pros & Developers. It's quick & easy.

passing an Array to a search function - ?

P: 9
getting a bit stuck here

got some code that allows a user to input numbers to a 3x3 array. but next on the tutorial sheet i have to then ask the user for a number to search for and then search the array for that number and come back with its location in the array

now i have the code that fils the array, but i dont know how to write the function, or what i should be passing to the function. i dont know how to get a location out of the other end either! :(

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdT5d_Click()
  3.  
  4. Dim intCol As Integer
  5. Dim intRow As Integer
  6. Dim intMyArray(3, 3) As Integer
  7. Dim intFindNum As Integer
  8. Dim intNumSearch As Integer
  9.  
  10.  
  11.  
  12.  
  13.  
  14. For intRow = 1 To 3
  15. For intCol = 1 To 3
  16.  
  17. intMyArray(intRow, intCol) = InputBox("please enter numbers into the array", "Numerical Input Box", 1)
  18.  
  19. Next intCol
  20. Next intRow
  21.  
  22. FindNum = InputBox("please select a number to search for","number search",1)
  23.  
  24.  
  25. NumSearch = Lsearch(intMyArray(), intFindNum)
  26.  
  27. txtT5e.text = NumSearch
  28.  
  29. End Sub
  30.  
for the search function then is this correct?
Expand|Select|Wrap|Line Numbers
  1. Private Function Lsearch(intMyArray() As Integer, intFindNum As Integer) As Integer 
  2.  
thats as far as i got :(
Oct 31 '07 #1
Share this Question
Share on Google+
3 Replies

Expert 5K+
P: 8,434
Your search function declaration looks pretty good to me. The code in there will just need to do a couple of nested loops like the ones that filled the array, and test whether each entry matches the search value.
Nov 1 '07 #2

P: 9
cheers dude,

erm would i need to pass intCol and intRow through or would it already know about those?
Nov 1 '07 #3

QVeen72
Expert 100+
P: 1,445
Hi,

Declare the array at the Form-Level..(Top of Form's Code Window)
So that, When you write the Search Code in another Command_Click, the array is still there..
If you declare in command_Click, the array goes out of scope...


Regards
Veena
Nov 1 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.