473,323 Members | 1,560 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,323 software developers and data experts.

How to search array

So far I've been blessed with a whole-lotta nice help and explaining
in here, so I'll give it a go once again:
I have some difficulty searching an array.

I have a structure:

Public Structure Naturgas

Public Id As Integer
Public Fabrikat As String
Public Effekt As String

End Structure

This is assigned to an ArrayList called _naturgasList:

lst.Id = CType(reader(0).ToString, Integer)
lst.Fabrikat = reader(1).ToString
lst.Effekt = reader(2).ToString
_naturgasList.Add(lst)

Now, in _naturgasList I wish to look up Effekt via Id. How do I do
this?

The runtime content of the Array is at www.dbconsult.dk/db/array.jpg

Thanks in advance for any help.
Regards /Snedker
Jan 23 '07 #1
4 1195
On Tue, 23 Jan 2007 13:22:14 +0100, Morten Snedker
<morten_spammenot_ATdbconsult.dkwrote:

Ahaaaaaaaaaa! =B-)

First I didn't know how to work the array. Back-drilling was the
trick.

Then my array was empty. And of course it is - it should be, since the
page finished loading ages ago. :-)

The trick was to load it again:

SetNaturgas()

Dim s As String
Dim a As Naturgas

a = CType(_naturgasList(3), Naturgas)
s = a.Effekt

MsgBox(s)
Thanks for your help, Snedker.
Your're welcome, Snedker. Anytime.

Also thanks to all replies in between. :-)
/Snedker
Jan 23 '07 #2
Public Struct Naturgas
Public int Id;
Public string Fabrikat;
Public string Effekt;
End Structure

class SomeClass {
ArrayList _naturgasList = new ArrayList();

public void Add(Reader reader) { // or whatever the class of your reader
variable is
Naturgas lst = new Naturgas();
lst.Id = int32.Parse(reader[0].ToString());
lst.Fabrikat = reader[1].ToString();
lst.Effekt = reader[2].ToString();
_naturgasList.Add(lst);
}

public Naturgas FindEffektById(int Id) {
for (int i = 0, i < _natrugasList.Count, i++) {
if (_naturgasList[i].Id == Id) {
return _naturgasList[i].Effekt;
}
}
return null;
}
}

Something like that anyway.

Sorry, I don't do VB. It's a religious thing.
Peter
"Morten Snedker" <morten_spammenot_ATdbconsult.dkwrote in message
news:4t********************************@4ax.com...
So far I've been blessed with a whole-lotta nice help and explaining
in here, so I'll give it a go once again:
I have some difficulty searching an array.

I have a structure:

Public Structure Naturgas

Public Id As Integer
Public Fabrikat As String
Public Effekt As String

End Structure

This is assigned to an ArrayList called _naturgasList:

lst.Id = CType(reader(0).ToString, Integer)
lst.Fabrikat = reader(1).ToString
lst.Effekt = reader(2).ToString
_naturgasList.Add(lst)

Now, in _naturgasList I wish to look up Effekt via Id. How do I do
this?

The runtime content of the Array is at www.dbconsult.dk/db/array.jpg

Thanks in advance for any help.
Regards /Snedker

Jan 23 '07 #3
Ooops! Forgot the typecast. Got too used to generics.

Sorry
Peter

"Peter Bradley" <pb******@uwic.ac.ukwrote in message
news:e%****************@TK2MSFTNGP03.phx.gbl...
Public Struct Naturgas
Public int Id;
Public string Fabrikat;
Public string Effekt;
End Structure

class SomeClass {
ArrayList _naturgasList = new ArrayList();

public void Add(Reader reader) { // or whatever the class of your
reader variable is
Naturgas lst = new Naturgas();
lst.Id = int32.Parse(reader[0].ToString());
lst.Fabrikat = reader[1].ToString();
lst.Effekt = reader[2].ToString();
_naturgasList.Add(lst);
}

public Naturgas FindEffektById(int Id) {
for (int i = 0, i < _natrugasList.Count, i++) {
if (_naturgasList[i].Id == Id) {
return _naturgasList[i].Effekt;
}
}
return null;
}
}

Something like that anyway.

Sorry, I don't do VB. It's a religious thing.
Peter
"Morten Snedker" <morten_spammenot_ATdbconsult.dkwrote in message
news:4t********************************@4ax.com...
>So far I've been blessed with a whole-lotta nice help and explaining
in here, so I'll give it a go once again:
I have some difficulty searching an array.

I have a structure:

Public Structure Naturgas

Public Id As Integer
Public Fabrikat As String
Public Effekt As String

End Structure

This is assigned to an ArrayList called _naturgasList:

lst.Id = CType(reader(0).ToString, Integer)
lst.Fabrikat = reader(1).ToString
lst.Effekt = reader(2).ToString
_naturgasList.Add(lst)

Now, in _naturgasList I wish to look up Effekt via Id. How do I do
this?

The runtime content of the Array is at www.dbconsult.dk/db/array.jpg

Thanks in advance for any help.
Regards /Snedker


Jan 23 '07 #4
Which brings up two important points...

If he is using 2.0, he probably _should_ be using a generic....and

if he is using 2.0, he _could_ use a delegate to search through the
generic..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Peter Bradley" <pb******@uwic.ac.ukwrote in message
news:en**************@TK2MSFTNGP03.phx.gbl...
Ooops! Forgot the typecast. Got too used to generics.

Sorry
Peter

"Peter Bradley" <pb******@uwic.ac.ukwrote in message
news:e%****************@TK2MSFTNGP03.phx.gbl...
>Public Struct Naturgas
Public int Id;
Public string Fabrikat;
Public string Effekt;
End Structure

class SomeClass {
ArrayList _naturgasList = new ArrayList();

public void Add(Reader reader) { // or whatever the class of your
reader variable is
Naturgas lst = new Naturgas();
lst.Id = int32.Parse(reader[0].ToString());
lst.Fabrikat = reader[1].ToString();
lst.Effekt = reader[2].ToString();
_naturgasList.Add(lst);
}

public Naturgas FindEffektById(int Id) {
for (int i = 0, i < _natrugasList.Count, i++) {
if (_naturgasList[i].Id == Id) {
return _naturgasList[i].Effekt;
}
}
return null;
}
}

Something like that anyway.

Sorry, I don't do VB. It's a religious thing.
Peter
"Morten Snedker" <morten_spammenot_ATdbconsult.dkwrote in message
news:4t********************************@4ax.com.. .
>>So far I've been blessed with a whole-lotta nice help and explaining
in here, so I'll give it a go once again:
I have some difficulty searching an array.

I have a structure:

Public Structure Naturgas

Public Id As Integer
Public Fabrikat As String
Public Effekt As String

End Structure

This is assigned to an ArrayList called _naturgasList:

lst.Id = CType(reader(0).ToString, Integer)
lst.Fabrikat = reader(1).ToString
lst.Effekt = reader(2).ToString
_naturgasList.Add(lst)

Now, in _naturgasList I wish to look up Effekt via Id. How do I do
this?

The runtime content of the Array is at www.dbconsult.dk/db/array.jpg

Thanks in advance for any help.
Regards /Snedker


Jan 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.