4 Replies - 542 Views - Last Post: 08 June 2012 - 01:05 PM Rate Topic: -----

#1 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 330
  • Joined: 11-July 07

Declaring functions

Posted 08 June 2012 - 12:55 PM

Hello, D.I.C.

I've been programming VB.NET for quite a while and see the simplicity when converting VB.NET to C#


My problem is this, although it may be a very simple solution. When I was programming VB.NET, I'd use Private xTimer as New Timer() then I'd create a custom sub and then just put ... handles xTimer.Tick - how do I do that in C#? I can't use handles, and I can't set a "Tick" function, or I can but don't know how...

Thanks for any help, always appreciated.

~huzi

Is This A Good Question/Topic? 0
  • +

Replies To: Declaring functions

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9579
  • View blog
  • Posts: 36,289
  • Joined: 12-June 08

Re: Declaring functions

Posted 08 June 2012 - 12:59 PM

The comparison chart should be your friend!

http://www.harding.e...comparison.html
Was This Post Helpful? 3
  • +
  • -

#3 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1363
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Declaring functions

Posted 08 June 2012 - 01:00 PM

You add an event handler to the .Tick event - something like this -

xTimer.Tick += TimerTick; // Add the TimerTick method to the tick event


Then you make your method which is called whenever the timer ticks.

private void TimerTick(object sender, EventArgs e)
{
   ...
}


Some reading on delegates and events will help you out a lot.

Link

This post has been edited by Ryano121: 08 June 2012 - 01:01 PM

Was This Post Helpful? 2
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5677
  • View blog
  • Posts: 12,208
  • Joined: 02-June 10

Re: Declaring functions

Posted 08 June 2012 - 01:04 PM

        private void someButton_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.Timer bob = new Timer();
            bob.Interval = 4000;
            bob.Tick += bob_Tick;
            bob.Start();
        }

        void bob_Tick(object sender, EventArgs e)
        {
            // Do this when the timer goes tick
        }



Suggestion: Don't think that speaking VB.NET means you can intuit your way through C#. That's like saying because you speak Spanish, and that's a language foreign to English, then you can intuit your way through Russian because that is also foreign to English.

Go through the tutorials and a basic "C# in 30 days" book.
Since you have an understanding of events, handlers, methods and so on you should be able to do 30 days of a book in a week if you have the handle on the concepts that you think you do. That will be time well spent and a LOT less time than feeling your way around and stumbling over all the differences like "handles" which is something else entirely in C#.


Resources, references and suggestions for new programmers. - Updated Mar 2012
Spoiler

Was This Post Helpful? 1
  • +
  • -

#5 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 330
  • Joined: 11-July 07

Re: Declaring functions

Posted 08 June 2012 - 01:05 PM

Brilliant!!

Thank you guys so much! Where would I be without D.I.C!?

Thanks again, and I'll check that comparison chart, thank you modi123_1.

~huzi
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1