none
想请帮忙看有关number load 的代码,我发现我的代码有时会重算过我已算过的数目 RRS feed

  • 问题

  • 我篇写了3 个number load 的代码。我用.ini file来记录数字。我发现我用.ini file里的数字会与控制其他.ini file的数字联系

    以下是我的代码

      Private Sub NumberLoadCAMR()
            For i As Integer = 1 To 1000000
                ids.Add(i)
            Next
            Dim sb As StringBuilder = New StringBuilder(50)
            GetPrivateProfileString("MyCAMR", "count", "", sb, 50, camera)
            count = CInt(sb.ToString)
            Dim idstring As String = "2" & ids(count).ToString().PadLeft(7, "0"c)
            txtNumberLoad.Text = idstring

        End Sub

       Private Sub NumberLoadAccessory()

            For i As Integer = 1 To 1000000
                ids.Add(i)
            Next
            Dim sb As StringBuilder = New StringBuilder(50)
            GetPrivateProfileString("MyACSR", "count", "", sb, 50, accessory)
            count = CInt(sb.ToString)
            Dim idstring As String = "1" & ids(count).ToString().PadLeft(7, "0"c)
            txtNumberLoad.Text = idstring

        End Sub

    Private Sub NumberLoadPC()
            For i As Integer = 1 To 1000000
                ids.Add(i)
            Next
            Dim sb As StringBuilder = New StringBuilder(50)
            GetPrivateProfileString("MyPC", "count", "", sb, 50, pc)
            count = CInt(sb.ToString)
            Dim idstring As String = "6" & ids(count).ToString().PadLeft(7, "0"c)
            txtNumberLoad.Text = idstring
        End Sub

      Private Sub GetNextNumberPC()
            count += 1
            Dim idstring As String = "" & ids(count).ToString().PadLeft(7, "0"c)
            TextBox4.Text = idstring
            Dim sb As StringBuilder = New StringBuilder(50)
            WritePrivateProfileString("Myini", "count", count.ToString(), pc)
        End SubPrivate Sub GetNextNumberACSR()
            count += 1
            Dim idstring As String = "" & ids(count).ToString().PadLeft(7, "0"c)
            TextBox1.Text = idstring
            Dim sb As StringBuilder = New StringBuilder(50)
            WritePrivateProfileString("Myini", "count", count.ToString(), accessory)
        End Sub

     Private Sub GetNextNumberCAMR()
            count += 1
            Dim idstring As String = "" & ids(count).ToString().PadLeft(7, "0"c)
            TextBox1.Text = idstring
            Dim sb As StringBuilder = New StringBuilder(50)
            WritePrivateProfileString("Myini", "count", count.ToString(), camera)
        End Sub

     WritePrivateProfileString("Myini", "count", count.ToString, camera)

    WritePrivateProfileString("Myini", "count", count.ToString, pc)

    WritePrivateProfileString("Myini", "count", count.ToString, accessory)

    2020年6月10日 13:48

答案

  • Hi christing,

    我发现你的 count 变量是共用的,为了不让每个函数之间都影响 count 的值,要为 camera,pc 和 accessory 都定义一个count.

    如:

        Dim cameraCount As Integer = 0
        Dim pcCount As Integer = 0
        Dim accessoryCount As Integer = 0
        Private Sub NumberLoadCAMR()
            For i As Integer = 1 To 1000000
                ids.Add(i)
            Next
            Dim sb As StringBuilder = New StringBuilder(50)
            GetPrivateProfileString("MyCAMR", "count", "", sb, 50, camera)
            cameraCount = CInt(sb.ToString)
            Dim idstring As String = "2" & ids(cameraCount).ToString().PadLeft(7, "0"c)
            txtNumberLoad.Text = idstring
        End Sub
        Private Sub GetNextNumberCAMR()
            cameraCount += 1
            Dim idstring As String = "" & ids(cameraCount).ToString().PadLeft(7, "0"c)
            TextBox1.Text = idstring
            Dim sb As StringBuilder = New StringBuilder(50)
            WritePrivateProfileString("Myini", "count", cameraCount.ToString(), camera)
        End Sub
        Private Sub NumberLoadAccessory()
    
            For i As Integer = 1 To 1000000
                ids.Add(i)
            Next
            Dim sb As StringBuilder = New StringBuilder(50)
            GetPrivateProfileString("MyACSR", "count", "", sb, 50, accessory)
            accessoryCount = CInt(sb.ToString)
            Dim idstring As String = "1" & ids(accessoryCount).ToString().PadLeft(7, "0"c)
            txtNumberLoad.Text = idstring
        End Sub
        Private Sub GetNextNumberACSR()
            accessoryCount += 1
            Dim idstring As String = "" & ids(accessoryCount).ToString().PadLeft(7, "0"c)
            TextBox1.Text = idstring
            Dim sb As StringBuilder = New StringBuilder(50)
            WritePrivateProfileString("Myini", "count", accessoryCount.ToString(), accessory)
        End Sub
        Private Sub NumberLoadPC()
            For i As Integer = 1 To 1000000
                ids.Add(i)
            Next
            Dim sb As StringBuilder = New StringBuilder(50)
            GetPrivateProfileString("MyPC", "count", "", sb, 50, pc)
            pcCount = CInt(sb.ToString)
            Dim idstring As String = "6" & ids(pcCount).ToString().PadLeft(7, "0"c)
            txtNumberLoad.Text = idstring
        End Sub
        Private Sub GetNextNumberPC()
            pcCount += 1
            Dim idstring As String = "" & ids(pcCount).ToString().PadLeft(7, "0"c)
            TextBox4.Text = idstring
            Dim sb As StringBuilder = New StringBuilder(50)
            WritePrivateProfileString("Myini", "count", pcCount.ToString(), pc)
        End Sub


    如果仍然存在问题,请提供你如何调用这些函数的更多细节,这样可以方便我们进行测试。

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.





    2020年6月11日 1:55
    版主