dmqueen
Board Regular
- Joined
- Aug 5, 2014
- Messages
- 53
I'm used to Implicit Return statements, so I'm probably doing this wrong. My compiler gives me a Variable not defined error for my return statement for my function. Someone please take a look and let me know what I've got wrong in my return stmt? Bless you!
<code>
Public Function fGenerateNextPartNumber(LastPartIn As String) As String
Dim LastPartNO As String
LastPartNO = LastPartIn
'LastPartNo = ActiveCell.Value
Dim NewStrPartNo As String
Dim strseparator As String
Dim strPartNo As String
Dim strLastPartNo As String
strPartNo = ActiveSheet.Name()
Dim strSeperator As String
Dim strLastSeqPartNo As String
strLastPartNo = (Right(LastPartIn, 4))
'debugging
Call MsgBox(LastPartNO)
Dim strNewSeqPartNo As String
Dim intNewSeqNo As Integer
Dim intLastSeqNo As Integer
'handle special case separators HERE!
Dim lastseqNo As Integer
intLastSeqNo = CInt(strLastPartNo)
intNewSeqNo = lastseqNo + 1
'debugging
Call MsgBox(strPartNo)
If strPartNo = "180" Or strPartNo = "300" Or strPartNo = "310" Or strPartNo = "320" Or strPartNo = "330" Or strPartNo = "970" Or strPartNo = "681" Or strPartNo = "981" Then
strseparator = "-1-"
Else: strseparator = "-0-"
End If
NewStrPartNo = strPartNo + strseparator + CStr(intNewSeqNo)
'return statement
fGenerateNextPartNo = NewStrPartNo
End Function
</code>
I've tried creating the string in the return stmt instead of in NewstPartNo first, to no avail.
<code>
Public Function fGenerateNextPartNumber(LastPartIn As String) As String
Dim LastPartNO As String
LastPartNO = LastPartIn
'LastPartNo = ActiveCell.Value
Dim NewStrPartNo As String
Dim strseparator As String
Dim strPartNo As String
Dim strLastPartNo As String
strPartNo = ActiveSheet.Name()
Dim strSeperator As String
Dim strLastSeqPartNo As String
strLastPartNo = (Right(LastPartIn, 4))
'debugging
Call MsgBox(LastPartNO)
Dim strNewSeqPartNo As String
Dim intNewSeqNo As Integer
Dim intLastSeqNo As Integer
'handle special case separators HERE!
Dim lastseqNo As Integer
intLastSeqNo = CInt(strLastPartNo)
intNewSeqNo = lastseqNo + 1
'debugging
Call MsgBox(strPartNo)
If strPartNo = "180" Or strPartNo = "300" Or strPartNo = "310" Or strPartNo = "320" Or strPartNo = "330" Or strPartNo = "970" Or strPartNo = "681" Or strPartNo = "981" Then
strseparator = "-1-"
Else: strseparator = "-0-"
End If
NewStrPartNo = strPartNo + strseparator + CStr(intNewSeqNo)
'return statement
fGenerateNextPartNo = NewStrPartNo
End Function
</code>
I've tried creating the string in the return stmt instead of in NewstPartNo first, to no avail.