Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
UPdating Text Box - Page 2
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

Thread: UPdating Text Box

  1. #11
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    Quote Originally Posted by athenso View Post
    Code:
     Client C = Client.GetClients()[0];
                Player P;
    
                P = C.GetPlayer();
    
                int ms = 1000;
                System.Windows.Forms.Timer expTimer = new System.Windows.Forms.Timer();
    
                expTimer.Interval = ms;
                expTimer.Tick += (sender, e) => { richTextBox1.Text = (P.Experience.ToString()); };
                expTimer.Start();
    This is what i have by the timer, and the Clinet c = client.getClinets() is throwing an error. and the tiker event im having an error with too. Sorry its been a long night.
    If get clients is still throwing an error try this:

    Client c = client.GetClients().firstOrDefault();

  2. #12
    Junior Member
    Join Date
    Aug 2012
    Posts
    27
    I tried
    Code:
    Client c = clinet.GetClients().firstOrDefault();
    and its still throwing the same error.

  3. #13
    Junior Member
    Join Date
    Aug 2012
    Posts
    27
    What I have:
    Code:
     public Form1()
            {
                InitializeComponent();
    
                Client c = Client.GetClients().FirstOrDefault();
                Player P;
                P = c.GetPlayer();
                
    
                int ms = 1000;
                System.Windows.Forms.Timer expTimer = new System.Windows.Forms.Timer();
                expTimer.Tick += (sender, e) => { expTextBox.Text = (P.Experience.ToString()); };
                expTimer.Interval = ms;
                expTimer.Start();
    If i could find a way to re write the tick part of expTimer.Tick += (sender, e) => { expTextBox.Text = (P.Experience.ToString()); };

    the P.Experience.ToString()); is part of the cause of the error

  4. #14
    Senior Member
    Join Date
    Dec 2011
    Posts
    249
    Don't forget to include using System.Threading;

    Code:
    public Form1()
    {
    	InitializeComponent();
    	
    	Client c = Client.GetClients().FirstOrDefault();
    	Player P = c.GetPlayer();
    	
    	new Thread(new ThreadStart(
                    delegate 
                    {
                        while (true)
                        {
                            this.Invoke(new ThreadStart(
                                delegate
                                {
    
                                    expTextBox.Text = P.Experience.ToString();
                                }
    
                                ));
                            Thread.Sleep(1000);
                        }
                    })).Start();
    	
    }
    Last edited by ottizy; 03-09-2013 at 09:28 PM.

  5. #15
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    Quote Originally Posted by athenso View Post
    What I have:
    Code:
     public Form1()
            {
                InitializeComponent();
    
                Client c = Client.GetClients().FirstOrDefault();
                Player P;
                P = c.GetPlayer();
                
    
                int ms = 1000;
                System.Windows.Forms.Timer expTimer = new System.Windows.Forms.Timer();
                expTimer.Tick += (sender, e) => { expTextBox.Text = (P.Experience.ToString()); };
                expTimer.Interval = ms;
                expTimer.Start();
    If i could find a way to re write the tick part of expTimer.Tick += (sender, e) => { expTextBox.Text = (P.Experience.ToString()); };

    the P.Experience.ToString()); is part of the cause of the error
    Assuming you're using Visual Studio, right click on the error and hit "copy" and paste it here.

  6. #16
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    Quote Originally Posted by ottizy View Post
    Don't forget to include using System.Threading;

    Code:
    public Form1()
    {
    	InitializeComponent();
    	
    	Client c = Client.GetClients().FirstOrDefault();
    	Player P = c.GetPlayer();
    	
    	Thread updateThread = new Thread(new ThreadStart( delegate { this.Invoke(new ThreadStart(delegate {expTextBox.Text = P.Experience.ToString(); Thread.Sleep(1000); })) })).Start();
    	
    }
    I don't think that will work as it will try to start the thread inside of the class but outside of a function...?

  7. #17
    Super Moderator
    Join Date
    May 2007
    Posts
    1,191
    Quote Originally Posted by ottizy View Post
    Don't forget to include using System.Threading;

    Code:
    public Form1()
    {
    	InitializeComponent();
    	
    	Client c = Client.GetClients().FirstOrDefault();
    	Player P = c.GetPlayer();
    	
    	Thread updateThread = new Thread(new ThreadStart( delegate { this.Invoke(new ThreadStart(delegate {expTextBox.Text = P.Experience.ToString(); Thread.Sleep(1000); })) })).Start();
    	
    }
    Dude, that's horrible...
    Code:
    new Thread(delegate()
    	{
    		// try-catch, otherwise the entire program will crash if the thread crashes
    		try
    		{
    			while (true)
    			{
    				// skip string.Format if you don't want to make it pretty
    				expTextBox.Invoke(delegate() { expTextBox.Text = string.Format("{N}", P.Experience); });
    				Thread.Sleep(1000);
    			}
    		}
    		catch { }
    	}).Start();
    Note that you'll have to kill all threads when exiting your application, personally I use Environment.Exit(Environment.ExitCode) in the FormClosing event.

    Anyway, timers are probably more suitable for you (OP), as they're friendlier to beginners.

    Quote Originally Posted by XtrmJash
    I don't think that will work as it will try to start the thread inside of the class but outside of a function...?
    Form1() is a constructor, you can start threads in constructors.

  8. #18
    Senior Member
    Join Date
    Dec 2011
    Posts
    249
    Perhaps it was a bad example, its not even gonna work I see now, corrected some. I know a timer would be better and more user friendly but since it was already shown how to do that I thought I could show another way since he still isn't getting it to work.

    Also, why would you need need a try block? It shouldn't raise any exceptions?
    Last edited by ottizy; 03-09-2013 at 09:25 PM.

  9. #19
    Senior Member
    Join Date
    Jan 2012
    Posts
    417
    My bet goes to: he's using some ot fully edited (maybe not even a tibia client, like OTClient, that Tibia's class name is not matching) or 'logged in' constant is wrong. As I took a look in the tibia api source and it should be the possible bugs, because I'm pretty sure my timer example works and he had a post explaining an "NotLoggedInException".

  10. #20
    Super Moderator
    Join Date
    May 2007
    Posts
    1,191
    Quote Originally Posted by ottizy View Post
    why would you need need a try block? It shouldn't raise any exceptions?
    Never run code in non-UI threads without a try-catch block, unless you are absolutely sure it won't raise exceptions. The only time I don't run code in try-catch blocks is when I create local variables (I instantiate them inside the try block) that needs to be accessed in catch or finally.
    There are several exceptions that may be raised, i.e. ThreadAbortException or NullReferenceException (expTextBox, P or P.Experience being null).

Posting Permissions

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