Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Simple Do While or For Question

Posted on 2003-03-03
5
Medium Priority
?
169 Views
Last Modified: 2010-04-07
Ok another easy one...

This time I am outoutting to a pole disolay using Mscomm1.
I am writing in VB6.

I wrote a small routime that loops through a listbox and sends it's current text to the comm port, moves 1 then displays again until it hits 20 (The pole displays line limit) it then moves to a second listbox and repeats. The for has 10 list boxes with checkboxes to see if that boxes text is to be displayed. Each listindex text is only a single characted, you can see how it works in the list boxes, but it stops after 1 round and just sits there, since both routies are identicle, I am at a loss as to why it stops...here is the code...


'Declare
Option Explicit
Dim Animating1 As Boolean
Dim Animating2 As Boolean

'Pause Function
Public Sub Pause(Duration As Single)
    Dim Current As Single
    Current = Timer
    Do Until Timer - Current >= Duration
        DoEvents
    Loop
End Sub

'Start the animation
Private Sub cmdAnimate_Click()
If MSComm1.PortOpen = True Then
MSComm1.Output = Chr$(31) + Chr$(17) 'Clear the Display
MSComm1.PortOpen = False 'Close the Port
Pause (0.05)
End If
MSComm1.CommPort = 1     ' sets port variable to COM1
MSComm1.PortOpen = True  ' opens the port for communication
MSComm1.Settings = "9600,N,8,1" 'sets Port Comm Settings
Animating1 = True
Animate1

End Sub

'Animation Code
Private Sub Animate1()
Animating1 = True
Animating2 = False
Pause (1)
If List1.ListCount < 20 Then
Do Until List1.ListCount = 21
List1.AddItem "*"
Loop
List1.ListIndex = 0
Do While Animating1 = True
Pause (cmbspeed.Text)
MSComm1.Output = List1.Text 'Output the Text
List1.ListIndex = List1.ListIndex + 1 'Move to the next letter
If List1.ListIndex = 20 And Animating1 = True Then
MSComm1.Output = Chr$(31) + Chr$(17) ' Clear the Display
If Check2.Value = 1 Then
  List2.ListIndex = 0
 Animating2 = True
 Animate2
End If
  End If
   Loop
 
   End If
End Sub
Private Sub Animate2()
Animating2 = True
Animating1 = False
Pause (1)
If List2.ListCount < 20 Then
Do Until List2.ListCount = 21
List2.AddItem "*"
Loop
List2.ListIndex = 0
Do While Animating2 = True
Pause (cmbspeed.Text)
MSComm1.Output = List2.Text 'Output the Text
List2.ListIndex = List2.ListIndex + 1 'Move to the next letter
If List2.ListIndex = 20 And Animating2 = True Then
MSComm1.Output = Chr$(31) + Chr$(17) ' Clear the Display
If Check10.Value = 2 Then
 List1.ListIndex = 0
 Animating1 = True
 Animate1
End If
  End If
   Loop
 
   End If
   
End Sub


Check 10 is required and greyed, therefore is alwasys 2...this is test code and animate2 will check for an animate3 etc and run through list boxes that are checked and continue until the user clicks stop which sets all animation booleans to false and closes mscomm... this runs a time or 2 and then stops..cannot figure out why as both animate1 and animate2 are the same...???


I appreciate your comments.
0
Comment
Question by:flosoft
  • 3
5 Comments
 
LVL 3

Expert Comment

by:DeAn
ID: 8059155
should this line in Animate2 say Check1?? not Check10?

If Check10.Value = 2 Then
0
 

Author Comment

by:flosoft
ID: 8059179
No, Check 10 represents the 1st listbox and that is checked gray (2) because the first list box will always be sent when using this program...I am thinking ideally I would wrap a thin listbox with a checkbox just above it into an active x control so I could load these into an array each control having an animate (boolean) property, add,remove,moveup,movedown,text and list index...just a thought I am having.
0
 

Author Comment

by:flosoft
ID: 8059410
I am experimenting with the active x part, but the code still does the same exact this...so hmmmm, maybe a way to use a time??
0
 
LVL 3

Accepted Solution

by:
DocM earned 100 total points
ID: 8059637
The last line with "End If" must be deleted
and replaced par "End if" after line 9.


Private Sub Animate2()
Animating2 = True
Animating1 = False
Pause (1)
If List2.ListCount < 20 Then
Do Until List2.ListCount = 21
List2.AddItem "*"
Loop
List2.ListIndex = 0
End If 'Line added

Do While Animating2 = True
Pause (cmbspeed.Text)
MSComm1.Output = List2.Text 'Output the Text
List2.ListIndex = List2.ListIndex + 1 'Move to the next letter
If List2.ListIndex = 20 And Animating2 = True Then
MSComm1.Output = Chr$(31) + Chr$(17) ' Clear the Display
If Check10.Value = 2 Then
List1.ListIndex = 0
Animating1 = True
Animate1
End If
 End If
  Loop
 
'End if  'Line deleted
 
End Sub


0
 

Author Comment

by:flosoft
ID: 8059971
Wow...DUH..... what can I say...thanks...now I have one last thing to post....it should be fairly easy if ya want to take a crack at it...thanks again/
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question