初學者 VB 程式 Function 問題 急

takeNumber(TextBox1.Text) <==== 假設TextBox1.Text為CC0001

Private Function takeNumber(ByVal pStr As String) As String

Dim s As String = String.Empty

Dim n As Integer = 0

While Val(pStr) = 0

s = s & pStr.Substring(0, 1)

pStr = pStr.Substring(1)

End While

n = Val(pStr) + 1

takeNumber = String.Format("{0}{1}", s, n.ToString("000"))

End Function

我要如何修改才能讓TextBox2.Text = CC0002

1 個解答

評分
  • John
    Lv 7
    6 年前
    最佳解答

    Private Function NextNumber(ByVal value As String) As String

    Dim result As Integer = CInt(value.SubString(2)) + 1

    Return String.Format("{0}{1}", value.SubString(0,2), result.ToString("00000"))

    End Function

還有問題?馬上發問,尋求解答。