0

我试着找了几个小时,却找不到我要找的东西。我对编程很陌生,但仍然不知道如何很好地操作数据......

我想做的是:

我目前正在使用 4 种表格。称他们为frm1、frm2、frm3、frm4。我正在尝试根据其他 3 种表格中提供的信息在 frm4 中创建成品。我需要在此打印数据order line = "0000 ---- --- --- --- --- --- ---".我目前有first two lines "0000 ----"我想要的方式。我遇到的问题是这些"--- --- --- --- --- --- ---"行将从另一种形式 frm3.lst3.items 填充,当我将行移过来并从列表中的每个项目中删除前两个数字时,我只能插入它们进入“线”的前三个破折号,不能将它们插入。

frm4.lst4 看起来像这样:

"0000 aaaa --- --- --- --- --- --- ---"              
"0000 bbbb --- --- --- --- --- --- ---"           
"0000 cccc --- --- --- --- --- --- ---"           
"0000 dddd --- --- --- --- --- --- ---"          
"0000 eeee --- --- --- --- --- --- ---"                        
"0000 ffff --- --- --- --- --- --- ---"              
"0000 gggg --- --- --- --- --- --- ---"                  
"0000 hhhh --- --- --- --- --- --- ---"      

frm3.lst3

1 aaaa                                                
2 dddd                                                   
3 aaaa                                                   
4 zzzz                                                
5 aaaa                                         
6 aaaa                                      
7 aaaa                                               
8 aaaa                                                
9 aaaa 

我需要将frm3中的字母与frm4中的字母匹配,并将带有破折号的数字添加到"---"使其看起来像这样"0000 aaaa 001 003 005 006 007 008 009".

' already found strCode and that = aaaa                      
Dim possition As String                                
        For Each strCode In lstTeamResults.Items                        
            strLine = "0000 ---- --- --- --- --- --- --- ---"                      
            Mid(strLine, 5, 4) = strCode 

' 我知道 instr 给出了下一个可用“---”的 int 位置。只是不知道如何在命令中使用它,该命令将"---"使用正确的代码填充下一个打开..

        InStr(10, strLine, "---")

        For Each item In frmRM3.lst3.Items

            possition = item
            ' this code returns the number 1, 2, 3....
            intPossition = InStr(item, " ")
            possition = Trim(Mid(possition, 1, intPossition - 1))
        Next


    Next
   lst4.items.add(strLine)

任何帮助是极大的赞赏。先谢谢了!

4

2 回答 2

0

这是我的解决方案,我认为它是独立的,您应该学习如何使用 Substring 和 IndexOf 而不是这些函数。

        Dim strLine As String = "0000 ---- --- --- --- --- --- --- ---"


        Mid(strLine, 6, 4) = strCode

        For Each item As String In ListBox2.Items

            possition = item
            ' this code returns the number 1, 2, 3....
            intPossition = InStr(item, " ")
            Dim lineNumber As String
            lineNumber = Mid(item, 1, intPossition - 1)
            Dim code As String
            code = Mid(item, intPossition + 1, 4)
            If strCode = code Then
                'Position of next available dashes
                Dim availablePosition As Integer
                availablePosition = InStr(1, strLine, "---")
                If availablePosition <> 0 Then
                    'Pad number with zeros
                    Dim numberPaddedWithZeros As String
                    numberPaddedWithZeros = "000" & lineNumber
                    numberPaddedWithZeros = Mid(numberPaddedWithZeros, Len(numberPaddedWithZeros) - 3 + 1, 3)

                    'Replace available positions
                    Mid(strLine, availablePosition, 3) = numberPaddedWithZeros
                End If
            End If

        Next
        ListBox1.Items.Add(strLine)
于 2013-05-08T04:03:18.367 回答
0

感谢 Daniel Victoria 提供的帮助。我更改了您给我的代码以适应我的程序。认为如果我发布实际问题会太长,而且可能还不够清楚。这是我到目前为止所拥有的:

' 此代码在 0000 之后添加 4 个破折号上的 4 个字符,以便以下代码并使用它将数字添加到“--- --- --- --- --- --- - ——”

Private Sub btnCalculateResults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateResults.Click
    Dim intPossition As Integer
    Dim strLine As String = ""
    Dim strSchoolCode As String


    strLine = "0000 ---- --- --- --- --- ---  --- ---"
    strSchoolCode = ""
    lstTeamResults.Items.Clear()


    For Each team As String In frmRM1000.lstTeam.Items
        strSchoolCode = team
        intPossition = InStr(1, strSchoolCode, "|")
        strSchoolCode = Trim(Mid(strSchoolCode, 1, intPossition - 1))

        strLine = "0000  ---- --- --- --- --- --- --- ---"
        Mid(strLine, 6, 4) = strSchoolCode

        lstTeamResults.Items.Add(strLine)
    Next

'这是丹尼尔帮助我修复的代码'现在我只需要循环此代码,以便填充其余字段'总共需要填充 9 行:

“0000 AUBH --- --- --- --- --- --- ---”
“0000 GSH- --- --- --- --- --- --- --- "
"0000 NBHS --- --- --- --- --- --- ---"
"0000 OHXS --- --- --- --- --- --- --- “'这个人需要去
“0000 OHXS 001 002 003 004 005 006 007”'这个人很好
“0000 QRHS --- --- --- --- --- --- ---”
“0000 WBCH --- --- --- --- --- --- ---”
“0000 WDHS --- --- --- --- --- --- ---”
"0000 WHS- --- --- --- --- --- --- ---"
"0000 WSHS --- --- --- --- --- --- --- "

'这是上述输出的代码:

Dim strLine1 As String = "0000 ---- --- --- --- --- --- --- ---" Dim possition As String Dim lineNumber As String

    Mid(strLine, 6, 4) = strSchoolCode
    'For Each item In
    '    lineNumber = item

    'Next

    For Each runner As String In frmRM3000.lstSyncTimeBibs.Items 'lstTeamResults.Item

        possition = runner
        ' this code returns the runner possiton number 1, 2, 3....
        intPossition = InStr(runner, " ")


        lineNumber = Mid(runner, 1, intPossition - 1)
        Dim code As String
        code = Mid(strLine, 6, 4)
        If strSchoolCode = code Then
            'Position of next available dashes
            Dim availablePosition As Integer
            availablePosition = InStr(1, strLine, "---")
            If availablePosition <> 0 Then
                'Pad number with zeros
                Dim numberPaddedWithZeros As String
                numberPaddedWithZeros = "00" & lineNumber
                numberPaddedWithZeros = Mid(numberPaddedWithZeros, Len(numberPaddedWithZeros) - 3 + 1, 3)

                'Replace available positions
                Mid(strLine, availablePosition, 3) = numberPaddedWithZeros
            End If
        End If

    Next
    lstTeamResults.Items.Add(strLine)

这确实将代码添加到“--- --- --- --- --- --- ---”行,但它只将其添加到代码的一行并在第 5 行执行。我需要它来为所有线路做这件事。谢谢您的帮助 :)

于 2013-05-10T01:11:47.800 回答