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
3 1907
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 -
Dim i As Integer = 10
-
Dim myArray(10) As String
-
For u As Integer = 0 To i
-
Dim jIn As String
-
jIn = InputBox("Type Enter with no value to leave or Enter data: ")
-
Try
-
If jIn = "" Then Exit Sub
-
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
-
Next
-
myArray(u) = jIn
-
Catch ex As Exception
-
MessageBox.Show(ex.Message)
-
End Try
-
Next
-
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.
@jac130
No problem. Try to understand now. If is still any problem just let me know. -
-
Dim iMyNumberOfArrayItems As Integer = 10
-
Dim myArray(10) As String
-
For iLoopAllArray As Integer = 0 To iMyNumberOfArrayItems
-
Dim sUserEntry As String
-
sUserEntry = InputBox("Type Enter with no value to leave or Enter data: ")
-
Try
-
If sUserEntry = "" Then Exit Sub
-
Dim j As Integer
-
For j = 0 To iMyNumberOfArrayItems - 1
-
If myArray(j) = sUserEntry Then
-
MessageBox.Show("Value is there")
-
iLoopAllArray = 0
-
Exit Try
-
End If
-
Next
-
myArray(iLoopAllArray) = sUserEntry
-
Catch ex As Exception
-
MessageBox.Show(ex.Message)
-
End Try
-
Next
-
-
Good luck
Sign in to post your reply or Sign up for a free account.
Similar topics |
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))
|
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...
|
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...
|
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))
|
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
| |
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).
|
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...
|
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
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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();...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |