Announcement

Collapse
No announcement yet.

Function questions.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Function questions.

    Please answer what questions you can:

    1) With EXEC functions, for example say:

    exec function MyExecFunction(int AnInteger)

    ...and the user types:

    MyExecFunction LOLOMG

    ...therefore doesn't supply a proper parameter, is there a way you can override the "error message" it gives the client?


    2) Say I have an array and I want to script a function such as:

    function MyFunction( int AnInteger)

    ...that would associate "AnInteger" with the same numbered array member. So if the function is called with "AnIntreger" paramater being 2, the function looks to MyArray(2) for data. Say this function displays messages. So "MyFunction" would be called with paramater "2" and look to MyArray(2) for the String information for the message to display. What is the best way to do this? Also, what is the most efficent way to detect if "AnInteger" is too high or low for the array (say the function is called with "AnInteger" paramater being 150! But the array only goes up to 5... so there is no 150...)

    3) Say a parent class has an array in it that goes up to 5 members. You want the child to only go up to 3. Is the easiest way to do this (and a proper method) just to make the "MyArray(4)" and "MyArray(5)" equal to "None"?


    Thanks

    #2
    Q1.
    You could try this:

    Code:
    exec function MyExecFunction(int AnInteger)
          if (IsNumeric(AnInteger)) {
               // Code goes here
          }
          //Other wise Exit
    Q2.
    You would use the switch command:
    Code:
    if (AnInteger <= MyArray.Length) {
      switch( AnInteger ){
          case 1: MyString=MyArray(AnInteger);
          case 2: MyString=MyArray(AnInteger);
          case 3: MyString=MyArray(AnInteger);
          case 4: MyString=MyArray(AnInteger);
      }
    }
    Q3. Simply stop a 3, 4 and 5 will not matter.
    Code:
    if (AnInteger < 4) {
      switch( AnInteger ){
          case 1: MyString=MyArray(AnInteger);
          case 2: MyString=MyArray(AnInteger);
          case 3: MyString=MyArray(AnInteger);
      }
    }

    Comment


      #3
      I'm good so far. Thanks, just one thing about Question 3:

      ...but say the length of that array was also a key role in my code. So the extra existing ones actually DO matter...

      What is the suggested way to make them non-existant?

      Thx in advance

      Comment


        #4
        If the parent class has defined an array of 10 elements, it is not possible that I know of, to redefine the array in the sub class.
        Because the sub class is using the parent array.

        Why would you need to redefine the array? My third example should be fine if your not going to be using the last two array elements. and if you are then you can.

        Comment

        Working...
        X