Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Was wondering if there was a way to pass through variables to the timer I start. For example:

 

I have a sub

Private sub subtest (caseit as integer)
Dim String1 as string
Dim String2 as string

select case caseit
  Case 1
     timer1.interval = 500
     timer1.start ' HERE I WANT TO PASS STRING1 TO timer
   Case 2      
     timer1.interval = 2000
     timer1.start ' HERE I WANT TO PASS STRING2 TO timer
end case
end sub

Edited by techmanbd
Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

basically the code in my timer looks like this.

I need to send a case variable and also a variable that is sent to test equipment. Before I have the timer start I also set the interval different. Because the sub takes a little longer. And what I am trying to avoid, is having a variable dim'd at the beginning of the program, instead having it pass through.

Select case casit
 case 1
     text1.text = voltmeasure(strVariable)
 case 2 
     text2.text = voltLISTmeas(strVariable)
end select

 

I also don't know what or how to do wrapper classes, i looked in the help section and didn't find it

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

your paradigm is a little backwards. . .

 

in the timer event, the value 'caseit' should be evaluated.

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

Actually I left out some stuff that wasn't what I thought was important. I have a select case in my 'subtest' and I left out code. depending on what was select string1 could be 15 different things, then I want that string1 sent to the timer sub. And depending on the case in the 'subtest' this will set the interval and start the timer event.

 

in the timer event, i send what case I want to do and also send the string1 to the timer which becomes the strVariable.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

what I am saying is. . . in ontimer event handler do the case statement and detemine the string to use there.

 

or. . .

 

select case the method to wire to the timer event. . .

 

or create another delegate that is assigned by the case statement and in the timer event execute the delegate.

 

or . . .

 

There are a million ways to skin this cat.

 

I would like to see your code, if its not too involved.

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

Private Sub cmdOutputON_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOutputON.Click
       If Me.pbxRedOff.Visible Then
           MessageBox.Show("POWER IS NOT ON", "Power", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
           Exit Sub
       End If
       Me.comWrite("0SPK00000000")
       Me.comWrite("1SPK00000000")
       Me.comWrite("2SPK00000000")
       If Me.pbxRedOff.Visible Then
           Me.comWrite("3SPK00000000")
       Else
           Me.comWrite("3SPK10000000")
       End If
       Dim strload As String
       Dim strcommand As String
       Dim strcommand1 As String
       Dim strcaseit As String

       If Me.rdbNormalOp.Checked Then
           strload = strOpload
           strcaseit = "normal"
       ElseIf Me.rdbJamOp.Checked Then
           strload = strJamload
           strcaseit = "jam"
       ElseIf Me.rdbOverCurrentOP.Checked Then
           strload = strHiload
           strcaseit = "over"
       End If

       If Me.rdbAc1.Checked = True Then
           strcommand1 = "0SK0"
           If Me.rdbDirectFWD.Checked Then
               strcommand = ActFWD(1)
           ElseIf Me.rdbDirectREV.Checked Then
               strcommand = ActREV(1)
           End If
       ElseIf Me.rdbAct2.Checked Then
           strcommand1 = "0SK1"
           If Me.rdbDirectFWD.Checked Then
               strcommand = ActFWD(2)
           ElseIf Me.rdbDirectREV.Checked Then
               strcommand = ActREV(2)
           End If
       ElseIf Me.rdbAct3.Checked Then
           strcommand1 = "0SK2"
           If Me.rdbDirectFWD.Checked Then
               strcommand = ActFWD(3)
           ElseIf Me.rdbDirectREV.Checked Then
               strcommand = ActREV(3)
           End If
       ElseIf Me.rdbAct4.Checked Then
           strcommand1 = "0SK3"
           If Me.rdbDirectFWD.Checked Then
               strcommand = ActFWD(4)
           ElseIf Me.rdbDirectREV.Checked Then
               strcommand = ActREV(4)
           End If
       ElseIf Me.rdbAct5.Checked Then
           strcommand1 = "0SK4"
           If Me.rdbDirectFWD.Checked Then
               strcommand = ActFWD(5)
           ElseIf Me.rdbDirectREV.Checked Then
               strcommand = ActREV(5)
           End If
       ElseIf Me.rdbAct6.Checked Then
           strcommand1 = "0SK5"
           If Me.rdbDirectFWD.Checked Then
               strcommand = ActFWD(6)
           ElseIf Me.rdbDirectREV.Checked Then
               strcommand = ActREV(6)
           End If
       ElseIf Me.rdbAct7.Checked Then
           strcommand1 = "0SK6"
           If Me.rdbDirectFWD.Checked Then
               strcommand = ActFWD(7)
           ElseIf Me.rdbDirectREV.Checked Then
               strcommand = ActREV(7)
           End If
       ElseIf Me.rdbAct8.Checked Then
           strcommand1 = "0SK7"
           If Me.rdbDirectFWD.Checked Then
               strcommand = ActFWD(8)
           ElseIf Me.rdbDirectREV.Checked Then
               strcommand = ActREV(8)
           End If
       ElseIf Me.rdbAux1.Checked Then
           strcommand1 = "0SK0"
           strcommand = ReadAux(1)
           strload = strvdc12opload
       ElseIf Me.rdbAux2.Checked Then
           strcommand1 = "0SK1"
           strcommand = ReadAux(2)
           strload = strvdc12opload
       ElseIf Me.rdbAux3.Checked Then
           strcommand1 = "0SK2"
           strcommand = ReadAux(3)
           strload = strvdc12opload
       ElseIf Me.rdbAux4.Checked Then
           strcommand1 = "0SK3"
           strcommand = ReadAux(4)
           strload = strvdc12opload
       ElseIf Me.rdbBacklight.Checked Then
           strcommand1 = "0SK4"
           strcommand = ReadAux(5)
           strload = strvdc12opload
       End If
       Dim intX As Integer
       For intX = 1 To 5
           Me.comWrite(ReadAux(intX).Replace("S", "R"))
       Next
       Me.comWrite("2SPK00000000")
       Me.comWrite(strcommand)
       Select Case strcaseit
           Case "normal"
               Me.tmrManual.Interval = 500
               Me.tmrManual.start
           Case "jam", "over"
               Me.tmrManual.Interval = 2000
               Me.tmrManual.start
       End Select
   End Sub

Private Sub cmdOutputOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOutputOff.Click
       Me.tmrManual.Stop()
       Me.comWrite("0SPK00000000")
       Me.comWrite("1SPK00000000")
       Me.comWrite("2SPK00000000")
       If Me.pbxRedOff.Visible Then
           Me.comWrite("3SPK00000000")
       Else
           Me.comWrite("3SPK10000000")
       End If
   End Sub

Private Sub tmrManual_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrManual.Tick
Select Case caseit
    Case "voltmeas"
       Me.electronicloadset(strload)
       Me.lblManVolt.Text = Format(Me.electloadmeasure, "#0.00").ToString
       If Convert.ToDouble(Me.lblManVolt.Text) < dblUpperVoltlimit Or Convert.ToDouble(Me.lblManVolt.Text) > dblLowerVoltlimit Then
           Me.lblManVolt.BackColor = Color.Green
       Else
           Me.lblManVolt.BackColor = Color.Red
       End If
     case "list"
                    Me.txtJamOp.Text = (Me.loadlistroutine(strLoad)).ToString
  end case
End Sub

 

this is the code I have written so far,

I would like to get the 'strLoad' variable and a 'Caseit' variable to the timer so that every 500 ms it runs the one code or if I set it to run the other code every 2000ms it runs that one. And the reason I would like to do this is so I don't dim the variable at the beginning of the program and set it when I get to this code. I want to only use the variable when I access that sub. because I am not using all the time.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

This will be fun. . .

 

give me the night. . .

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

  • *Experts*
Posted

One way you might "pass a variable" is through a function with a static declared local variable and a parameter ie:

 

   Private Function theVariable(ByVal pram As String, ByVal value As String) As String
       Static variable As String
       If pram = "Set" Then
           variable = value
       Else : Return variable
       End If
   End Function

 

You can "Set" the variable from the radio button subs,

theVariable("Set", "some value").

And call the function from the timer event to retrieve the variable.

neededVariable = theVariable("Get", "doesn't matter")

 

The cool thing about static variables is that they will never change unless you change them.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

you can also inherit from timer

 

 

CustomTimer

Imports System.Windows.Forms
Public Class CustomTimer
   Inherits System.Windows.Forms.Timer
   Dim strload As String
   Dim strcaseit As String
' Component Designer generated code deleted for brevity
   Public Property LoadString() As String
       Get
           LoadString = strload
       End Get
       Set(ByVal Value As String)
           strload = Value
       End Set
   End Property
   Public Property CaseString() As String
       Get
           CaseString = strcaseit
       End Get
       Set(ByVal Value As String)
           strcaseit = Value
       End Set
   End Property
End Class

 

CustomTimer Usage

Public Class Form1
   Inherits System.Windows.Forms.Form
   Dim WithEvents MyTimer As New CustomTimer
'  Windows Form Designer generated code deleted for brevity
   Private Sub MyTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyTimer.Tick
       Select Case MyTimer.CaseString
           ' 
           ' do your stuff here
           '

       End Select
   End Sub
   Private Sub cmdOutputOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOutputOn.Click
       ' 
       ' Set Custom Timer Properties here
       '
   End Sub
End Class

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...