Using array like pattern matching?

Reply

Join Date: Jul 2008
Posts: 36
Reputation: Teropod is an unknown quantity at this point 
Solved Threads: 6
Teropod Teropod is offline Offline
Light Poster

Using array like pattern matching?

 
0
  #1
Jul 15th, 2008
Is there any way how i could compare arrays like pattern matching or should i write my own code?

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 95
Reputation: manoshailu is an unknown quantity at this point 
Solved Threads: 9
manoshailu's Avatar
manoshailu manoshailu is offline Offline
Junior Poster in Training

Re: Using array like pattern matching?

 
0
  #2
Jul 16th, 2008
Hi,

You can use Like Operator or StrComp Function for Pattern Matching in Array Variable or any other Variable. You can compare the Values like below Given:

1) Bring the Array Values in loop and check the Value like this

IF a(I) LIKE "*a*" THEN
-----
-----
END IF
You can refer more about the Like Operator in

http://msdn.microsoft.com/en-us/libr...xw(VS.71).aspx


2) You can use StrComp Function like this

IF StrComp(a(I), "a") THEN
-----
-----
END IF



Shailaja



Originally Posted by Teropod View Post
Is there any way how i could compare arrays like pattern matching or should i write my own code?

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 36
Reputation: Teropod is an unknown quantity at this point 
Solved Threads: 6
Teropod Teropod is offline Offline
Light Poster

Re: Using array like pattern matching?

 
0
  #3
Jul 16th, 2008
And there is no way to find "pattern" of one array in other? something like a(0) = b, a(1) = c and b(0) = a, b(1) = b, b(2) = c, b(3) = d.

bool = a like *b*

???
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 95
Reputation: manoshailu is an unknown quantity at this point 
Solved Threads: 9
manoshailu's Avatar
manoshailu manoshailu is offline Offline
Junior Poster in Training

Re: Using array like pattern matching?

 
0
  #4
Jul 18th, 2008
hi,

You can do like below when using the variable instead of values.


IF a(0) like "*" & b & "*" THEN
-----------
-----------
END IF


Shailaja

Originally Posted by Teropod View Post
And there is no way to find "pattern" of one array in other? something like a(0) = b, a(1) = c and b(0) = a, b(1) = b, b(2) = c, b(3) = d.

bool = a like *b*

???
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 36
Reputation: Teropod is an unknown quantity at this point 
Solved Threads: 6
Teropod Teropod is offline Offline
Light Poster

Re: Using array like pattern matching?

 
0
  #5
Jul 18th, 2008
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. Dim A(2) As String
  3. Dim B(4) As String
  4.  
  5. A(0) = 3
  6. A(1) = 2
  7. A(2) = 67
  8.  
  9. B(0) = 89
  10. B(1) = 3
  11. B(2) = 2
  12. B(3) = 67
  13. B(4) = 99
  14.  
  15. If A(0) Like "*" & B & "*" Then
  16. MsgBox "ahoy"
  17. End If
  18.  
  19. End Sub

It looks like ill have to use loops, because these is not working. And i don't need one value i need to find is one entire dimension of array in other. I am afraid loops will last too long.

Originally Posted by manoshailu View Post
hi,

You can do like below when using the variable instead of values.


IF a(0) like "*" & b & "*" THEN
-----------
-----------
END IF


Shailaja
Last edited by Teropod; Jul 18th, 2008 at 4:11 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 95
Reputation: manoshailu is an unknown quantity at this point 
Solved Threads: 9
manoshailu's Avatar
manoshailu manoshailu is offline Offline
Junior Poster in Training

Re: Using array like pattern matching?

 
0
  #6
Jul 18th, 2008
hi,

Array can be used only by loops and that could be very if u understand wel.
Try the below coding and if you have any doubts in below codings you can ask me i will explain u in detail.

In Below coding, i had used nested loop (i.e). Loop is nothing but Loop is to make a rotation until it gets the end value. If it is Nested Loop then 2 loops used (i.e)
For i = 0 to 10 'Outer Loop
For j = 0 to 5 'Inner Loop
---------
Next
Next

Outer Loop have the value and comes to the inner loop. Then the inner loop starts the rotation until it getting the end value after that move to the outer loop and goes on until the outer loop ends. Simply we can say one element of outer loop compare with all element in the inner loop.

If u understand the loop concept clearly then only u can do anything in any language.





[QUOTE=Teropod;650258]
Private Sub Command1_Click()
Dim A(2) As String
Dim B(4) As String
Dim intI as Integer       'intI Variable for A()
Dim intj as Integer       'intJ Variable for B()

    A(0) = 3
    A(1) = 2
    A(2) = 67
    
    B(0) = 89
    B(1) = 3
    B(2) = 2
    B(3) = 67
    B(4) = 99
    
 'Nested Loop
     For intI = 0 to Ubound(A)
           For intJ = 0 to Ubound(B)  'Loop works until the size of the B() Array
                If A(intI) Like "*" & B(intJ) & "*" Then  'A() compared with the all element in the B() 
                      MsgBox A(intI)
                End If
          Next
     Next  

    
End Sub

Shailaja

Originally Posted by Teropod View Post
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. Dim A(2) As String
  3. Dim B(4) As String
  4.  
  5. A(0) = 3
  6. A(1) = 2
  7. A(2) = 67
  8.  
  9. B(0) = 89
  10. B(1) = 3
  11. B(2) = 2
  12. B(3) = 67
  13. B(4) = 99
  14.  
  15. If A(0) Like "*" & B & "*" Then
  16. MsgBox "ahoy"
  17. End If
  18.  
  19. End Sub

It looks like ill have to use loops, because these is not working. And i don't need one value i need to find is one entire dimension of array in other. I am afraid loops will last too long.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 36
Reputation: Teropod is an unknown quantity at this point 
Solved Threads: 6
Teropod Teropod is offline Offline
Light Poster

Re: Using array like pattern matching?

 
0
  #7
Jul 18th, 2008
Tanks but i wanted to avoid that because i am using 3d arrays with 100+ values per one i was hoping i could do it faster.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 95
Reputation: manoshailu is an unknown quantity at this point 
Solved Threads: 9
manoshailu's Avatar
manoshailu manoshailu is offline Offline
Junior Poster in Training

Re: Using array like pattern matching?

 
0
  #8
Jul 22nd, 2008
Hi,

Try this one. I think this may be useful to u.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. Dim A(2) As String
  3. Dim B(4) As String
  4. Dim C as String
  5. A(0) = 3
  6. A(1) = 2
  7. A(2) = 67
  8.  
  9. B(0) = 89
  10. B(1) = 3
  11. B(2) = 2
  12. B(3) = 67
  13. B(4) = 99
  14.  
  15. IF UBound(Filter(B, A(0), True, vbTextCompare)) >-1 THEN
  16. C=Filter(B, A(0), True, vbTextCompare)
  17. MsgBox C(0)
  18. End If
  19.  
  20. End Sub

To Know more

http://www.vb6.us/tutorials/vb-strin...it-join-filter


Shailaja

Originally Posted by Teropod View Post
Tanks but i wanted to avoid that because i am using 3d arrays with 100+ values per one i was hoping i could do it faster.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC