[RESOLVED]How to make in this loop - please help me
I'm not the best in explaining things. O.K. I will try
So, when I click the commandbutton COUNT, it my application it does one operation of calculation. Visible the progress bar on a screen shots it is registering progress executed calculations. Visible number shows how much operation was executed.
If I will click the commanbutton UNDO COUNT then will be withdrawal 1 operation, then recently segment should stopping shine.
And now, essence of matter
I make such code and I used statement Case, where I used variable as counter.
For button COUNT
VB Code:
Dim Lic As Integer
Select Case Lic
Case 0
With lbl1
.caption = 1
.Backcolor = RGB ( 44, 164, 214)
.Forecolor = RGB (255, 255, 255)
End With
Lic = 1
Case 1
With lbl2
.caption = 2
.Backcolor = RGB ( 44, 164, 214)
.Forecolor = RGB (255, 255, 255)
End With
Lic = 2
…….etc until to lbl10.caption
(Truth, that this looks fatally)
Of course, for button UNDO COUNT the statement makes in reverse order
I want this to make from use in some loop ( better For...Next) and the array of objects (Label)
Just, I don't know how to make this.
P.S. Array of objects this is simply, I know how to make.
thx, in advance for every help
Re: How to make in this loop - please help me
What is Lic for? You declare Lic but doesnt assign it to anything, so its always going to be 0 and will follow the 0 case everytime
Re: How to make in this loop - please help me
Ooopss...you have right. I correct example- code, you see
Lic it is name my variable, which is my counters. Value of this variable decides about writes to next Label. It value on start = 0. When I click the button COUNT it write to first lbl1 number 1, it will change backcolor and forecolor and value variables to 1....etc.
And next, if variable = 1, then.....etc,etc. It works fine now, but it is primitive. I want more professionally.
Re: How to make in this loop - please help me
Okay, but dont you see in your code if you put 'Dim Lic as Integer' you are creating a new variable, and unless you assign some data to it, since it is an integer, its default value will be 0, so it will always go down the case 0 path.
Do you have your command buttons as arrays, or do you have Lic declared elsewhere in your project?
Re: How to make in this loop - please help me
Make Array for your label like a lbl(0) -> lbl(10) then there is less code
VB Code:
Public Sub ChangeLabelColor(index As Integer)
With lbl(index)
.Caption = 1
.BackColor = RGB(44, 164, 214)
.ForeColor = RGB(255, 255, 255)
End With
End Sub
Re: How to make in this loop - please help me
Quote:
want this to make from use in some loop ( better For...Next) and the array of objects (Label)
Just, I don't know how to make this.
P.S. Array of objects this is simply, I know how to make.
i dont know if this is what you are trying to do.
Quote:
For i = Lb1.LBound To Lbll1.uBound
If Lbl1(i).Index = lic Then
With lbl1(i)
.caption = 1
.Backcolor = RGB ( 44, 164, 214)
.Forecolor = RGB (255, 255, 255)
End With
Lic = 1+i
End If
Next
Re: How to make in this loop - please help me
Thank you for your solution and for quick reply. But the problem is such, in order to after every turn of loop highlight ONLY 1 label. Now the all labels are highlighted in one loop turn, understand me? This is large difference.
I need such cycle: 1 turn of loop and 1 Label (in example lbl1(0)) it is highlight and it was executed 1 calculation, 2 turn of loop and 2 label (in example lbl1(1)) is highlight it was executed 2 calculation etc...
This has to be the bar progress of calculations, it has to inform user about this how much he made the calculations - this is the programme to calculation of roofs
Re: How to make in this loop - please help me
Quote:
Originally Posted by Tamgovb
Thank you for your solution and for quick reply. But the problem is such, in order to after every turn of loop highlight ONLY 1 label. Now the all labels are highlighted in one loop turn, understand me? This is large difference.
I need such cycle: 1 turn of loop and 1 Label (in example lbl1(0)) it is highlight and it was executed 1 calculation, 2 turn of loop and 2 label (in example lbl1(1)) is highlight it was executed 2 calculation etc...
Change Dim to Static
VB Code:
Static Lic As Integer
Select Case Lic
1 Attachment(s)
Re: How to make in this loop - please help me
Here is my tip and example-code. He shows about what it walks me. I can't me with him advise. Moreover appeared error. Error jumps from 2 MsgBox, I don't know what.
Re: How to make in this loop - please help me
Quote:
Originally Posted by Tamgovb
Here is my tip and example-code. He shows about what it walks me. I can't me with him advise. Moreover appeared error. Error jumps from 2 MsgBox, I don't know what.
You have not Label0, correct code:
VB Code:
MsgBox "The packet of calculations is full", vbInformation, "Attention"
If MsgBox("You want to remove results", vbQuestion + vbYesNo, "questions") = vbYes Then
For i = 1 To 7
Controls("Label" & i).Caption = ""
Next
End If
Re: How to make in this loop - please help me
O.K thanks,
I improved already and it's O.K. So, however main problem stayed not solved, what about this you plant this?
Please help me.
Re: How to make in this loop - please help me
Quote:
Originally Posted by Tamgovb
O.K thanks,
I improved already and it's O.K. So, however main problem stayed not solved, what about this you plant this?
Please help me.
I made some changes for your sample code. First change labels to the array.
Label1 -> Label1(0), Label2 -> Label1(1) ....
VB Code:
Option Explicit
Private Lic As Integer
Private i As Integer
Private Info As String
Private OriginalBackColor As Long
Private OriginalForeColor As Long
Private Sub Form_Load()
OriginalBackColor = Label1(0).BackColor
OriginalForeColor = Label1(0).ForeColor
End Sub
Private Sub cmdCount_Click()
Select Case Lic
Case 0 To 6
With Label1(Lic)
.Caption = Lic + 1
.BackColor = RGB(44, 164, 214)
.ForeColor = RGB(255, 255, 255)
End With
End Select
Lic = Lic + 1
If Lic = 7 Then
MsgBox "The packet of calculations is full", vbInformation, "Attention"
If MsgBox("You want to remove results", vbQuestion + vbYesNo, "questions") = vbYes Then
For i = 0 To 6
With Label1(i)
.Caption = ""
.BackColor = OriginalBackColor
.ForeColor = OriginalForeColor
End With
Next
Lic = 0
End If
End If
End Sub
Private Sub cmdUndo_Click()
Select Case Lic
Case 0 To 6
With Label1(Lic)
.Caption = ""
.BackColor = OriginalBackColor
.ForeColor = OriginalForeColor
End With
End Select
Lic = Lic - 1
If Lic < 0 Then
MsgBox "Resignation is not possible", vbExclamation, "Error"
Lic = 0
End If
End Sub
Re: [RESOLVED]How to make in this loop - please help me
Thank for your solution, it is elegant and simple solution and now works fine.
Many many thanks!!