answersLogoWhite

0

'With block' in visual basic

Updated: 9/14/2023
User Avatar

Wiki User

15y ago

Best Answer

if we want to make our code short and easy then With Block is a very nice choise in some cases. Consider the following code for loading picture in a picture box. On Error Resume Next

CommonDialog1.CancelError = True

CommonDialog1.Filter = "Pictures (*.bmp;*.jpg)|*.bmp;*.jpg"

CommonDialog1.Flags = cdlOFNFileMustExist

CommonDialog1.ShowOpen

If Err.Number = cdlCancel Then

Exit Sub

ElseIf Err.Number <> 0 Then

MsgBox "Error Loading File"

End If

Picture1.Picture = LoadPicture(CommonDialog1.FileName) You may notice that there are a lot of name I have written repeating again and again which may become boring sometime. What about some shortcut. With block is the answer. we can replace the same code as following easyl which is more convenient.

On Error Resume Next

With CommonDialog1

.CancelError = True

.Filter = "Pictures (*.bmp;*.jpg)|*.bmp;*.jpg"

.Flags = cdlOFNFileMustExist

.ShowOpen

If Err.Number = cdlCancel Then

Exit Sub

ElseIf Err.Number <> 0 Then

MsgBox "Error Loading File"

End If

Picture1.Picture = LoadPicture(.FileName)

End With With block must need to be closed with "End With".

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: 'With block' in visual basic
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Objects and its behavior with an example?

Objects are the fundamental building block of Visual Basic; nearly everything you do in Visual Basic involves modifying objects. Every element of Microsoft Word - documents, tables, paragraphs, bookmarks, fields and so on - can be represented by an object in Visual Basic.


What is visual basic control?

Visual Basic Controls work on Visual Studio for Visual Basic and Applications that made by Visual Basic.


The year of invention of visual basic?

Visual Basic was started in 1991.


Who developed visual basic?

Microsoft is the developer of visual basic


Who invented the visual basic?

Visual Basic was created by a team at Microsoft.


What is the difference between visual basic and visual c?

The programming language: Visual Basic is a BASIC-like (or BASIC-derived) language, Visual C is... well C.


Is Visual Basic 6.0 compatible with Visual Basic 2005?

No.


Who is the developer of Visual Basic?

Microsoft is the developer of Visual Basic.


When visual basic started?

Visual Basic was started in 1991.


What is the diff between Visual Basic 2005 and Visual Basic dot net?

Visual Basic 2005 is actually a version of VB.NET (v8.0). The latest version (9.0) is Visual Basic 2008.


How do you install visual basic?

Visual Basic 6.0 Product Key


How do you create a program in visual basic?

arrays programms in visual basic