PS I tried to upload the form, which contains the code, but I got a message that I was not allowed to upload that kind of file, so I attached a text version of the code.
[code]
Private Sub Command1_Click()
Dim Num As Long '5 digit number to be tested
Dim DivL As Long 'Long version of divisior
Dim Quot As Long 'Quotient = Num / Div
Dim m As Long 'Work variable
Dim Div As Integer 'Divisior
Dim j As Integer 'Counter
Dim d(1 To 5) As Integer 'Array to hold digits of Num
Dim n(1 To 5) As Integer 'Array to hold digits of Quot
Dim Match As String 'Variable to signal solution was found
Dim Ans As String 'Dummy variable
For Div = 9 To 2 Step -1
DivL = Div 'We need a long version of Div for next stm.
'Start searching at 10,000 * Div. Smaller numbers give 4 digit quotient
'Go in steps of Div, because we want exact division
For Num = DivL * 10000 To 99999 Step Div
'Code to follow progress of calcualtion
If Num Mod 1000 = 0 Then
Debug.Print "Num is", Num
End If
'Store digits of Num in d(1 to 5)
m = Num
For j = 1 To 5
d(6 - j) = m Mod 10
m = m \ 10
Next j
'Divide Num by DivL
Quot = Num \ DivL
'Now store digits of Quot in n(1 to 5)
m = Quot
For j = 1 To 5
n(6 - j) = m Mod 10
m = m \ 10
Next j
'Check if Quot is the reverse of Num
Match = "Yes"
For j = 1 To 3
If d(j) <> n(j) Then
Match = "No"
Exit For
End If
Next j
If Match = "Yes" Then
Debug.Print "Houray", Num, Div
Exit For
End If
Next Num
If Match = "Yes" Then
Ans = InputBox("We Found Solution")
Exit For
End If
Debug.Print "We are finished with", Div
Next Div
End Sub
[\code]
Attached File(s)
-
ReverseDigits.txt (2.02K)
Number of downloads: 140
This post has been edited by mickey11030: 25 February 2010 - 10:51 AM

New Topic/Question
Reply




MultiQuote



|