|
Im not sure of your point. With the second method you also have the option of throwing an exception or returning false (instead of nothing).
the calling methods would be something like this (if the functions didnt handle their own exceptions
1.
<br />
try<br />
course = GetCourse(courseid)<br />
catch<br />
'error handle<br />
end try<br />
if course is nothing then<br />
' do something<br />
else<br />
'do something else<br />
end if<br />
2.
<br />
try<br />
if GetCourse(courseid, course) then<br />
' do something<br />
else<br />
' do something else<br />
end if<br />
catch<br />
' error handle<br />
end try<br />
theyre essentially the same as far as i can tell
|
|
|
|
|
Why use an extra Boolean that does that exact same thing as checking the return for an object?
|
|
|
|
|
If the first function handled all its exceptions internally it would return nothing when there was database error or there was no course with that ID in the database. The calling method wouldnt be able to tell what really happened. With the second function you could differentiate between when the function failed or whether there just wasnt a course with that id in the database. i dont think the calling method should care about how the function failed, just whether it did or not.
Allowing the functions to throw out exceptions in my opinion is a bad idea if you can just handle them internally.
Yes or no?
|
|
|
|
|
Kevin Brydon wrote: If the first function handled all its exceptions internally it would return nothing when there was database error or there was no course with that ID in the database. The calling method wouldnt be able to tell what really happened.
Yes, it would if the function was written to throw an exception and not bury them internally. Depending on the requirements, the function should throw an exception if there was a problem, and let the caller (business rules) decide what to do about it.
Kevin Brydon wrote: i dont think the calling method should care about how the function failed, just whether it did or not.
This is up to the business rules of your app, not you. Think about that. This is not a hard and fast rule in every application.
Kevin Brydon wrote: Allowing the functions to throw out exceptions in my opinion is a bad idea if you can just handle them internally.
There are many cases where the caller needs to know HOW the operation failed and handle the failure in ceratin ways depending on the type of failure. Just returning a True/False doesn't convery any kind of useful failure information back to the caller.
|
|
|
|
|
Sending parameters by reference should generally be avoided if practically possible. As the extra boolean is totally redundant in this case, the choise is rather simple.
Whether the method should return a null reference or throw an exception when it can not return an Course object, that depends on the reason. If it's normal for courses to be missing, it should return a null reference, but if the reason is that an error has occured, it should throw an exception.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: Whether the method should return a null reference or throw an exception when it can not return an Course object, that depends on the reason. If it's normal for courses to be missing, it should return a null reference, but if the reason is that an error has occured, it should throw an exception.
Another possibility which may ease things for the caller would be to have similar versions of the function, one of which will throw an exception if it can't retrieve a course for any reason, and one of which will simply return nothing in the case where it can tell that a course does not exist (it will still throw an exception in case of things like database error and so forth). An application could call the latter if it doesn't know whether the course exists, and the former when it knows that it should and will be in trouble if it doesn't. While returning 'nothing' would probably cause an exception in the latter case, having code throw a deliberate exception is probably better than causing a null-reference exception.
|
|
|
|
|
supercat9 wrote: Another possibility which may ease things for the caller would be to have similar versions of the function, one of which will throw an exception if it can't retrieve a course for any reason, and one of which will simply return nothing in the case where it can tell that a course does not exist (it will still throw an exception in case of things like database error and so forth).
More of a complement than an alternative... That could easily be accomplished with a method that gets a course and throws an exception if it's null:
Public Function GetCourseUnconditionally(courseId As Integer) As Course
Course result = GetCourse(courseId)
If result Is Nothing Then
Throw New AppplicationException("Course not found.");
End If
Return result
End Function
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for your answers. I've decided to get rid on my byref/boolean functions and opted for the first option. I think its the most sensible choice for my application and possibly is the best choice for most apps.
|
|
|
|
|
Hello,
I have a listview with a playlist, in column 0 are the names of the songs and column 1 is the parth/url of the song.
True a textbox i want to search for a song, column 0.
When i press for example ab, all songs beginning with ab must come to top of the listview, all other song under that.
Can anybody help me out with this???
Regards,
idi
|
|
|
|
|
This is another example of using a control to store application data. This is the wrong method to use.
A visual control should show you the data stored in the application in a certain manner, not be used as a repository to store data, which is what you're doing. You should be maintaining this list in a collection (lookup Dictionary or Hashtable) or array or objects, which will be very easily searchable, and filling the ListView with a copy of this data only when needed.
|
|
|
|
|
Hello Dave,
First of all thank you for the reply!
This morning i sarched like you said but i can't find an example of hashable with searching in listview, can you give me a url with sample code or project so i can analyse and learn true that? This would be very helpfull for me as this is totally new for me.
With kin dregards,
idi
|
|
|
|
|
Like I said - forget the ListView. It's not involved in a search at all.
You use a Hashtable or Dictionary, which are both key/value pair collections, to store your data. You've already found thousands of examples of using a Hashtable or Dictionary when you Googled for "vb.net hashtable".
|
|
|
|
|
I would like to know how to send messages phone the computer program to the cell phone, using vb.net
|
|
|
|
|
By using an SMS gateway, there's at least one article on this site, but people who try to use it, quickly find they need to find a local SMS provider.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello every one,
I have a VB 2005 application in which i let the user to store an image in DB.
The users upload really huge images, which are of no good for the application as well.
Is there any method by which I can resize / reduce / shrink the image's physical size, in vb.net
Regards
Nishkarsh
|
|
|
|
|
Sure - you can call a method on the bitmap class to return a thumbnail, or you can manually resize it, by creating a new smaller bitmap and drawing the image onto it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for the response
I was trying things like that on my own and saw something which i need some support on to make my understanding
- I created a sample application with one picture box, one button and one text box
- I loaded a picture(JPEG) in the picture box at design time, of size 2834 KB and dimensions 2816x2112
- On the click of button first thing i do is sane the image from the picture box to "c:\picorg.jpg" as jpg, the size of this picture got reduced to 494KB and dimensions were same as 2816x2112
- Now after that i took ".3" which was entered in the text box and reduced the picture and saved it... I got a really low size and picture dimensions also reduced..
I issue who did the size of picture reduced when i had only loaded it in picture box and the dimensions did not changed..
Regards
Nishkarsh
|
|
|
|
|
The orginal JPEG was probably saved at 90% quality. GDI+ JPEG by default saves it at 75% quality.
|
|
|
|
|
Can we control the quality of image save?
Also, which are the functions of bitmap class were you referring to, can you give some examples also...
I will explain you the whole issue..
- I want to first find the image size
- If the size id bigger then a predefined sizes then reduce the image size and then send it to DB..
Hope that you can help me out with the needful
Regards
Nishkarsh
|
|
|
|
|
You get the original image size from the dimensions of the image and the PixelFormat, but I think you are interested in the file size which you can get a variety of ways from IO. You change the encoder quality by the Quality EncoderParameter. There is no direct relation between file size and encoder quality other than lower quality results in smaller files.
|
|
|
|
|
Hi guys i am working in vb.net 2005,
i want to get some user interface like help ,i cannot develop some good interfaces or i have
nomore new ideas to develop some other interfaces .can any body help me out how to improve my
interface development skills , any link from where i could get some good interface based applicaions.
hello
|
|
|
|
|
There is a microsoft book on interface design, I guess you could buy that
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
I want to write some values into HKEY_CLASSES_ROOT but when i try to do so i get the message that i don't have the permission. (Using Vista). So, is there any way to let my program run as Administrator, without the user right-clicking on the file and choose Run as Administrator?
Thanks in advance,
--Zaegra--
|
|
|
|
|
Nope, there's not a way to run an application as admin without having to log on with an admin account. You need to write registry values to a different part of the registry (HKEY_CURRENT_USER in stead of HKEY_LOCAL_MACHINE) or use .NET's isolated stored functionality which I'd prefer...
|
|
|
|
|
I would've done so, if only I wasn't registering a filetype, which has to be stored in HKEY_CLASSES_ROOT. So there is no way doing this, without the user right clicking on the file and run as administrator?
|
|
|
|