Results 1 to 13 of 13

Thread: [RESOLVED]How to make in this loop - please help me

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    [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:
    1. Dim Lic As Integer
    2. Select Case Lic
    3.  
    4. Case 0
    5.  
    6.     With lbl1
    7.        .caption = 1
    8.        .Backcolor = RGB ( 44, 164, 214)
    9.        .Forecolor = RGB (255, 255, 255)
    10.    End With
    11.        Lic = 1
    12. Case 1
    13.  
    14.     With lbl2
    15.        .caption = 2
    16.        .Backcolor = RGB ( 44, 164, 214)
    17.        .Forecolor = RGB (255, 255, 255)
    18.    End With
    19.        Lic = 2
    20. …….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
    Last edited by Tamgovb; Mar 10th, 2006 at 05:59 AM.
    I know, I know, my English is bad, sorry .....

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    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
    Chris

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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.
    Last edited by Tamgovb; Feb 18th, 2006 at 09:28 AM.
    I know, I know, my English is bad, sorry .....

  4. #4
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    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?
    Chris

  5. #5
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    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:
    1. Public Sub ChangeLabelColor(index As Integer)
    2.  
    3.     With lbl(index)
    4.     .Caption = 1
    5.     .BackColor = RGB(44, 164, 214)
    6.     .ForeColor = RGB(255, 255, 255)
    7.     End With
    8.  
    9. End Sub
    oh1mie/Vic


  6. #6
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    Re: How to make in this loop - please help me

    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.
    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
    Last edited by mikee_phil; Feb 18th, 2006 at 10:00 AM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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
    Last edited by Tamgovb; Feb 18th, 2006 at 11:27 AM.
    I know, I know, my English is bad, sorry .....

  8. #8
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    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:
    1. Static Lic As Integer
    2. Select Case Lic
    oh1mie/Vic


  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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.
    Attached Files Attached Files
    I know, I know, my English is bad, sorry .....

  10. #10
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    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:
    1. MsgBox "The packet of calculations is full", vbInformation, "Attention"
    2.      If MsgBox("You want to remove results", vbQuestion + vbYesNo, "questions") = vbYes Then
    3.         For i = 1 To 7
    4.           Controls("Label" & i).Caption = ""
    5.         Next
    6.      End If
    oh1mie/Vic


  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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.
    I know, I know, my English is bad, sorry .....

  12. #12
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    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:
    1. Option Explicit
    2.  
    3. Private Lic  As Integer
    4. Private i    As Integer
    5. Private Info As String
    6.  
    7. Private OriginalBackColor As Long
    8. Private OriginalForeColor As Long
    9. Private Sub Form_Load()
    10.  
    11.   OriginalBackColor = Label1(0).BackColor
    12.   OriginalForeColor = Label1(0).ForeColor
    13.  
    14. End Sub
    15. Private Sub cmdCount_Click()
    16.  
    17.     Select Case Lic
    18.     Case 0 To 6
    19.        With Label1(Lic)
    20.            .Caption = Lic + 1
    21.            .BackColor = RGB(44, 164, 214)
    22.            .ForeColor = RGB(255, 255, 255)
    23.        End With
    24.     End Select
    25.     Lic = Lic + 1
    26.    
    27.     If Lic = 7 Then
    28.         MsgBox "The packet of calculations is full", vbInformation, "Attention"
    29.         If MsgBox("You want to remove results", vbQuestion + vbYesNo, "questions") = vbYes Then
    30.            For i = 0 To 6
    31.                With Label1(i)
    32.                .Caption = ""
    33.                .BackColor = OriginalBackColor
    34.                .ForeColor = OriginalForeColor
    35.                End With
    36.            Next
    37.            Lic = 0
    38.         End If
    39.     End If
    40.  
    41. End Sub
    42. Private Sub cmdUndo_Click()
    43.  
    44.     Select Case Lic
    45.     Case 0 To 6
    46.        With Label1(Lic)
    47.            .Caption = ""
    48.            .BackColor = OriginalBackColor
    49.            .ForeColor = OriginalForeColor
    50.        End With
    51.     End Select
    52.     Lic = Lic - 1
    53.     If Lic < 0 Then
    54.        MsgBox "Resignation is not possible", vbExclamation, "Error"
    55.        Lic = 0
    56.     End If
    57.    
    58. End Sub
    Last edited by oh1mie; Feb 18th, 2006 at 02:20 PM.
    oh1mie/Vic


  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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!!
    I know, I know, my English is bad, sorry .....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width