Results 1 to 7 of 7

Thread: why is this not working?{resolved}

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Resolved why is this not working?{resolved}

    I have a JtextArea named textArea2 and I want to search for text and then select it.
    My code is not working and I don't know what could possibly be wrong with it.

    Code:
     String textSearch = JOptionPane.showInputDialog("Enter a string to search for");
    	int left = textArea2.indexOf(textSearch);
    	int right = textArea2.lastIndexOf(textSearch);
                    textArea2.select(left,right);
    Last edited by System_Error; Nov 18th, 2004 at 06:19 PM.

  2. #2

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    I get 2 errors saying:

    Cannot resolve symbol
    method indexOf(String);

    Cannot resolve symbol
    method lastIndexOf(String);

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    textArea2 is a JTextArea, not a String.

    Code:
    String val = textArea2.getText();
    int left = val.indexOf(searchString);
    int right = left + searchString.length();
    textArea2.setSelectionStart(left);
    textArea2.setSelectionEnd(right);
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    Thank you so much. I was starting to go crazy with this problem.

  5. #5
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    It's funny how VB always confuses people when moving to a new language. In VB, it wouldn't have sent the object itself, like in java, but it would have called a standard sub, the text() sub. This, although it's made to save time, is a really bad thing, because it often confuses new programmers to think that's the way of doing things. It's especially hard to move on to OOP when you've been doing VB for a while...

    Just my 2 cents, hehe
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Well, OOP is OOP and Procedural Programming is Procedural Programming. The shift from one to the other is confusing and often leads to bad design, but that's not only VB's fault - the switch from C to C++ has similar problems.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    Originally posted by CornedBee
    Well, OOP is OOP and Procedural Programming is Procedural Programming. The shift from one to the other is confusing and often leads to bad design, but that's not only VB's fault - the switch from C to C++ has similar problems.
    Agreed, but VB still does have a way of hiding certain things, that the user should be aware of. Though this is to increase user friendlyness, it does lead to confusion. If you understand WHY 2 + 2 = 4, you can determine that 2 + 3 = 5, but if you just take that 2 + 2 will always equal 4, you have no way of knowing what 2 + 3 is. That was generally my experience when moving on...
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

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