A Quick One 
Author Message
 A Quick One

myarray= array("a","b","c","d","e","f","g","h","i","j")
findpos = -1
findstr = "e"
for n = 0 to ubound(myarray)
  if myarray(n) = findstr then
    findpos = n
    exit for
  end if
next

if findpos > -1 then
  msgbox findstr & " found at index " & findpos
else
  msgbox findstr & " not found"
end if

--
Michael Harris

  What's the VB function for finding the location of a string in an array?
  myarray=("a","b","c","d","e","f","g","h","i","j")
  If I'm looking for "e", I want 4 returned.

  Sent via Deja.com http://www.*-*-*.com/
  Before you buy.



Sat, 15 Jun 2002 03:00:00 GMT  
 A Quick One
What's the VB function for finding the location of a string in an array?
myarray=("a","b","c","d","e","f","g","h","i","j")
If I'm looking for "e", I want 4 returned.

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 16 Jun 2002 03:00:00 GMT  
 A Quick One
If you implemented the characters in a string, you could short cut

CONST MYSTRINGS="abcdefghi"
Pos = Instr(MYSTRINGS, "e")    ' should return 5

Quote:

> What's the VB function for finding the location of a string in an array?
> myarray=("a","b","c","d","e","f","g","h","i","j")
> If I'm looking for "e", I want 4 returned.

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Mon, 17 Jun 2002 03:00:00 GMT  
 A Quick One
It's implemented as an array.  I have a series of questions stored in a
database and each question has a name.  The names of the questions are
stored in the array.  After supplying the name I want to find out its
location in the array.  I expected there to be a Find or search or
Locate function.  My array is about 70 long.  I'm lucky it's not a lot
longer.



Quote:
> If you implemented the characters in a string, you could short cut

> CONST MYSTRINGS="abcdefghi"
> Pos = Instr(MYSTRINGS, "e")    ' should return 5




Quote:
> > What's the VB function for finding the location of a string in an
array?
> > myarray=("a","b","c","d","e","f","g","h","i","j")
> > If I'm looking for "e", I want 4 returned.

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Mon, 17 Jun 2002 03:00:00 GMT  
 A Quick One

Why not use a Scripting.Dictionary object instead of arrays?

One would hold the questions, indexed by (string) name.  The other would hold the answers indexed by question name.  

Or use one dictionary indexed by question name where each dictionary item is a 2 element array with element 0 the question text and element 1 the answer.  

Or...

--
Michael Harris

  It's implemented as an array.  I have a series of questions stored in a
  database and each question has a name.  The names of the questions are
  stored in the array.  After supplying the name I want to find out its
  location in the array.  I expected there to be a Find or search or
  Locate function.  My array is about 70 long.  I'm lucky it's not a lot
  longer.



  > If you implemented the characters in a string, you could short cut
  >
  > CONST MYSTRINGS="abcdefghi"
  > Pos = Instr(MYSTRINGS, "e")    ' should return 5
  >


  > > What's the VB function for finding the location of a string in an
  array?
  > > myarray=("a","b","c","d","e","f","g","h","i","j")
  > > If I'm looking for "e", I want 4 returned.
  > >
  > >
  > >
  > > Sent via Deja.com http://www.deja.com/
  > > Before you buy.
  >
  >

  Sent via Deja.com http://www.deja.com/
  Before you buy.



Mon, 17 Jun 2002 03:00:00 GMT  
 A Quick One
The dictionary approach is a good one.  The only problem that's come up
is the dictionary is defined during the retrieval of the data from a
database.  After I populate it, I close the database and open up others
to retrieve other data.  At the end of it all I need to use the data
from the dictionary.  Apparently the keys remain but the items
disappear after I close the database.  Since I don't totally understand
dictionaries, the items were a pointer to the rs() field in the
database which couldn't be resolved after the database was closed.  So
I stored the data in an array and populated the dictionary after the db
was closed.  It seems to work now.  Thanks



Quote:
> This is a multi-part message in MIME format.

> ------=_NextPart_000_0452_01BF52BF.092DF060
> Content-Type: text/plain;
>    charset="Windows-1252"
> Content-Transfer-Encoding: quoted-printable

> Why not use a Scripting.Dictionary object instead of arrays?

> One would hold the questions, indexed by (string) name.  The other
would =
> hold the answers indexed by question name. =20

> Or use one dictionary indexed by question name where each dictionary =
> item is a 2 element array with element 0 the question text and
element 1 =
> the answer. =20

> Or...

> --=20
> Michael Harris



>   It's implemented as an array.  I have a series of questions stored
in =
> a
>   database and each question has a name.  The names of the questions
are
>   stored in the array.  After supplying the name I want to find out
its
>   location in the array.  I expected there to be a Find or search or
>   Locate function.  My array is about 70 long.  I'm lucky it's not a
lot
>   longer.



>   > If you implemented the characters in a string, you could short cut

>   > CONST MYSTRINGS=3D"abcdefghi"
>   > Pos =3D Instr(MYSTRINGS, "e")    ' should return 5



>   > > What's the VB function for finding the location of a string in
an
>   array?
>   > > myarray=3D("a","b","c","d","e","f","g","h","i","j")
>   > > If I'm looking for "e", I want 4 returned.

>   > > Sent via Deja.com http://www.deja.com/
>   > > Before you buy.

>   Sent via Deja.com http://www.deja.com/
>   Before you buy.

> ------=_NextPart_000_0452_01BF52BF.092DF060
> Content-Type: text/html;
>    charset="Windows-1252"
> Content-Transfer-Encoding: quoted-printable

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML><HEAD>
> <META content=3D"text/html; charset=3Dwindows-1252" =
> http-equiv=3DContent-Type>
> <META content=3D"MSHTML 5.00.2919.6307" name=3DGENERATOR>
> <STYLE></STYLE>
> </HEAD>
> <BODY bgColor=3D#ffffff>
> <DIV><FONT size=3D2>Why not use a Scripting.Dictionary object instead
of =

> arrays?</FONT></DIV>
> <DIV>&nbsp;</DIV>
> <DIV><FONT size=3D2>One would hold the questions, indexed by (string)
=
> name.&nbsp;=20
> The other would hold the answers indexed by question name.&nbsp; =
> </FONT></DIV>
> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT size=3D2>Or use one dictionary indexed by question name
where =
> each=20
> dictionary item is a 2 element array with element 0 the question text
=
> and=20
> element 1 the answer.&nbsp; </FONT></DIV>
> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT size=3D2>Or...</FONT></DIV>
> <DIV><BR>-- <BR>Michael Harris</DIV>
> <DIV>&nbsp;</DIV>
> <DIV><BR>&nbsp;</DIV>
> <BLOCKQUOTE=20
> style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-
RIGHT: =
> 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
>   <DIV>&lt;<A =


>   =



- Show quoted text -

Quote:
> m</A>...</DIV>It's=20
>   implemented as an array.&nbsp; I have a series of questions stored
in=20
>   a<BR>database and each question has a name.&nbsp; The names of the =
> questions=20
>   are<BR>stored in the array.&nbsp; After supplying the name I want
to =
> find out=20
>   its<BR>location in the array.&nbsp; I expected there to be a Find
or =
> search=20
>   or<BR>Locate function.&nbsp; My array is about 70 long.&nbsp; I'm =
> lucky it's=20
>   not a lot<BR>longer.<BR><BR>In article &lt;<A=20
>   =



Quote:
> q.edu.au</A>&gt;,<BR>&nbsp;=20
>   "Chui Tey" &lt;<A =


> could short=20
>   cut<BR>&gt;<BR>&gt; CONST MYSTRINGS=3D"abcdefghi"<BR>&gt; Pos =3D =
> Instr(MYSTRINGS,=20
>   "e")&nbsp;&nbsp;&nbsp; ' should return 5<BR>&gt;<BR>&gt; &lt;<A=20

wrote =
> in=20
>   message<BR><A=20
>   =


o=

- Show quoted text -

Quote:
> m</A>...<BR>&gt;=20
>   &gt; What's the VB function for finding the location of a string
in=20
>   an<BR>array?<BR>&gt; &gt;=20
>   myarray=3D("a","b","c","d","e","f","g","h","i","j")<BR>&gt; &gt; If
=
> I'm looking=20
>   for "e", I want 4 returned.<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; =
> &gt;<BR>&gt;=20
>   &gt; Sent via Deja.com <A=20
>   href=3D"http://www.deja.com/">http://www.deja.com/</A><BR>&gt; &gt;
=
> Before you=20
>   buy.<BR>&gt;<BR>&gt;<BR><BR><BR>Sent via Deja.com <A=20
>   href=3D"http://www.deja.com/">http://www.deja.com/</A><BR>Before
you=20
> buy.</BLOCKQUOTE></BODY></HTML>

> ------=_NextPart_000_0452_01BF52BF.092DF060--

Sent via Deja.com http://www.deja.com/
Before you buy.


Tue, 18 Jun 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Very quick one: Syntax for password????

2. quick one

3. Quick one!

4. quick one (TextTransfer method)

5. Quick One

6. Oracle Newbie (coupla quick ones!)

7. Quick One!!!!

8. quick one

9. username (quick one)

10. One More Quick Question...

11. ASP.NET : one quick question

12. Quick Database question - Easy one for you experienced programmers, but out my hands - Please help

 

 
Powered by phpBB® Forum Software