mark.bendal.erica
mark.bendal.erica

Reputation: 57

Reset back to one in every loop

I want to revert the loop to 1 but only in .cmdTable(i).caption = txtPrefix.Text + Str(i) so the name + the number will revert back to 1 because every time a transact it will get the continues number of the loop

I want that Str(i) revert back to 1 on every time i click OK

For example i set the name of the table = TABLE + the number txtEndTable.Text = 5 it will loop from TABLE 1 to TABLE 5 for the second transaction name of the table = MARK + the number txtEndTable.Text = 5 it will generate MARK 6 to MARK 10. I want to get the MARK 1 to MARK 5 for second transaction

Any idea will do

       Public Sub pAddMultipleTables()
       Dim i As Integer
       Dim x As Long
       Dim lcDefaultTop As Integer
       Dim lcLastLeft As Integer
       Dim lcMax As Integer
       Dim lcSpacing As Integer
       Dim lcCurrentTable As Integer
       Dim lcStart As Integer

       lcSpacing = 1200
       lcDefaultTop = 1300
       lcMax = 5
       lcCurrentTable = 1
       lcLastLeft = 240
       lcStart = 0
       x = 0

   With frmTableMap

For i = .cmdTable.ubound + 1 To .cmdTable.ubound + txtEndTable.Text
    Load .cmdTable(i)
    .cmdTable(i).Visible = True
    If lcCurrentTable < lcMax Then
        If lcCurrentTable = 1 Then
            .cmdTable(i).Top = lcDefaultTop
        Else
            .cmdTable(i).Top = (.cmdTable(i - 1).Top + .cmdTable(i - 1).Height) + 120
        End If

        .cmdTable(i).Left = lcLastLeft
        lcCurrentTable = lcCurrentTable + 1

        ' Add to database
        .cmdTable(i).ZOrder 0
        If optSquare.Value = True Then
            .cmdTable(i).ButtonShape = 0
        Else
            .cmdTable(i).ButtonShape = 4
        End If


        .cmdTable(i).Caption = txtPrefix.Text + Str(i)

        bRS.AddNew
        bRS!Name = txtPrefix.Text + Str(i)
        bRS!buttonorder = .cmdTable(i).Index
        bRS!section = .lblSection.Caption
        bRS!ForeColor = .cmdTable(i).ForeColor
        bRS!FontSize = .cmdTable(i).Font.Size
        bRS!Width = .cmdTable(i).Width
        bRS!Height = .cmdTable(i).Height
        bRS!Top = .cmdTable(i).Top
        bRS!Left = .cmdTable(i).Left
        bRS!FontBold = .cmdTable(i).Font.Bold
        bRS!FontName = .cmdTable(i).Font.Name
        bRS!BackColor = .cmdTable(i).BackColor
        bRS!Capacity = txtCapacity.Text
        bRS!Type = "1"
        If optSquare.Value = True Then
            bRS!ButtonShape = 0
        Else
            bRS!ButtonShape = 4
        End If
        bRS.Update



    ElseIf lcCurrentTable = lcMax Then

         If i > 1 Then
            .cmdTable(i).Top = (.cmdTable(i - 1).Top + .cmdTable(i - 1).Height) + 200
            .cmdTable(i).Left = lcLastLeft
         End If

        lcLastLeft = (lcLastLeft + .cmdTable(i).Width) + 120
        lcCurrentTable = 1

        .cmdTable(i).ZOrder 0
        If optSquare.Value = True Then
            .cmdTable(i).ButtonShape = 0
        Else
            .cmdTable(i).ButtonShape = 4
        End If

        .cmdTable(i).Caption = txtPrefix.Text + Str(i)

        bRS.AddNew
        bRS!Name = txtPrefix.Text + Str(i)
        bRS!buttonorder = .cmdTable(i).Index
        bRS!section = .lblSection.Caption
        bRS!ForeColor = .cmdTable(i).ForeColor
        bRS!FontSize = .cmdTable(i).Font.Size
        bRS!Width = .cmdTable(i).Width
        bRS!Height = .cmdTable(i).Height
        bRS!Top = .cmdTable(i).Top
        bRS!Left = .cmdTable(i).Left
        bRS!FontBold = .cmdTable(i).Font.Bold
        bRS!FontName = .cmdTable(i).Font.Name
        bRS!BackColor = .cmdTable(i).BackColor
        bRS!Capacity = txtCapacity.Text
        bRS!Type = "1"
        If optSquare.Value = True Then
            bRS!ButtonShape = 0
        Else
            bRS!ButtonShape = 4
        End If
        bRS.Update


    End If


Next

End With

End Sub

-Thanks guys

Upvotes: 0

Views: 38

Answers (1)

Danieboy
Danieboy

Reputation: 4521

This might not be the most elegant solution but something like this might work.

For i = .cmdTable.lbound + 1 To .cmdTable.ubound + CInt(txtEndTable.Text)

https://msdn.microsoft.com/en-us/library/t9a7w1ac(v=vs.90).aspx

Upvotes: 1

Related Questions