473,883 Members | 1,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array.IndexOf - not working


This statement returns a -1, indicating "not found":
Find1 = Array.IndexOf(F ilesArray, "sa001")

But IndexOf on a specific item in that array returns a value of 26:
Find1 = FilesArray(2).I ndexOf("sa001")
This shows the value "sa001" is found in FilesArray.

Any suggestions why Array.IndexOf does not return a number (index of
item that has the value)?


Nov 21 '05
11 12868
Sorry for the delay. I did some performance testing, learning about
timespan and formatting the results.
If the array is very large, the "two array" method I described is

But the difference is subsecond even if the array has one million
Two array method, selecting "1000000" (one million) did it in 46 to 109
One array method did it in 531 to 875 milliseconds.

Selecting "10000" (ten thousand) was "zero" milliseconds in both
In my app, the array size is expected to be smaller than 10,000. So
there is no advantage for this app to use Array.IndexOf.

I discovered some interesting things about timespan - at least on my
The system reports zero if the number of ticks is less than 156250 (15
To test the result formatting, I needed to artificially increase the
timespan above 15 milliseconds.
I assume there is a good reason not to report the ACTUAL number of

The system reports timespan in increments of 156250 ticks.


Nov 21 '05 #11
Hello Al,

Don't you think it would be easier to use the Visual Basic function Filter?:

"Al" <al**********@h otmail.com> escribió en el mensaje news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
| This is how I changed the app, utilizing Array.IndexOf.
| One time steps:
| 1. Create the files array (as was done before).
| FilesArray = Directory.GetFi les(FolderName)
| Each item is a file name with path (e.g."C:\ImageP roject\sa001.ti f")
| 2. Create a mirror array FilesArray2 (additional step, but one-time).
| Using string.LastInde xOf in a For/Next loop, extract the file name
| (e.g. "sa001") from each FilesArray item. Both arrays have same index
| numbers.
| When user selects an item (e.g. clicks "Next" button):
| 3a. Data file (which may be sorted different ways) provides the file
| name ("e.g. "sa001").
| 3b. Use Array.IndexOf on FilesArray2 to find that item.
| 3c. Use that index on FilesArray to get the file path.
| 3d. Display image file.
| When array is 1000 or more, this should provide faster and more
| consistent performance than a For/Next loop. User may click "Next"
| button fast.
| Al
Nov 21 '05 #12

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

Similar topics

by: Treetop | last post by:
I cannot get this array to work. I want to have the game listed until the day after the event, then come off the list. function events() { var today = new Date(); var dayarray=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat") var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec
by: Shang Wenbin | last post by:
Hi, I use the following snip: myarray = new Array(2, 5, 9); var index = myarray.indexOf(2); but it is not workable, the debugger says array.indexOf is not a function.I use mozilla 1.7.10 Any suggestion?
by: Sueffel | last post by:
Okay, I can certinatly use a For..Next loop to find the specified info I need, but I'm thinking the BinarySearch will be faster, if I can get it working LOL Anyhew, got an array, may have 5 or 5,000 elements, and I need to find the string, say it's "Start here". I've tried this: Dim MyObj as Object = "Start Here" Dim I as Integer = System.Array.BinarySearch(MyArr,MyObj)
by: Larry | last post by:
I have a Byte Array Dim A1() as byte = {1,2,3,4,9,9,9,11,12,13,14,9,9,9} I want to find the location of the first occurance of the byte sequence {9,9,9}. Is there a built in Framework class that will do this easily? I've tried messing with Array.IndexOf but can't seem to get it to indicate where the byte sequnce starts.
by: Allen Maki | last post by:
Why can I get the index of the item of the array when I use string*, but can not get the index of the array when I use any other type (such as Int32)? This code will compile perfectly, but if I replace String* with Int32, the code would not compile? The code using String* type: #include "stdafx.h"
by: =?ISO-8859-1?Q?Jonathan_Gro=DF?= | last post by:
Hi everybody, in the sample below my programm gives a "Bus error" on the marked line. I don't get it why that happens. I followed the instructions in the C-FAQ. #include <math.h> #include <stdlib.h> #define dim 2
by: Morten71 | last post by:
I have a strange problem. I have a local string() var I populate this way: clmns() As String = {"InvoiceNo", "InvoiceDate"} When I call: Array.IndexOf(clmns,"InvoiceDate") I get 0 (zero) as expected. If I fetch the values from the web.config this way: clmns() As String =
by: eknee1417 | last post by:
' Determine what roles the selected user belongs to Dim strSelectedUserName As String = ddlUserList.SelectedValue Dim strSelectedUsersRoles() As String = Roles.GetRolesForUser(strSelectedUserName) Dim strRoleNames() As String = Roles.GetAllRoles.Clone ' Loop through the Repeater's Items and check or uncheck the checkbox as needed For Each ri As RepeaterItem In...
by: luftikus143 | last post by:
Hi there, I have an array, which stores in the first dimension a counter for the number of sets, and in the second the value: $value I found somewhere how to find min and max values in such an array: // find max and min value foreach( $value as $__vals )
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:
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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: 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: 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.