www.webdeveloper.com
Results 1 to 5 of 5

Thread: just a logical question

  1. #1
    Join Date
    Feb 2005
    Location
    Middle Village, NY
    Posts
    203

    just a logical question

    ive never done anything like this before, so maybe someone can help me out with some logic instead of code. ok, so if a user inputs(in my program) lets say a specific command with parameters. for example: fruit(apple,orange,berry); how can i check that there are parameters specified. so if a user enters fruit(); with no parameters, return an error. and if parameters are present, split them up. can someone help me out?
    ...?

  2. #2
    Join Date
    Apr 2005
    Location
    Perth, Australia
    Posts
    340
    deleted, double post.
    Last edited by Waylander; 12-11-2005 at 10:08 PM.
    Perth Web Development
    Web Developer
    Perth, Western Australia

  3. #3
    Join Date
    Apr 2005
    Location
    Perth, Australia
    Posts
    340
    Im not sure exactly what you mean, if your talking about directly inputing the command as text read it as a string and parse the text... I would replace each bracket comma and semi-colon with a space character, and then use the array split method to split the string into an array. The first index would be the function name and the rest would be the parameters, it would work well too because double or more occurances of the split character dont match... there has to be something else between them so once all the syntax is out of the way you would only get the important stuff.

    If you mean in code sense like if you were setting the text for the contents of the parameters from inside text fields or something then it would be better and easier to validate the gui itself rather than to check for it later within the code.

    Waylander.
    Last edited by Waylander; 12-11-2005 at 10:15 PM.
    Perth Web Development
    Web Developer
    Perth, Western Australia

  4. #4
    Join Date
    Feb 2005
    Location
    Middle Village, NY
    Posts
    203
    i understand what your saying. i will try it out tomorow. thanks again.
    ...?

  5. #5
    Join Date
    Apr 2005
    Location
    Perth, Australia
    Posts
    340
    If you want to call a method based on user input as in something from a text box which is put into your application at run time after the classes are compiled you will need to use reflection to look for the class and method names, the stuff can get fairly tricky..

    The class is java.lang.reflect, I would suggest reading the api.

    Waylander
    Last edited by Waylander; 12-12-2005 at 02:07 PM.
    Perth Web Development
    Web Developer
    Perth, Western Australia

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles