Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Variables

Status
Not open for further replies.

007MCSE

IS-IT--Management
Jan 3, 2003
51
US
I have a Timer variable called T1

The value of T1 is set from an Input box within a form.

The problem is that T1 in the main code dosen't get set to the new Value from the Input Box.

The Input box generated its own code called Data Project and thats where the Value for T1 is set.

How do I get T1 in my main code to equal the value from the Input Box?

Gary
 
is T1 a global variable or a local variable?

Sounds to me like an issue of scope.
 
Need to see the code, but If your using an Input Box it will return a string value... So in the simplest form you could do this.

T1.Interval = val(InputBox("Enter a timer value:"))

But of course if they type text in there you will have issues.
Craig, mailto:sander@cogeco.ca

Si hoc legere scis, nimis eruditionis habes
 
Jeepxo

I dont know what type it is....I'm new to this Programing.

Craig
That didn't work. Its doing the same as what my code is doing.

One thing I didn't mention is that the Input box is launched when a user selects a Speedset Command Button.

Private Sub SpeedSet_Click()
T1 = InputBox("Enter The Speed:- Eg 1 Sec = 1000")
End Sub

The problem is then that I can't get the main code (see Below) to recognize the T1 value.

Private Sub Start_Click()
Time1 = T1

Green = vbGreen
Red = vbRed
Clear = vbWhite
Blue = vbBlue
Black = vbBlack
Do

Thanks
Gary
 
Hey 007MCSE the val that is returned from the textbox is text isn't it? If so tehn the val would have to be converted to CInt(InputBox("Enter The Speed:- Eg 1 Sec = 1000"))

Also by declaring the variable in global format the fact that Time1, which I am assumming is the name for the timer in it's present form is not defaulted to read the T1 variable declared and automatically assign it to the interval value of the control.
Perhaps Time1.interval = CInt(T1) would be useful.
Have you done a debug.print T1 from the developers window and seen indeed if the T1 variable is a text or integer value? By seein a left or right alignment of the output will tell you which it is.

HTH
AntonV
 
Hey AntonV

I did what you said and the timer runs through once and then stops.

Maybe it would be helpfull if you saw all the code.
' These two declarations for the inpout32.dll are for getting data from the
' parallel port, Inp, and sending data to the parallel port, Out.

Private Declare Function Inp Lib "inpout32.dll" _
Alias "Inp32" (ByVal PortAddress As Integer) As Integer

Private Declare Sub Out Lib "inpout32.dll" _
Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)

' Declare the veriables for the Port Address and the Value to send to the port
Dim PortAddress As String


Private Sub SpeedSet_Click()
'T1 = InputBox("Enter The Speed:- Eg 1 Sec = 1000")
T1 = CInt(InputBox("Enter The Speed:- Eg 1 Sec = 1000"))

End Sub

Private Sub LEDColors_Click() 'openform.LEDColors'
Dim frmLedColours As LEDColors
Set frmLedColours = New LEDColors
frmLedColours.Show vbModal, Me

End Sub

Private Sub Speed_Click() 'openform.SpeedSetup'
Out PortAddress, &H0
Dim frmSpeedSetup As SpeedSetup
Set frmSpeedSetup = New SpeedSetup
frmSpeedSetup.Show vbModal, Me
End Sub




Private Sub Start_Click()
'Timer1.Interval = CInt(T1)
'Time1 = T1

Green = vbGreen
Red = vbRed
Clear = vbWhite
Blue = vbBlue
Black = vbBlack
Do

Out PortAddress, &H1
LED1.FillColor = Green
Timer1.Interval = CInt(T1)
Timer1_Timer
LED1.FillColor = Black

Out PortAddress, &H2
LED2.FillColor = Red
Timer1.Interval = CInt(T1)
Timer1_Timer
LED2.FillColor = Black

Out PortAddress, &H4
LED3.FillColor = Clear
Timer1.Interval = CInt(T1)
Timer1_Timer
LED3.FillColor = Black

Out PortAddress, &H8
LED4.FillColor = Blue
Timer1.Interval = CInt(T1)
Timer1_Timer
LED4.FillColor = Black

Out PortAddress, &H10
LED5.FillColor = Green
Timer1.Interval = CInt(T1)
Timer1_Timer
LED5.FillColor = Black

Out PortAddress, &H20
LED6.FillColor = Red
Timer1.Interval = CInt(T1)
Timer1_Timer
LED6.FillColor = Black

Out PortAddress, &H40
LED7.FillColor = Clear
Timer1.Interval = CInt(T1)
Timer1_Timer
LED7.FillColor = Black


Out PortAddress, &H80
LED8.FillColor = Blue
Timer1.Interval = CInt(T1)
Timer1_Timer
LED8.FillColor = Black

Loop While DoEvents


End Sub

Private Sub ExitCmd_Click()
Out PortAddress, &H0
End

End Sub

Private Sub Stop_Click()
Out PortAddress, &H0
Dim frmXmas1 As Xmas1
Set frmXmas1 = New Xmas1
frmXmas1.Show vbModal, Me
End Sub

Private Sub Timer1_Timer()
Static Temp As Integer
Temp = Temp + 1
Do While DoEvents()
If Temp Mod 2 = 0 Then Exit Do
Loop

End Sub
Private Sub Form_Load()
' The Port Address is the HEX address of Your parallel port. You find this
' by going to your device manager and clicking on the Resources tab for your
' parallel port. &H378 is the default but if yours isn't change it below.

PortAddress = &H378
Call Timer2_Timer
End Sub

Private Sub Timer2_Timer()
Clock.Text = Format(Now, "hh:mm:ss am/pm")
End Sub

The code is sequencing 8 LEDS on a form called Xmas1

Now after I added your code the first LED does come on then it just stops.

Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top