J
Jeff Wagner
I am trying to rewrite an old program written in VB. I can't figure out how to do the following:
if SumOfNumbers == 11 or SumOfNumbers == 22 or SumOfNumbers == 33:
return
else:
I2 = int(SumOfNumbers / 10)
F2 = SumOfNumbers - (I2 * 10)
SumOfNumbers = I2 + F2
What I want this thing to do is if the SumOfNumbers is equivalent to any of the above, I want it to
stop and return from whence it came. In VB, I had used a GOTO statement which doesn't exist in
Python. I can not, for the life of me, figure out how to replace the GOTO function I was using. I
have tried many options, i.e., continue, break, return, return SumOfNumbers, return(), and none of
them work.
This is what I am trying to accomplish:
def MasterNumberRoutine(SumOfNumbers):
#This routine determines if the input is a master number and, if not,
#adds the resultant
if SumOfNumbers == 11 or 22 or 33:
#go back to where you came from, don't continue ...
I2 = int(SumOfNumbers / 10)
F2 = SumOfNumbers - (I2 * 10)
SumOfNumbers = I2 + F2
if SumOfNumbers = 10:
#If SumOfNumbers = 10, then set it's value to 1
SumOfNumbers = 1
elif SumOfNumbers > 9:
MasterNumberRoutine()
else:
return SumOfNumbers
This is the old routine from VB which worked ... I know, it's crappy code. It's the first program I
wrote many years ago.
Public Sub MasterNumberRoutine()
On Error GoTo ErrorHandler
'This routine determines if the input is a master number and, if not,
'adds the resultant
Dim I2 As Integer
Dim F2 As Integer
If SumOfNumbers = 11 Or SumOfNumbers = 22 Or SumOfNumbers = 33 Then
GoTo Done
End If
I2 = Int(SumOfNumbers / 10)
F2 = SumOfNumbers - (I2 * 10)
SumOfNumbers = I2 + F2
If SumOfNumbers = 10 Then
GoTo Check10
ElseIf SumOfNumbers > 9 Then
MasterNumberRoutine
Else
GoTo Done
End If
Check10:
'If SumOfNumbers = 10, then set it's value to 1
SumOfNumbers = 1
Done:
Exit_Next:
Exit Sub
ErrorHandler:
MsgBox "Error: " & Err.Number _
& vbCrLf & Err.Description, _
vbOKOnly, "Unexpected Error"
Call ErrLogger("MasterNumberRoutine")
Resume Exit_Next
End Sub
Thanks, Jeff
if SumOfNumbers == 11 or SumOfNumbers == 22 or SumOfNumbers == 33:
return
else:
I2 = int(SumOfNumbers / 10)
F2 = SumOfNumbers - (I2 * 10)
SumOfNumbers = I2 + F2
What I want this thing to do is if the SumOfNumbers is equivalent to any of the above, I want it to
stop and return from whence it came. In VB, I had used a GOTO statement which doesn't exist in
Python. I can not, for the life of me, figure out how to replace the GOTO function I was using. I
have tried many options, i.e., continue, break, return, return SumOfNumbers, return(), and none of
them work.
This is what I am trying to accomplish:
def MasterNumberRoutine(SumOfNumbers):
#This routine determines if the input is a master number and, if not,
#adds the resultant
if SumOfNumbers == 11 or 22 or 33:
#go back to where you came from, don't continue ...
I2 = int(SumOfNumbers / 10)
F2 = SumOfNumbers - (I2 * 10)
SumOfNumbers = I2 + F2
if SumOfNumbers = 10:
#If SumOfNumbers = 10, then set it's value to 1
SumOfNumbers = 1
elif SumOfNumbers > 9:
MasterNumberRoutine()
else:
return SumOfNumbers
This is the old routine from VB which worked ... I know, it's crappy code. It's the first program I
wrote many years ago.
Public Sub MasterNumberRoutine()
On Error GoTo ErrorHandler
'This routine determines if the input is a master number and, if not,
'adds the resultant
Dim I2 As Integer
Dim F2 As Integer
If SumOfNumbers = 11 Or SumOfNumbers = 22 Or SumOfNumbers = 33 Then
GoTo Done
End If
I2 = Int(SumOfNumbers / 10)
F2 = SumOfNumbers - (I2 * 10)
SumOfNumbers = I2 + F2
If SumOfNumbers = 10 Then
GoTo Check10
ElseIf SumOfNumbers > 9 Then
MasterNumberRoutine
Else
GoTo Done
End If
Check10:
'If SumOfNumbers = 10, then set it's value to 1
SumOfNumbers = 1
Done:
Exit_Next:
Exit Sub
ErrorHandler:
MsgBox "Error: " & Err.Number _
& vbCrLf & Err.Description, _
vbOKOnly, "Unexpected Error"
Call ErrLogger("MasterNumberRoutine")
Resume Exit_Next
End Sub
Thanks, Jeff