Solved

Tricky Problem in Visual Basic

Posted on 2002-06-05
8
201 Views
Last Modified: 2013-11-25
Hi,

I have 2 variables kept in string value

strVar1 = "010101010110101.......... " 88 characters
strVar2 = "101001111111111........... " 88 characters

Is there any way of directly OR'ing the values without
writing a function and taking each digit in array and OR'ing

Result should be "11110111111......... "

Thanks,
0
Comment
Question by:Pankaj27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 7055944
Simply put, no as there is no intrinsic Binary conversion. Your number anyway would be of the order of  1.54742504910673E+26 so that would be a pain to convert to a decimal or double. This function will do the trick pretty quickly.

Private Sub Command2_Click()
    strVar1 = "010101010110101" '88 characters
    strVar2 = "101001111111111" '88 characters
    MsgBox MyOr(strVar1, strVar2)
End Sub

Private Function MyOr(ByVal BinString1 As String, ByVal BinString2 As String) As String
    Dim strResult As String
    Dim intPos As Integer
    For intPos = 1 To Len(BinString1)
        strResult = strResult & (CInt(Mid(BinString1, intPos, 1)) Or CInt(Mid(BinString2, intPos, 1)))
    Next
    MyOr = strResult
End Function
0
 
LVL 1

Author Comment

by:Pankaj27
ID: 7055969
yes TimCottee,

I have done the Same using Function. But I wanted to avoid the looping during the Or'ing activity (88 times in my case) as this function in turn is called for lot many time depending upon the data coming from server.

0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7055978
Well without being able to convert the binary into a number of some datatype or other which you can then do the OR function on directly there is little option. You may be able to create a C++ program (standard dll) that can take your strings and convert to numbers then perform the OR function on the result and return it as a string but in straight VB I don't see an alternative I am afraid.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 7055995
your only hope would be to break the 88 character string of Binary digits into 3 LONGS (32 bits each - totakl allows up to 96 bits), then you could OR the corresponding pieces....That might offer a more satisfactory approach.

Arthur Wood
0
 
LVL 3

Expert Comment

by:MCummings111400
ID: 7056201
Pankaj27,
   Have you profiled your application to see how long this routine is taking to perform your operation? I doesn't seem like this would eat up that much time, as compared to converting to a numeric format , OR'ing, then converting back.
0
 
LVL 3

Expert Comment

by:MCummings111400
ID: 7056209
Second,
    Would it be possible to break the string down into multiples of 16, or 32? Is 88 characters coming from the server at a time?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7057556
hearing...
0
 
LVL 1

Accepted Solution

by:
BabyFace earned 50 total points
ID: 7058032
There is not much you can do. A literal "1" is not a 1, likewise for "0". The following code may help you. It is capable of ORing two strings of length 1,000,001 in 0.453125 seconds on a P4 1.5 Ghz. This is not much computing time... Hope you could use it.

Dim s1 As String
Dim s2 As String
Dim s3 As String
Dim b1() As Byte
Dim b2() As Byte
Dim b3() As Byte
Dim i As Long
s1 = "010101010110101"
s2 = "101001111111111"
b1 = StrConv(s1, vbFromUnicode)
b2 = StrConv(s2, vbFromUnicode)
ReDim b3(UBound(b1))
For i = 0 To UBound(b1)
    If b1(i) = 49 Or b2(i) = 49 Then
        b3(i) = 49
    Else
        b3(i) = 48
    End If
Next i
s3 = StrConv(b3, vbUnicode)
Debug.Print s3
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question