Re: Option Compare Statement

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



As always, thanks Mike. My arrays are always either double, or strings, and
both arrays are always the same type. I guess, one thing I can do, which is
the easiest (but not the cleanest code) is to have the exact routines in two
different modules, one with option compare binary, and one with option
compare text, (of course with two different names). Then depending on the
user's choice, call the appropriate routine. This way, I do not have to
mess with my code.

Bob

"MikeD" <nobody@xxxxxxxxxxx> wrote in message
news:O%231$cdcHJHA.4232@xxxxxxxxxxxxxxxxxxxxxxx

"Bob" <someonw@xxxxxx> wrote in message
news:ejRt79OHJHA.4884@xxxxxxxxxxxxxxxxxxxxxxx
Hi Everyone:

I had posted this message in another newgroup, and it was suggested that
I post it here. So, sorry about the double posting.

Your first post regarding this in the vb.controls newsgroup was,
technically, off-topic because your question has nothing to do with
controls. But it was hardly the most off-topic question posted to any of
these newsgroups. vb.general.discussion gets the most traffic. So, it's
usually the best choice. You might *cross-post* your message to other
newsgroups too (on MS's newserver; personally, I hate it when people
crosspost to non-MS newsgroups) if your question fits that particular
newsgroup as well. For example, if your question had been about a control
array, it'd have been perfectly appropriate in the vb.controls newsgroup.


In VB 6.0, I have two variant arrays, that may either contain doubles or
strings, let's say A and B. Then I want to compare their values. For
example,
If A(i)<B(i) then
c=c+1
else
c=c+2
endif

Now, on my form, I have a checkbox that asks the user if they want the
comparison to be case sensitive. So, here is my question.
1- Can I somehow achieve this by using the Option Compare. remember, the
user chooses the type of comparison.
2- if not, is the Instr statement my only option? If so, how do I handle
doubles? Do, I have to check the data type for all members, if they are
all doubles choose <. otherwise choose Instr? Or is there a better way
of doing this.


Are both arrays always going to be of the same data type? I mean, one's
not going to be of type Double and the other String, right? They're either
both going to be Double or both going to be String?

Also, be aware that comparing Doubles is not always so straight-forward
due to innaccuracies of representing a Double. If you're doing
calculations prior to the comparison, you could end up with something like
comparing 1.00000001 to 1.0 (where the expection might be 1.0 compared to
1.0...or equality)

--
Mike
Microsoft MVP Visual Basic




.



Relevant Pages

  • Re: compare two dynamic string
    ... >>> How compare two dynamic string? ... what you've got here is arrays of characters ... instead if strings. ... your question was how to compare them. ...
    (comp.lang.fortran)
  • Re: C++/CLI System::String question
    ... You should also be able to cast one or both of the strings to Object^ ... and compare that. ... Please reply only to the newsgroup. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Comparing to Arrays
    ... compare on each element. ... > I have two relatively large 1D arrays (I could make them into a two D ... > arrays contain a series of strings, with each string being exactly the ... > same length (in this case 18 characters). ...
    (microsoft.public.excel.programming)
  • Comparing Strings
    ... I have two arrays of strings, ... If I try to compare the first string in x, x, to the ...
    (comp.soft-sys.matlab)
  • Re: Cant remove duplicate values from an array
    ... I'm trying to compare two arrays of strings, and I need to remove all ... duplicate words from one of the arrays. ...
    (comp.lang.php)