Re: Boolean logic on strings?
From: Bob Butler (tiredofit_at_nospam.com)
Date: 11/15/04
- Next message: DIOS: "Re: Feedback on recursive file search..."
- Previous message: Andy: "RE: vbscript to change and reset permissions on folders on a SAN"
- In reply to: Rex Shudde: "Boolean logic on strings?"
- Next in thread: Larry Serflaten: "Re: Boolean logic on strings?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 15 Nov 2004 10:05:29 -0800
"Rex Shudde" <0024p@vm1.cc.nps.navy.mil> wrote in message
news:O0zRLuzyEHA.1296@TK2MSFTNGP10.phx.gbl
> Is there any way to do Boolean logic on *long* strings in VB6? For
> example, given the two strings
> x$ = "1000010000"
> y$ = "0001010010"
> I would like to set
> z$ = x$ Or y$
> which should result in
> z$ = "1001010010"
> not
> z$ = "1000339802"
>
> Also setting
> w$ = x$ And y$
> should result in
> w$ = "0000010000"
> not
> w$ = "680208"
>
> The VB Help file, when looking under the AND or OR logical operators,
> says that the expressions must be numeric, but I get the same results
> whether numeric or string. Also, these results are contrary to the
> truth tables given in the Help file.
>
> I need to perform these logical operations on 0/1 strings of length
> 100 or greater. Any help would be appreciated.
You are getting the starnge results because VB is converting the strings to
numbers, doing the And or Or operation and then converting the result back
to a string. To avoid that you'll need to loop through the characters and
doing each byte individually
z=space$(len(x))
for i=1 to len(x)
mid$(z,i,1)=cstr(clng(mid$(x,i,1)) Or clng(mid$(y,i,1)))
next
-- Reply to the group so all can participate VB.Net... just say "No"
- Next message: DIOS: "Re: Feedback on recursive file search..."
- Previous message: Andy: "RE: vbscript to change and reset permissions on folders on a SAN"
- In reply to: Rex Shudde: "Boolean logic on strings?"
- Next in thread: Larry Serflaten: "Re: Boolean logic on strings?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|