473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to search in array?

Hello

I want to search number in array, i wrote the following code but it doesnt work
please check it
and sned me the solution.
----------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Sub Main()
  2.         Dim array As Integer() = New Integer(3) {}
  3.         Dim search As Integer
  4.         For i As Integer = 0 To array.GetUpperBound(0)
  5.             Console.Write("Enter any number for array location [{0}]: ", i + 1)
  6.             array(i) = Console.ReadLine()
  7.         Next
  8.         Console.WriteLine()
  9.         For i As Integer = 0 To array.GetUpperBound(0)
  10.             Console.WriteLine("The outpu of array is {0}", array(i))
  11.         Next
  12.         Console.WriteLine()
  13.         Console.Write("Enter any value to search: ")
  14.         search = Console.ReadLine()
  15.         For i As Integer = 0 To array.GetUpperBound(0)
  16.             If array(i) = search Then
  17.                 Console.Write("The search value found at array location {0}", i)
  18.                 Exit For
  19.             End If
  20.  
  21.             If array(i) <> search Then
  22.                 Console.Write("the search does not matched with array")
  23.  
  24.             End If
  25.         Next
  26.         Console.ReadLine()
  27.     End Sub
----------------------------------------------------------------
thanks in advance
Apr 15 '10 #1
2 2033
tlhintoq
3,525 Expert 2GB
TIP: When you first created your question you were asked to wrap your code with [code] tags.

It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Apr 15 '10 #2
tlhintoq
3,525 Expert 2GB
"It doesn't work" is hardly helpful. Could you be a little more specific as to the problem? You get a wrong value... you get an exception error...

May I suggest you put a breakpoint at line 15... then walk through the loop line by line with the F10 key. Look at the values of your variables in the 'Locals' or 'Autos' pallet. You'll probably find that the match is failing because 15 does not equal "15\r" or something similar
Apr 15 '10 #3

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

Similar topics

28
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
1
by: cyrvb | last post by:
Hello, I'm a very very newbie in C# I did start 2 days ago, I get Visual Stuido 2005 C# I try to understand how to manage the arrays I did write this
10
by: free2cric | last post by:
Hi, I have a single link list which is sorted. structure of which is like typedef struct mylist { int num; struct mylist *next;
5
by: Martien van Wanrooij | last post by:
I have been using phpdig in some websites but now I stored a lot of larger texts into a mysql database. In the phpdig search engine, when you entered a search word, the page where the search word...
36
by: lovecreatesbeauty | last post by:
Any comments are welcome for following the two sequential search C functions of both integer and string versions. Though they are simple, please do not laugh at it :) Could you give your great...
3
by: mdh_2972 | last post by:
I have an array of over 1000 links in a .JS file. I do not want to put the whole thing on my page because it would take to long to render the page. So how can I randomly pick 1 element from the...
6
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. ...
0
by: Atos | last post by:
Binary search is used to locate a value in a sorted list of values. It selects the middle element in the array of sorted values, and compares it with the target value; that is the key we are...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.