?
Solved

Simple Do While or For Question

Posted on 2003-03-03
5
Medium Priority
?
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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, 22 hours left to enroll

771 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