View Single Post
  #1  
Unread 07-06-2011, 02:35 PM
Fortunis's Avatar
Fortunis Fortunis is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Mar 2011
Location: Leeds, UK
Posts: 72
ListBox number/string error (Help!) [SOLVED]

Heres the scenerio. Im making a Listbox for user input. The input range is 0-9999 and everything works according to plan with this until the next step.
Im placing an if-then-else-end statement in to check that no other characters/letters are used, for the listbox to be wiped clean and a message to the user that they inputted illegal data, but im getting 'attempt to compare number with nil' error.

Is there anything i can do to either allow the lua to ignore the error and carryon with the if-then-else-end statement or allow it to not do an error at all?

heres the code i have at the moment-

Code:
     ImageAmountInput:SetWantsKeyEvents( true );
     
     ImageAmountInput.KeyDown = function( sender, args )
        
        if args.Action == 162 then
            OpWindow:Activate();
            ImageAmountInput:SetSelection( 1, 4 );
            IAI = ImageAmountInput:GetText();
            IAI = tonumber( IAI );

            if  IAI >= 0 and IAI <= 9999 then -- ERROR produced here if non-numerical characters are used in user input box.
                ImageAmountInput:SetSelection( 0, 0 );
            else
                ImageAmountInput:SetText( "" );
                print ( "You entered an illegal entry" );
            end

        end

     end
__________________
Author of Mouse Cursor Highlighter Advanced

Last edited by Fortunis : 07-06-2011 at 03:14 PM.
Reply With Quote