473,494 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

openDialog Cancel Button

9 New Member
Hi,

This should hopefully be a quick question. i have an openDialog box in my project, which works when opening a file - however, when no file is selected and the user clicks cancel on the dialog box, the program crashes, because it obviously cannot load a file into memory

The code is as follows
Expand|Select|Wrap|Line Numbers
  1.         Dim strm As System.IO.Stream
  2.         Dim name As System.IO.Stream
  3.         strm = dialogFile.OpenFile()
  4.         txtFileName.Text = dialogFile.FileName.ToString()
  5.         lblSize.Text = FileLen(dialogFile.FileName.ToString())
  6.         If Not (strm Is Nothing) Then
  7.         End If
  8.  
In short, does anyone know what to put in the code for when the user doesnt select a file, and just clicks cancel?

Thanks

Sam
Nov 6 '07 #1
4 2286
Killer42
8,435 Recognized Expert Expert
Can you give us the details of the "crash"?

However, if this is similar enough to the old common dialog control I use in VB6, then there should be a property you can set to determine whether clicking cancel raises an error or simply doesn't return anything.

Perhaps you should simply use a Try construction to handle the error?
Nov 6 '07 #2
dablyz
9 New Member
Can you give us the details of the "crash"?

However, if this is similar enough to the old common dialog control I use in VB6, then there should be a property you can set to determine whether clicking cancel raises an error or simply doesn't return anything.

Perhaps you should simply use a Try construction to handle the error?

Hi,

Yeah, it crashes by hightlighting this portion of code within a button click

With dialogFile
picBox.Image = Image.FromFile(.FileName) <<<
End With

Dim file As String
Dim filesize As Long

file = txtFileName.Text
filesize = FileLen(file)

It then pops up with a box saying 'illegal characters in path'

i can see why - the dialog box doesnt find a path to submit to the picture box - but i dont know how to fix it. Forgive me, but i dont know what a Try construction is!!

Hope you can help

Sam
Nov 6 '07 #3
dablyz
9 New Member
Just an update, i did find out what Try constructions were, but i couldnt figure out what to use in the catch statement. Can anyone advise?

Thanks
Nov 7 '07 #4
Killer42
8,435 Recognized Expert Expert
Just an update, i did find out what Try constructions were, but i couldnt figure out what to use in the catch statement. Can anyone advise?
Let's hope so. I use a much older version, which doesn't have the whole Try...Catch thing, so error handling is completely different.

In any case, you should be able to get around the problem quite easily, by checking the value returned by the dialog, before using it. For example...
Expand|Select|Wrap|Line Numbers
  1. Dim MyFileName As String
  2. MyFileName = dialogFile.FileName
  3. If MyFileName = "" Then
  4.   ' Whatever. No file was chosen.
  5. Else
  6.   picBox.Image = Image.FromFile(MyFileName)
  7. End If
Nov 7 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

13
2295
by: Mike L | last post by:
I have a child form frmDataEntry call up another child form frmDealerSearch. If the user clicks on cancel on frmDealerSearch, I want to close frmDealerSearch and put the focus on txtDealerNum on...
3
5555
by: Mvk | last post by:
Hi; I have a simple aspx form. I have put a textbox and 2 buttons on it. The textbox is linked to a requiredfieldvalidator. Click on button 1 (= ok button) = Store value in textbox in...
3
2392
by: MB | last post by:
Hi, I am doing a project which uses asp.net to develop its forms. The form uses validation web controls to validate the data entered in text boxes. When Cancel Button is pressed which is to exit...
14
2604
by: clintonG | last post by:
This is an appeal for peer support sent to Microsoft as will be noted in closing. The Login control does not include a Cancel button. The only option is to convert the Login control to a...
21
9112
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
4
7802
by: martin | last post by:
Hello, Is there a way to make a kind of "cancel" button on a form? Suppose you accidently changed or overwrote some data in a form, then I'd like to leave this form at once and cancel any...
4
3093
by: MaxMax | last post by:
I have a dialog box with a Cancel button that I want to be activable with the ESC key. In the form the Cancel button is connected to the CancelButton property. Now my problem is that the OnClick...
0
2789
by: Eraser | last post by:
Hi to all .NET guru guys... I have a problem in my delete button inside gridview. How to avoid postback on when i select cancel on confirmation message? But postback is okay on Ok confirmation....
5
13565
by: ghjk | last post by:
I have "cancel" button in php files. I want to write common javascript function for cancel button. When user click cancel button I want to clear php form data. Is it possible? <input id="Cancel"...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.