Click here to Skip to main content
15,891,657 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: how to run the progresbar.......?? Pin
kubben5-May-07 2:02
kubben5-May-07 2:02 
AnswerRe: how to run the progresbar.......?? Pin
Crook_EVB5-May-07 1:07
Crook_EVB5-May-07 1:07 
AnswerRe: how to run the progresbar.......?? Pin
Dileep_Vickey5-May-07 1:43
Dileep_Vickey5-May-07 1:43 
GeneralRe: how to run the progresbar.......?? Pin
Paul Conrad5-May-07 5:15
professionalPaul Conrad5-May-07 5:15 
QuestionRe: how to run the progresbar.......?? Pin
P P Vilsad6-May-07 5:30
P P Vilsad6-May-07 5:30 
AnswerRe: how to run the progresbar.......?? Pin
Dave Kreskowiak5-May-07 5:27
mveDave Kreskowiak5-May-07 5:27 
QuestionTransparency by image in GDI Pin
Crook_EVB5-May-07 0:42
Crook_EVB5-May-07 0:42 
QuestionTimer for Test Timeout + General Code Structure Pin
RichardBerry4-May-07 22:51
RichardBerry4-May-07 22:51 
Hi

1) Can anyone help me with how to structure some code that if something has not happened in a certain time, the function will return 'False'. The example 'Test0' below must be bad because I am constantly sitting in a loop checking the Port Pin.

2) Is there a better way to use a Timer in 'Test1'?

3) Which routines should be at the Top of the code. Since the routine 'DoTests' is the main loop, I have put it at the top - then as the tests are called, so you find the routines further down in the code. It obviously works anyway around, but I have often noticed in other code examples that the main routine is at the bottom of all the code.

4) After the tests are done (Pass or fail, the routine 'DisplayError is called from the 'DoTests' routine. 'Display Error' in turn calls 'DoTests'. In other words they are constantly calling each other. Is this bad?

Any comments on how I can make this code better will be appreciated..

Example:
Private Sub DoTests()
Test0()
If Not Test1() Then
DisplayError(1)
End If
If Not Test2() Then
DisplayError(2)
End If
DisplayError(10) 'All Tests Passed

End Sub

'Loop until Jig Closes (D0 = 0) to start tests
Private Function Test0() As Boolean
Do While LPTPort.GetState(D0) = 1

Loop
Return True
End Function

Private Function Test1() As Boolean
Dim tmrTestTimeout As Windows.Forms.Timer
tmrTestTimeout.Interval = 3000
tmrTestTimeout.Enabled = True
'Wait for LPTPort pin D1 to go low OR timeout
Do While tmrTestTimeout.Enabled
If LPTPort.GetState(D1) = 0 Then
tmrTestTimeout.Enabled = False
Return True
End If
Loop
'Timed out - so Return False
tmrTestTimeout.Enabled = False
Return False
End Function

Private Sub DisplayError(ByVal intErrorCode As Integer)
Select Case (intErrorCode)
Case 1
Me.lblTestStatus.Text = "Test 1 Failed"
Case 2
Me.lblTestStatus.Text = "Test 2 Failed"
Case 10
Me.lblTestStatus.Text = "All Tests Passed"
Case Else
Me.lblTestStatus.Text = "Unknown Error - Test Aborted"
End Select
'Wait for Jig to open (D0 = 0) so last unit tested is removed
Do While LPTPort.GetState(D0) = 1

Loop
DoTests()
End Sub

AnswerRe: Timer for Test Timeout + General Code Structure Pin
kubben5-May-07 1:11
kubben5-May-07 1:11 
QuestionCustom PaperSize Problem Pin
AmirAlilou4-May-07 21:54
AmirAlilou4-May-07 21:54 
AnswerRe: Custom PaperSize Problem Pin
Duncan Edwards Jones4-May-07 23:48
professionalDuncan Edwards Jones4-May-07 23:48 
GeneralRe: Custom PaperSize Problem Pin
AmirAlilou5-May-07 1:05
AmirAlilou5-May-07 1:05 
AnswerRe: Custom PaperSize Problem Pin
P P Vilsad6-May-07 5:34
P P Vilsad6-May-07 5:34 
GeneralRe: Custom PaperSize Problem Pin
AmirAlilou6-May-07 21:15
AmirAlilou6-May-07 21:15 
GeneralRe: Custom PaperSize Problem Pin
P P Vilsad7-May-07 3:03
P P Vilsad7-May-07 3:03 
QuestionIs Multiple Exit points in a method wrong [modified] Pin
RichardBerry4-May-07 21:46
RichardBerry4-May-07 21:46 
AnswerRe: Is Multiple Exit points in a meethod wrong Pin
Xandip4-May-07 22:59
Xandip4-May-07 22:59 
GeneralRe: Is Multiple Exit points in a meethod wrong Pin
RichardBerry4-May-07 23:16
RichardBerry4-May-07 23:16 
AnswerRe: Is Multiple Exit points in a method wrong Pin
Kevin McFarlane5-May-07 3:52
Kevin McFarlane5-May-07 3:52 
AnswerRe: Is Multiple Exit points in a method wrong Pin
Dave Kreskowiak5-May-07 3:57
mveDave Kreskowiak5-May-07 3:57 
GeneralRe: Is Multiple Exit points in a method wrong Pin
Paul Conrad5-May-07 5:18
professionalPaul Conrad5-May-07 5:18 
GeneralRe: Is Multiple Exit points in a method wrong Pin
Kevin McFarlane5-May-07 12:18
Kevin McFarlane5-May-07 12:18 
GeneralRe: Is Multiple Exit points in a method wrong Pin
Paul Conrad5-May-07 12:29
professionalPaul Conrad5-May-07 12:29 
GeneralRe: Is Multiple Exit points in a method wrong Pin
RichardBerry6-May-07 23:56
RichardBerry6-May-07 23:56 
GeneralRe: Is Multiple Exit points in a method wrong Pin
Dave Kreskowiak7-May-07 1:16
mveDave Kreskowiak7-May-07 1:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.