Results 1 to 16 of 16

Thread: Quick but meaningful question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2000
    Location
    Sugar Grove, IL
    Posts
    99

    Quick but meaningful question

    Or maybe not so meaningful. Anyways....

    If you have never coded in java or a similiar language subs and functions are generally seperated by the { and } characters. I was looking to see if anyone had code to match up these characters. In other words, if someone were to click on a text box on the { (open) character, I would like for the } (close) character to be selected as well.

    Anyone??
    In case of a water landing, my head may be used as a flotation device.

  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    What do you mean by selected? As in highlighted, for example when you do cut & paste?
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2000
    Location
    Sugar Grove, IL
    Posts
    99
    Mainly what I am looking for is some sort of sorting sequence that will match up the pairs of {'s and }'s. And save them in a type, lets say :

    Public type bracketPairs
    openBracketPosition as integer
    closeBracketPosition as integer
    end type

    When a matching pair is found, bracketPairs.openBracketPosition = location of open bracket and the same for closed bracket position. I am just having a hard time matching up the pairs.
    In case of a water landing, my head may be used as a flotation device.

  4. #4
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Question Question.

    Do you mean, for example, if you had the following string.
    int main
    {
    cout "Blah" << endl;
    for(int i=0;i<10;i++)
    {
    cout << i << endl;
    }
    return 0;
    }
    When you select the opening brace in a text box, all data between the opening, and matched up ending brace is selected? So if i selected the first brace, the following would be selected:
    cout "Blah" << endl;
    for(int i=0;i<10;i++)
    {
    cout << i << endl;
    }
    return 0;
    But if i selected the second brace, the following woulld be selected:
    cout << i << endl;
    Is this what you mean?
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  5. #5
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Use Instr.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2000
    Location
    Sugar Grove, IL
    Posts
    99
    Digital - exactly. But I am not worried about how to highlight them. I am just looking to locate matching pairs. Displaying or highlighting them is simple enough.
    In case of a water landing, my head may be used as a flotation device.

  7. #7
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    PosClose = 0

    ' some kind of loop (to parse all text)
    PosOpen = Instr(PosClose + 1, Text, "{")
    PosClose = Instr(PosOpen + 1, Text, "}")
    ' end loop
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2000
    Location
    Sugar Grove, IL
    Posts
    99
    Here, let me show what I have done so far.

    In a module:
    Public Type openBrackets
    position As Integer
    matchingClosed As Integer
    End Type

    Public Type closedBrackets
    position As Integer
    matchingOpen As Integer
    End Type

    Public oB() As openBrackets
    Public cB() As closedBrackets

    My parsing sub:

    Public Sub findBrackets()
    Dim x As Integer
    Dim y As Integer
    Dim xCount As Integer
    Dim yCount As Integer
    Dim startAt As Integer


    x = 1
    While InStr(x, RTB.Text, "{") > 0
    x = InStr(x, RTB.Text, "{")
    xCount = xCount + 1
    If xCount = 1 Then
    ReDim oB(1)
    Else
    ReDim Preserve oB(xCount)
    End If
    oB(xCount).position = x
    x = x + 1
    Wend
    x = 1
    While InStr(x, RTB.Text, "}") > 0
    x = InStr(x, RTB.Text, "}")
    yCount = yCount + 1
    If yCount = 1 Then
    ReDim cB(1)
    Else
    ReDim Preserve cB(yCount)
    End If
    cB(yCount).position = x
    x = x + 1
    Wend
    While allFilled = False 'all filled is a boolean function denoting the existance of a number in the .matchingOpen and .matchingClosed
    For x = 1 To UBound(oB) - 1
    If oB(x).matchingClosed = 0 Then
    For y = 1 To UBound(cB)
    If cB(y).position > oB(x).position And cB(y).matchingOpen = 0 Then
    If cB(y).position < oB(x + 1).position And cB(y).matchingOpen < 1 Then
    oB(x).matchingClosed = cB(y).position
    cB(y).matchingOpen = oB(x).position
    Exit For
    Else
    Exit For
    End If
    End If
    Next y
    End If
    Next x
    Wend
    End Sub
    In case of a water landing, my head may be used as a flotation device.

  9. #9
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Looks about right. Is it working?

    oh ps -- a good programming practice is to indent. everytime you enter a loop or if or whatever, add another space or tab in front of the lines:

    For I = 1 to 100000
    Msgbox I
    Next I
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  10. #10
    Just so others can read it...

    VB Code:
    1. Public Type openBrackets
    2.     position As Integer
    3.     matchingClosed As Integer
    4. End Type
    5.  
    6. Public Type closedBrackets
    7.     position As Integer
    8.     matchingOpen As Integer
    9. End Type
    10.  
    11. Public oB() As openBrackets
    12. Public cB() As closedBrackets
    13.  
    14. My parsing sub:
    15.  
    16. Public Sub findBrackets()
    17.     Dim x As Integer
    18.     Dim y As Integer
    19.     Dim xCount As Integer
    20.     Dim yCount As Integer
    21.     Dim startAt As Integer
    22.    
    23.    
    24.     x = 1
    25.     While InStr(x, RTB.Text, "{") > 0
    26.         x = InStr(x, RTB.Text, "{")
    27.         xCount = xCount + 1
    28.         If xCount = 1 Then
    29.             ReDim oB(1)
    30.         Else
    31.             ReDim Preserve oB(xCount)
    32.         End If
    33.         oB(xCount).position = x
    34.         x = x + 1
    35.     Wend
    36.     x = 1
    37.     While InStr(x, RTB.Text, "}") > 0
    38.         x = InStr(x, RTB.Text, "}")
    39.         yCount = yCount + 1
    40.         If yCount = 1 Then
    41.             ReDim cB(1)
    42.         Else
    43.             ReDim Preserve cB(yCount)
    44.         End If
    45.         cB(yCount).position = x
    46.         x = x + 1
    47.     Wend
    48.     While allFilled = False 'all filled is a boolean function denoting the existance of a number in the .matchingOpen and .matchingClosed
    49.         For x = 1 To UBound(oB) - 1
    50.             If oB(x).matchingClosed = 0 Then
    51.                 For y = 1 To UBound(cB)
    52.                     If cB(y).position > oB(x).position And cB(y).matchingOpen = 0 Then
    53.                         If cB(y).position < oB(x + 1).position And cB(y).matchingOpen < 1 Then
    54.                             oB(x).matchingClosed = cB(y).position
    55.                             cB(y).matchingOpen = oB(x).position
    56.                             Exit For
    57.                         Else
    58.                             Exit For
    59.                         End If
    60.                     End If
    61.                 Next y
    62.             End If
    63.         Next x
    64.     Wend
    65. End Sub

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2000
    Location
    Sugar Grove, IL
    Posts
    99
    Unfortunately, no. It gets stuck in a loop. Don't know why either. I know I can eventually solve thison my own, I was just hoping someone had already done a similiar routine and I could just borrow theirs.
    In case of a water landing, my head may be used as a flotation device.

  12. #12
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    If all filled is a function, it needs ():

    If allFilled() = true then

    etc.


    filburt1: tnx!
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  13. #13
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Which loop does it get stuck in?
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Nov 2000
    Location
    Sugar Grove, IL
    Posts
    99
    Thanks filburt, I swear that's what it looked like when I pushed post. he hehe
    In case of a water landing, my head may be used as a flotation device.

  15. #15
    Originally posted by X__man
    Thanks filburt, I swear that's what it looked like when I pushed post. he hehe
    I just quoted you and put [vbcode][/vbcode] tags around it.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Nov 2000
    Location
    Sugar Grove, IL
    Posts
    99
    It never leaves the While allFilled = false.

    allFilled is a very simple function, checking to make sure that all types are filled, if they are not, it returns false.

    This is ultimately going to be a mIRC Script Editor.

    I'll include the sample script I am using.
    Attached Files Attached Files
    In case of a water landing, my head may be used as a flotation device.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width