Error Handling Pada Visual Basic 6.0
Database Guide User login Username: * Password: * Request new password Home › Tutorials Error Handling In Visual Basic Level: Despite your best efforts to cover all possible contingencies, run-time errors will occur in your applications. You can and should do all you can to prevent them, but when they happen you have to handle them. Introduction Trapping Errors at Run-Time Building Error Handlers Raising Your Own Errors Summary Introduction The various functions, statements, properties and methods available in Visual Basic and the components used in Visual Basic expect to deal with certain types of data and behavior in your applications. For example, the CDate() function can convert a value to a Date variable. The function is remarkably flexible in the type of information it can accept, but it expects to receive data that it can use to derive a date. If you provide input that it can't convert, it raises error number 13 - "Type mismatch" - essentially saying "I can't handle this input data." In an application, this type of error may be a program logic error (you simply passed the wrong data) or it may be a data entry error on the part of the user (you asked for a date and the user typed a name). In the first case, you need to debug the program to fix the mistake. However, there is no way for you to anticipate the behavior of the end users of the application. If the user enters data you can't handle, you need to deal with the situation. Dealing with errors at run-time is a two step process: Trap the Error Before you can deal with an error, you need to know about it. You use VB's On Error statement to setup an error trap. Handle the Error Code in your error handler may correct an error, ignore it, inform the user of the problem, or deal with it in some other way. You can examine the properties of the Err object to determine the nature of the error. Once the error has been dealt with, you use the Resume statement to return control to the regular flow of the code in the application. In addition to dealing with run-time errors, you may at times want to generate them. This is often done in class modules built as co
Error Handle Error Informasi Sekilas Mengenai Desain Visual Basic 6.0 Tutorial Handle Error di Visual Basic 6.0 Handle Error Membuat project di Visual Basic 6.0 dengan segudang Error memang sungguh menjengkelkan. Apalagi Errornya gak ketahuan dan gak dimengerti kenapa itu bisa terjadi. Untuk itu penting adanya handle-error atau solusi yang bisa menjadi "Warning" bagi developer Visual Basic 6.0 untuk segera mengetahui Jenis Error apa yang tengah terjadi. Atau, Kenapa error itu bisa terjadi. Berikut ini adalah tutorial handle error sesuai pengalaman penulis. Selamat menyimak! On Error Resume Next Apa maksudnya? On Error Resume Next kita gunakan apabila seluruh project yang telah selesai dibuat diyakini tidak akan terjadi bug atau error. Jadi, tidak serta http://www.vb6.us/tutorials/error-handling merta kita tuliskan kode On Error Resume Next ini ditiap blok source code. Lalu, apa maknanya? On Error Resume Next itu memiliki makna sbb: "Bila terjadi error, maka lanjutkan saja! abaikan! lanjutkan apa yang diminta oleh user untuk dieksekusi. Misalnya: Private Sub cmdSimpan_Click() With Adodc1.Recordset .Find "ID_User='"+txtID.Text+"'",,AdSearchForward,1 If .EOF then .AddNew !ID_User = txtID.Text !Nama_Lengkap = txtNama.Text !Alamat = txtAlamat.Text http://vb6-blog.blogspot.com/2015/03/handle-error-vb6-visual-basic-6.html !Telp = txtTelp.Text .Update MsgBox "Data Berhasil Disimpan!", vbInformation, "Simpan: Sukses" Kosongkan_Form Exit sub Else MsgBox "Data ID User sudah ada didatabase!", vbCritical, " Data Found" txtID.SetFocus Exit Sub End If End With End Sub Pada contoh blok source code diatas, secara sekilas, nampak benar, tapi ternyata memunculkan Error pada saat Eksekusinya. Apa error yang mungkin terjadi dari contoh tersebut? Variabel Not Defined! Error tersebut mengacu pada If .EOF then. Hal ini disebabkan karena diatas sekali tidak disebutkan (baca: dipanggil) koneksinya, yang seharusnya menjadi: Private Sub cmdSimpan_Click() KONEKSI_DATABASE ' Panggil ini dulu baru mulai dengan dibawahnya. With Adodc1.Recordset .Find "ID_User='"+txtID.Text+"'",,AdSearchForward,1 If .EOF then .AddNew !ID_User = txtID.Text !Nama_Lengkap = txtNama.Text !Alamat = txtAlamat.Text !Telp = txtTelp.Text .Update MsgBox "Data Berhasil Disimpan!", vbInformation, "Simpan: Sukses" Kosongkan_Form Exit sub Else MsgBox "Data ID User sudah ada didatabase!", vbCritical, " Data Found" txtID.SetFocus Exit Sub End If End With End Sub KONEKSI_DATABASE pada contoh diatas mengacu pada blok koneksi seperti yang digambarkan pada bahasan sebelumnya. Lihat Koneksi_Database! On Error Go To ErrPesan Untuk memastikan tidak akan ada error ata
J2EEOther migration services Downloads Product Demos White Papers Videos/Audio Blogs About About ArtinSoft Our Technology Legacy Software MigrationBoard of http://www.artinsoft.com/vbc_errorhandling.aspx Directors General FAQ JobsPress Room Mobilize.NET Customers Our CustomersCase Studies Partners Partner Program Commercial Deployment Certification ProgramOur Partners Contact Us Mobilize.NET ES Tweet Error Handling Transformation Visual Basic 6.0 and the .NET languages have different error handling techniques; while VB.NET is able to support a small subset of VB6 error handling keywords, C#.NET is not. Also, error handling VB6 features in-code labels that can be used to create confusable “jump” patterns. These patterns are complex to read in VB6 and need to be removed from the resulting code for the sake of maintainability. The Visual Basic Upgrade Companion is able to remove unstructured “spaghetti code” and convert it to structured .NET statements. All error handling pada unused labels are removed from the resulting code, plus the most commonly used “On Error” patterns are currently recognized and replaced for native .NET equivalent “try … catch” blocks. As part of the full conversion of the Visual Basic 6 Error handling schema (On Error ... Goto) to .NET, it is also necessary to convert the Err Object. The following VB6 extract shows a simple usage of the “On Error” statement to avoid a possible division by zero. The flow control of this source code extract will jump to the “ErrorHandler:” label in case there is an arithmetic error. Original VB6 source code Public Sub ErrorHandling(arg1 As Integer) On Error GoTo ErrorHandler Dim var1 As Integer var1 = 1 / arg1 MsgBox var1 MsgBox arg1 Exit Sub ErrorHandler: MsgBox Err.Description, , "Error" End Sub The Upgrade Wizard converts it using the same error management statements as in the original VB6 source code. VB.NET code generated by the Upgrade Wizard Public Sub ErrorHandling(ByRef arg1 As Shor
be down. Please try the request again. Your cache administrator is webmaster. Generated Mon, 10 Oct 2016 02:23:32 GMT by s_ac5 (squid/3.5.20)