VB.net尝试捕获.接球后保持循环 [英] VB.net Try Catch. Keep the Loop after the Catch

查看:64
本文介绍了VB.net尝试捕获.接球后保持循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用尝试捕获",我想将其他类型的Form2.ListBoxes项添加到Form3.ListBoxes中.但是它会在Catch异常之后停止添加.所以我想在异常被捕获后保留Loop

I'm using Try Catch and I want to add into Form3.ListBoxes the items that are into Form2.ListBoxes in other type. But it stop adding after the Catch the exception. So I want to keep the Loop after the exception be caught!

我的程序获取产品并以另一种类型显示相同的产品(例如:我有一个品牌的T恤,但我想要另一个品牌的相同" T恤).

My program get products and show the same products but in another type (Like: I have a T-shirt with a brand, but I want the "same" T-shirt in another brand).

ListBox5是我在Form1中添加的数量.我加载图像很清楚. Form2列表框是按顺序排列的(ListBox1,ListBox2 ...). Form2和Form3具有相同的设计.

ListBox5 are the quantity that I add in Form1. I load Images to be clearly. Form2 Listboxes are in order (ListBox1,ListBox2...). Form2 and Form3 have the same design.

Dim ConnectionString As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\Tabela_Precos.xlsx; Extended Properties=Excel 12.0;")
        ConnectionString.Open()

        Dim ds As New DataSet
        Dim dt As New DataTable
        ds.Tables.Add(dt)
        Dim da

For i = 0 To Form1.ListBox1.Items.Count - 1

        Dim str As String = Form1.ListBox1.Items(i).ToString
        Dim prod As String = str.Substring(2, 3)
        da = New OleDbDataAdapter("SELECT * FROM [Mesa$] WHERE Format([Ref], ""000000000"") like '%" & prod & "%'", ConnectionString)

        da.Fill(dt)
        Try
            ListBox1.Items.Add(dt.Rows(i).Item(0))
            ListBox2.Items.Add(dt.Rows(i).Item(1))
            ListBox3.Items.Add(dt.Rows(i).Item(3))
            ListBox4.Items.Add(dt.Rows(i).Item(5))
            ListBox5.Items.Add(Form1.ListBox5.Items(i))
            ListBox6.Items.Add(ListBox4.Items(i) * ListBox5.Items(i))
        Catch ex As Exception
        End Try
    Next

我需要Try-Catch.我正在执行查询,如果数据库中不存在该行,它将停止.停止后如何继续循环播放?

I need the Try-Catch. I'm doing a Query and if doesn't exist the line in DataBase it stop. How can I keep doing the Loop, after stop?

这些是程序正在运行的图像(已被编辑):

These are the images with program running (they are edited):

Form1

Form2

Form3

推荐答案

当您说抓住陷阱后保持循环" 时,您已经回答了自己的问题.您希望循环继续继续或移至下一个迭代.所有这些都是VB关键字,建议您对于下一个语句了解For循环的工作原理.

You have answered the question yourself when you say "keep the loop after the catch". You want your loop to continue, resume or move to the next iteration. All of these are VB keywords and I recommend you review For Next Statement to understand how a For loop works.

这是完成此操作的几种方法之一.

Here is one of a few ways you can accomplish this.

没有错误处理,只需忽略并继续:

With no error handling, just ignore and continue:

Try
    ...
Catch ex As Exception
    Continue For
End Try

这篇关于VB.net尝试捕获.接球后保持循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆