使用新参数

时间:2017-05-23 08:12:27

标签: vb.net

我对使用新参数重新输入button_click事件的最佳方法有疑问,而无需用户再次点击。

基本上,代码在Excel工作表中搜索字符串。如果找不到该字符串,我希望它提示用户更改工作表,然后再次搜索代码。

显然是来自['从这里]评论['在这里]评论将完全符合我的要求,但由于GOTO被视为瘟疫,我认为我应该远离它。

还有其他方法吗?

Private Sub button1_Click(sender As Object, e As RoutedEventArgs) Handles button1.Click


If (radioButton1.IsChecked) Then
    Dim Choice As String = My.Application.myYear
    ' TO HERE
    If Not (My.Application.XLws Is My.Application.XLwb.Worksheets(Choice)) Then
        My.Application.XLws = My.Application.XLwb.Worksheets(Choice)
    End If

    Dim SearchStr As String = Trim(textBox1.Text)
    If Not (SearchStr.Contains(" ")) Then
        SearchStr = SearchStr.Insert(2, " ")
    End If

    Dim rRng As Long
    rRng = LastUsedCell(My.Application.XLws).item2
    Debug.Print(SearchStr)

    Dim SrcR As String = "A" & rRng
    Dim Serials As Excel.Range = My.Application.XLws.Range("A1", SrcR)
    Dim fRange As Excel.Range = ExcelFind(Serials, SearchStr)

    ' If no serial is found, prompt for a new year
    If (fRange Is Nothing) Then
        Debug.Print("Serial not found")
        Choice = InputBox("Try another year", "Serial not found in " & My.Application.myYear, "Auto", 100, 100)
        ' FROM HERE
        Return
    End If
    ' etc

0 个答案:

没有答案