# 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

Joined:
Apr 14, 2002
Location:
Sydney, Australia
#1
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..

Code:
```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
Loop

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

Do While reply = True
If reply = True Then foo = foo + 1
Loop

End Sub

Private Sub rotateCards(reply As Boolean, foo As Integer)

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
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
```

File size:
33.7 KB
Views:
20

### Staff Member

Joined:
Dec 7, 2002
Location:
New Zealand
#2
Couldn't help but notice the use of foo
Never used it myself

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).