Help converting VB logic from graphical to memory

Discussion in 'Mac Apps and Mac App Store' started by mmmdreg, Jun 21, 2004.

  1. mmmdreg macrumors 65816


    Apr 14, 2002
    Sydney, Australia
    I was wondering if anyone was willing to help me use the logic in the following code in a memory way instead of in a graphical way..

    the attached file shows what the code is doing..

    Dim stopPermutation As Boolean
    Dim permutation As Long
    Dim theColumn As Integer
    Dim permutationArray() As String
    Public Sub permutate()
        Dim totalPermutations As Double
        Dim progressLength As Integer, progress As Integer
        Dim path As String
        permutation = 0
        totalPermutations = numberOfColumns ^ (numberOfCards - 1)
        stopPermutation = False
        path = App.path & "/test.txt"
        Close #1
        Open path For Append As #1
        Close #1
        Kill path
        Do While stopPermutation = False 'until the limiting factor (all cards in last column) is met
            permutation = permutation + 1
            Call writePermutations(path)
            Call permutateStep
    End Sub
    Private Sub permutateStep()
        Dim reply As Boolean
        Dim foo As Integer  'the card under consideration
        Dim i As Integer
        stopPermutation = True
        For i = 1 To numberOfCards - 1
            If god.card(i).Left < columnDistance(numberOfColumns - 1) + 125 Then
                stopPermutation = False 'has not finished entirely, hence, keep permutating!
                Exit For
            End If
        Next i
        If stopPermutation = True Then Exit Sub 'all cards are in the final column
        foo = 1
        reply = True
        Do While reply = True
            Call rotateCards(reply, foo)
            If reply = True Then foo = foo + 1
    End Sub
    Private Sub rotateCards(reply As Boolean, foo As Integer)
        reply = False
        If foo > (numberOfCards - 1) Then Exit Sub 'cannot have a card greater than the total amount of cards
        theColumn = 1 + ((god.card(foo).Left - cardLeft) / (cardWidth + horizontal)) 'column is stepped up
        If theColumn = numberOfColumns Then
            theColumn = 0 'if the card is in the last column, make it go into the first next round
            reply = True
        End If
        god.card(foo).Left = columnDistance(theColumn) + 125 'card moved based on column increments
    End Sub
    Private Sub writePermutations(path As String)
        Dim i As Integer, j As Integer
        Close #1
            Open path For Append As #1
                For j = 0 To numberOfColumns
                    For i = 1 To god.card.UBound
                        If god.card(i).Left = columnDistance(j) + 125 Then
                            Print #1, permutation & Left(god.card(i).Caption, 4) & j
                        End If
                    Next i
                Next j
            Close #1
    End Sub

    Attached Files:

  2. Nermal Moderator


    Staff Member

    Dec 7, 2002
    New Zealand
    Couldn't help but notice the use of foo :)
    Never used it myself :eek:

    Other than that, I'm too lazy/tired to try to figure out what that code's doing (been awake for 16.5 hours and only had 5 hours sleep last night).

Share This Page