dcsimg
Results 1 to 14 of 14

Thread: Timer canot be converted to control in vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    10

    Timer canot be converted to control in vb.net

    I have the following code in VB.NET. It gives error that timer cannot be converted to type control.


    Code:
    Dim ctl As System.Windows.Forms.Control
    Timer1.Load(a_instance)
    ctl = Timer1(a_instance)
    DisplayForm_GetDisplay = ctl
     If a_instance = 1 Then
         ReDim tmrevtback(1)
     End If
    In Designer.vb form

    Code:
    Public WithEvents Timer1 As Microsoft.VisualBasic.Compatibility.VB6.TimerArray
    Me.Timer1 = New Microsoft.VisualBasic.Compatibility.VB6.TimerArray(Me.components)

    EDIT:

    Code:
    Dim lctl As System.Windows.Forms.Control
    lctl = mDisplayForm.GetDisplayElementControl(a_elemtype, i, a_displayelement)

    Code:
    Private Function DisplayForm_GetDisplayElementControl(ByRef a_type As String, ByRef a_instance As Integer, ByRef a_displayelement As DisplayEvent) As System.Windows.Forms.Control Implements _DisplayForm.GetDisplayElementControl
    Dim ctl As System.Windows.Forms.ControlDim ctl As System.Windows.Forms.Control
    Timer1.Load(a_instance)
    ctl = Timer1(a_instance)
    DisplayForm_GetDisplayElementControl= ctl
     If a_instance = 1 Then
         ReDim tmrevtback(1)
     End If
    If UBound(tmrevtback) < a_instance Then
        ReDim Preserve tmrevtback(a_instance)
    End If
    tmrevtback(a_instance) = a_displayelement
    frmDisplayToolbox.RegisterNewControl(Me, a_type, a_instance, a_displayelement, ctl)
    This calls the below functions.

    Code:
    Public Function RegisterNewControl(ByRef a_form As System.Windows.Forms.Form, ByRef a_type As String, ByVal a_instance As Integer, ByRef a_displayelement As DisplayElement, ByRef a_control As System.Windows.Forms.Control) As Boolean
    		Dim lkey As String = "" 
    		Dim levent As String = "" 
    		Dim lparms As DataSetNode
    		On Error GoTo bad
    		If a_form Is mForm Or mForm Is Nothing Then
    			lkey = "k" & a_type & a_instance
    			
    			If Not a_control Is Nothing Then
    				mDisplayInstances.Add(a_type & a_instance)
    				mDisplayControls.Add(a_control, lkey)
    				mDisplayElements.Add(a_displayelement, lkey)
    				
    				mLog("+ Register New Control: K=" & lkey)
    				RegisterNewControl = True
    			Else
    				mLog("!! Unable to Register New Control (control is empty): T=" & a_type & "  I=" & a_instance)
    			End If
    		Else
    			mLog("!! Unable to Register New Control (no or bad form): T=" & a_type & "  I=" & a_instance)
    		End If
    		Exit Function
    Note: I'm converting this project from VB6 to VB.NET and it works fine in VB6.
    Code:
    ctl = Timer1(a_instance)
    line throws error in VB.NET.
    Last edited by Himanshupatel06; Jun 21st, 2018 at 09:17 AM. Reason: Provided more code

  2. #2
    Member
    Join Date
    Jun 2018
    Posts
    33

    Re: Timer canot be converted to control in vb.net

    Code:
    Dim ctl As System.Windows.Forms.Control
    Timer1.Load(a_instance)
    ctl = Timer1(a_instance)
     clsijwIDisplayForm_GetDisplay'CODE IDOT on
     If a_instance = 1 Then
         ReDim tmrevtback(1)
     End If
    Don't know enough VB6 to help much but this line seem a bit odd,
    Also I don't remember .net timers having a .load property.

    KBConsole
    Last edited by KBConsole; Jun 21st, 2018 at 08:52 AM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    10

    Re: Timer canot be converted to control in vb.net

    Any alternative solutions for this?

  4. #4
    Member
    Join Date
    Jun 2018
    Posts
    33

    Re: Timer canot be converted to control in vb.net

    What is your code supposed to do ?

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    10

    Re: Timer canot be converted to control in vb.net

    It register a new display control and when more than one display in queue, it avoid screen flashing so each screen displays for a second or two minimum. So basically it should register timer control instance.

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    10

    Re: Timer canot be converted to control in vb.net

    Check Edited post. I've added bit more code.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,378

    Re: Timer canot be converted to control in vb.net

    How about using an actual .NET Timer component rather than the VB6 Timer control? I'd also replace tmrevtback with a List(of) rather than array... it'll cut down on some of thee array management code clutter.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    10

    Re: Timer canot be converted to control in vb.net

    But how can I pass that to a control? I've tried using
    Code:
     Friend Timer1() As Timer
    but it throws same error that value of timer can not be converted to Control while executing
    Code:
    ctl = Timer1(instance)
    .
    Last edited by Himanshupatel06; Jun 21st, 2018 at 09:31 AM.

  9. #9
    Member
    Join Date
    Jun 2018
    Posts
    33

    Re: Timer canot be converted to control in vb.net

    Sadly 'timers' in .Net are no longer considered 'controls' but 'components'.

    I'd just rewrite the whole thing in .Net to avoid errors or unproper syntax since i'm not a big fan of "patching" or code conversion.

    Hoping someone gives you a better solution but I can't think of one for now,

    Good luck,

    KBConsole

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,916

    Re: Timer canot be converted to control in vb.net

    Ultimately, that's the best advice. I don't remember how timers worked in VB6, but in .NET, forms and all controls inherit from Control, which offers up certain functionality. Timer does NOT inherit from Control, partially because it doesn't need that functionality. It doesn't have a location, it doesn't have a text property, it doesn't have some of the events that controls have, and it doesn't have a handle. I'm not even sure which of those was the more important one when it comes to not having Timer inherit from Control, but whatever the reason or reasons, that is the result.

    You also don't want more than one control per form, cause having more than one will clutter things up, so the idea of an array of timers is a bit misguided to begin with. Technically, you could probably use Object, since both Control and Timer derive from that, but even if that would work, you shouldn't do it, because having an array of timers is just asking for trouble.

    This is one of the reasons why people say that VB.NET and VB6 are not the same language despite superficial similarities. Much of what you are showing is an attempt to force VB.NET to act as if it were VB6. For example, all the Redim Preserves (which weren't efficient in VB6, either), On Error form of exception handling, and use of whatever that arraytimer thing is.

    For that matter, your solution to the problem may be due to a holdover from VB6, too, as screen 'flashing' is usually not solved using timers, it's usually solved by changing doublebuffer to True, unless the issue is that things change from A to B to C so fast that B just 'flashes' on the screen, and what you really want is for it to take some time. Still, one timer should suffice.

    EDIT: I'm not thrilled with that answer, and you probably aren't either. The reason for that is that you used some terminology in your description that is sufficiently ambiguous that I'm not sure what the best answer would be. You gave a brief description in post #5, but it left a whole lot to the imagination.

    I am likely misunderstanding you, but the way I read post #5 was that you had a single form that showed a series of "display controls". I don't know what a display control is, and how it differs from any other type of control, if it differs at all. It's unusual to have a form with controls that are showing up and going away automatically. Is this happening in the same place? What is driving the change? Is the flashing just that the controls are flickering, or that they are changing so fast they barely become visible before leaving?
    Last edited by Shaggy Hiker; Jun 21st, 2018 at 10:48 AM.
    My usual boring signature: Nothing

  11. #11
    Member
    Join Date
    Jun 2018
    Posts
    33

    Re: Timer canot be converted to control in vb.net

    or that they are changing so fast they barely become visible before leaving?
    Pretty sure it's close to that, "display control" kinda triggered my OCD too but I believe he simply :

    has multiple "x" to display (the array) and had to insert a delay so they show long enough to be seen (timer)

    If this theory is right it would be very easy to recreate in .Net but i might be wrong about the program's goal.

    KBConsole

  12. #12

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    10

    Re: Timer canot be converted to control in vb.net

    Quote Originally Posted by Shaggy Hiker View Post
    Ultimately, that's the best advice. I don't remember how timers worked in VB6, but in .NET, forms and all controls inherit from Control, which offers up certain functionality. Timer does NOT inherit from Control, partially because it doesn't need that functionality. It doesn't have a location, it doesn't have a text property, it doesn't have some of the events that controls have, and it doesn't have a handle. I'm not even sure which of those was the more important one when it comes to not having Timer inherit from Control, but whatever the reason or reasons, that is the result.

    You also don't want more than one control per form, cause having more than one will clutter things up, so the idea of an array of timers is a bit misguided to begin with. Technically, you could probably use Object, since both Control and Timer derive from that, but even if that would work, you shouldn't do it, because having an array of timers is just asking for trouble.

    This is one of the reasons why people say that VB.NET and VB6 are not the same language despite superficial similarities. Much of what you are showing is an attempt to force VB.NET to act as if it were VB6. For example, all the Redim Preserves (which weren't efficient in VB6, either), On Error form of exception handling, and use of whatever that arraytimer thing is.

    For that matter, your solution to the problem may be due to a holdover from VB6, too, as screen 'flashing' is usually not solved using timers, it's usually solved by changing doublebuffer to True, unless the issue is that things change from A to B to C so fast that B just 'flashes' on the screen, and what you really want is for it to take some time. Still, one timer should suffice.

    EDIT: I'm not thrilled with that answer, and you probably aren't either. The reason for that is that you used some terminology in your description that is sufficiently ambiguous that I'm not sure what the best answer would be. You gave a brief description in post #5, but it left a whole lot to the imagination.

    I am likely misunderstanding you, but the way I read post #5 was that you had a single form that showed a series of "display controls". I don't know what a display control is, and how it differs from any other type of control, if it differs at all. It's unusual to have a form with controls that are showing up and going away automatically. Is this happening in the same place? What is driving the change? Is the flashing just that the controls are flickering, or that they are changing so fast they barely become visible before leaving?


    Yes instance of timer control helps displays to run for minimum time and avoid screen flashing. If more then one displays are in queue it helps to display each screen for at least minimum time. "It's not for flashing it's to avoid flashing and display screen for at least minimum few seconds." And there are more then one forms. Couple forms have few controls like Picturebox, Panel, Timer, Flash control.

  13. #13

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    10

    Re: Timer canot be converted to control in vb.net

    Quote Originally Posted by KBConsole View Post
    Pretty sure it's close to that, "display control" kinda triggered my OCD too but I believe he simply :

    has multiple "x" to display (the array) and had to insert a delay so they show long enough to be seen (timer)

    If this theory is right it would be very easy to recreate in .Net but i might be wrong about the program's goal.

    KBConsole
    Yes you're right. Yes instance of timer control helps displays to run for minimum time and avoid screen flashing. If more then one displays are in queue it helps to display each screen for at least minimum time. "It's not for flashing it's to avoid flashing and display screen for at least minimum few seconds." And there are more then one forms. Couple forms have few controls like Picturebox, Panel, Timer, Flash control.

  14. #14
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,916

    Re: Timer canot be converted to control in vb.net

    In that case, the design really needs only one timer. If the 'displays' are on a form, then the timer can be on the form. If the displays ARE forms, then it would be better to have the timer somewhere else, such as in a module.

    In either case, you can have the displays in a Queue. In the timer tick event, dequeue the next item and show it. The item knows where it needs to be, so it's really just a matter of dequeuing the next control and making it visible. If you need different items to be visible for different amounts of time, then you could put the time (in milliseconds) to display each control into the .Tag property of the control. When you dequeue the item in the timer tick event, you could set the timer interval to whatever was held in the .Tag property. That way, each control can have a different length of time for it to be displayed.
    My usual boring signature: Nothing

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width