473,657 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help searching array

18 New Member
the program runs, and user is prompted via inputbox to enter an integer-this is the size of the array, then the user fills the array with that many values...but as the user enters the values, i need to check and make sure that none of hte values have already been entered in the array, if it has..then there must be a message telling user to enter a new value.

EX: user prompted to enter an integer e.g.-2, then user is prompted to enter values to fill array, it loops until 2 values have been entered- e.g. 1 and 2..then the numbers 1 and 2 are displayed in a list box...but if the user enters 1 and 1..there needs to be a message or input box saying to enter a new value b/c 1 has already been used.

any help on searching the array would be great, here is my code:


Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim length As String
length = InputBox("Enter size of array")
Do While Not ispositiveinteg er(length)
length = InputBox("Enter size of array")
Loop



Dim stringarray() As String
stringarray = MakeArray(lengt h)
Dim i As Integer
For i = 0 To stringarray.Get UpperBound(0)

lstdisplay.Item s.Add(stringarr ay(i))
End If

Next
End Sub

Function MakeArray(ByVal size As Integer) As String()
Dim Array(size - 1) As String
Dim i As Integer
For i = 0 To Array.GetUpperB ound(0)
Array(i) = InputBox("Enter array values: ")
Next
Return Array

End Function
End Class
Nov 24 '08 #1
3 1907
rpicilli
77 New Member
Hi there,

Certanly will have a better way but you can study this and modify. This is just for you get on the way. Put this code into a buttom_click event and go step by step to figured out what is going on

Hope this help you

Expand|Select|Wrap|Line Numbers
  1.         Dim i As Integer = 10
  2.         Dim myArray(10) As String
  3.         For u As Integer = 0 To i
  4.             Dim jIn As String
  5.             jIn = InputBox("Type Enter with no value to leave or Enter data: ")
  6.             Try
  7.                 If jIn = "" Then Exit Sub
  8.                 Dim j As Integer
  9.                 For j = 0 To i - 1
  10.                     If myArray(j) = jIn Then
  11.                         MessageBox.Show("Value is there")
  12.                         u = 0
  13.                         Exit Try
  14.                     End If
  15.                 Next
  16.                 myArray(u) = jIn
  17.             Catch ex As Exception
  18.                 MessageBox.Show(ex.Message)
  19.             End Try
  20.         Next
  21.  
Nov 25 '08 #2
jac130
18 New Member
I'm a bit confused by your code, and some of the terms you use.
Dim j As Integer
For j = 0 To i - 1
If myArray(j) = jIn Then
MessageBox.Show ("Value is there")
u = 0
Exit Try
End If
this is the portion of the code searching the array, right? I should also mention, that i think it has to go inside another for loop.
Nov 25 '08 #3
rpicilli
77 New Member
@jac130
No problem. Try to understand now. If is still any problem just let me know.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  Dim iMyNumberOfArrayItems As Integer = 10 
  3.         Dim myArray(10) As String 
  4.         For iLoopAllArray As Integer = 0 To iMyNumberOfArrayItems
  5.             Dim sUserEntry As String 
  6.             sUserEntry = InputBox("Type Enter with no value to leave or Enter data: ") 
  7.             Try 
  8.                 If sUserEntry = "" Then Exit Sub 
  9.                 Dim j As Integer 
  10.                 For j = 0 To iMyNumberOfArrayItems - 1 
  11.                     If myArray(j) = sUserEntry Then 
  12.                         MessageBox.Show("Value is there") 
  13.                         iLoopAllArray = 0 
  14.                         Exit Try 
  15.                     End If 
  16.                 Next 
  17.                 myArray(iLoopAllArray) = sUserEntry 
  18.             Catch ex As Exception 
  19.                 MessageBox.Show(ex.Message) 
  20.             End Try 
  21.         Next 
  22.  
  23.  

Good luck
Nov 26 '08 #4

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

Similar topics

9
2117
by: Nathan Rose | last post by:
Here's my problem. I am reading from a text file using this: if (!file_exists($file)) { echo "Don't exist\n"; return false; } $fd = @fopen($file, 'r'); if (!is_resource($fd))
4
1969
by: Vinc_get31 | last post by:
Hi everyone! I have 2 matrices : The 1 is smaller than the 2. I would like to select in the 2nd only lines which correspond to couples of 1st... Is that possible? And how? However, I need a very optimized code, because I work with very very big matrice (250000*3), and this operation had to be quick...
3
1936
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store objects of my classes Person(superclass), Student(inherit Person), Teacher(inherit Person) in that array. The name will be the unique key. These classes are all working ok. I want to be able to add, remove, find etc. objects. To all of this, I...
1
1665
by: romain.jouin | last post by:
Hi everyone, I just wanted to propose this piece of code which is searching recursively a value in an array... and let you indicate me if there is an error... function in_array_recursive($array, $val) { $r = false; if(is_array($array))
1
2284
by: Scott Handojo | last post by:
Lets say I have the following arrays X1 (1, 2, 7, 8) X2 (1, 2, 4, 6) X3 (1, 2, 3, 5) X4 (1, 3, 5) X5 (2, 3, 5) X6 (4, 5, 6, 8) My 'search array' is comprised of
8
1599
by: hothead098 | last post by:
ASSIGNMENT (4) USING AND MANIPUPATING ARRAYS (Chapter 10 material) For this assignment you are to: 1) Create and manage arrays a) One of type integers (containing 10 elements). b) One of type strings (containing 20 elements). c) One of type char (containing 30 elements).
12
3872
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that looked sensible, but it didn't work right. Here is a simple example of what I'm trying to accomplish: // I have a hardware peripheral that I'm trying to access // that has two ports. Each port has 10 sequential // registers. Create a...
2
1163
by: gonzocanuck | last post by:
Hi guys, I need some help performing a sort. I tried searching Google and Google Groups, but maybe I'm asking the wrong question or using the wrong terminology, so I'll explain it. I have a database of a list of words, such as: horse dog
11
2045
by: jza | last post by:
Hello all, I am fairly new to c, coming from a Java background. I am working on a mathematical program and I have a function that needs to return a 2-d array. After some web searching, I have determined that in c, it is better to just pass the array in the function. Since arrays are passed by reference, I expected for the updated array to be passed back with the correct values filled in, however, only the first row of the array is returned...
0
8411
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.