Click here to Skip to main content
15,910,471 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Somebody help me! Pin
Dave Kreskowiak6-Feb-10 5:36
mveDave Kreskowiak6-Feb-10 5:36 
AnswerRe: Somebody help me! Pin
loyal ginger6-Feb-10 9:51
loyal ginger6-Feb-10 9:51 
QuestionMDI children w/progress bars not asynchronously updating Pin
Jim Dolson5-Feb-10 14:32
Jim Dolson5-Feb-10 14:32 
AnswerRe: MDI children w/progress bars not asynchronously updating Pin
Luc Pattyn5-Feb-10 15:00
sitebuilderLuc Pattyn5-Feb-10 15:00 
AnswerRe: MDI children w/progress bars not asynchronously updating Pin
Wayne Gaylard5-Feb-10 17:25
professionalWayne Gaylard5-Feb-10 17:25 
QuestionKeypress Event Double Firing Pin
eddieangel5-Feb-10 13:07
eddieangel5-Feb-10 13:07 
AnswerRe: Keypress Event Double Firing Pin
Luc Pattyn5-Feb-10 13:21
sitebuilderLuc Pattyn5-Feb-10 13:21 
Questiongood coding practices? Pin
kmas37525-Feb-10 8:26
kmas37525-Feb-10 8:26 
Hello everyone,

I would like some opinions on good coding practices.
Below are 3 methods of writing a procedure.
Currently I am coding like method 3.
Any comments, please ?

Criteria: The function must return null if any errors occured.


'Method 1
'If byteIn is null the function will return nothing.
'This function uses two (2) returns.
'I read that using the return statements is perfered (I don't know why).
'The catch will fire if byteIn is nothing.
Public Function ByteArrayToStream(ByRef byteIn() As Byte) As System.IO.MemoryStream
    Try
        Return New System.IO.MemoryStream(byteIn, True)
    Catch ex As Exception
        Return Nothing
    End Try
End Function



'Method 2
'If byteIn is null the function will return nothing.
'This function is assigning the result to the name of the procedure.
'The catch will fire if byteIn is nothing.
Public Function ByteArrayToStream(ByRef byteIn() As Byte) As System.IO.MemoryStream
    Try
        ByteArrayToStream = New System.IO.MemoryStream(byteIn, True)
    Catch ex As Exception
        ByteArrayToStream = Nothing
    End Try
End Function


'Method 3
'If byteIn is null the function will return nothing.
'This function is checking for null so the catch does not have to fire.
'I read somewhere that it is better to pre-check for possible error conditions.
'This function uses only 1 return statement, better?
'I believe there is extra memory overhead (ms2) with this method.
Public Function ByteArrayToStream(ByRef byteIn() As Byte) As System.IO.MemoryStream
    Dim ms2 As IO.MemoryStream = Nothing
    Try
        If byteIn Is Nothing Then Exit Try
        ms2 = New System.IO.MemoryStream(byteIn, True)
    Catch ex As Exception
        ms2 = Nothing
    End Try
    Return ms2
End Function

AnswerRe: good coding practices? [modified] Pin
Ray Cassick5-Feb-10 8:59
Ray Cassick5-Feb-10 8:59 
AnswerRe: good coding practices? Pin
MicroVirus5-Feb-10 11:26
MicroVirus5-Feb-10 11:26 
AnswerRe: good coding practices? Pin
DaveAuld5-Feb-10 20:10
professionalDaveAuld5-Feb-10 20:10 
AnswerRe: good coding practices? Pin
William Winner8-Feb-10 9:44
William Winner8-Feb-10 9:44 
QuestionTaking Screen Shots of PPC Apps Pin
Dominick Marciano5-Feb-10 7:31
professionalDominick Marciano5-Feb-10 7:31 
AnswerRe: Taking Screen Shots of PPC Apps Pin
Smithers-Jones5-Feb-10 12:57
Smithers-Jones5-Feb-10 12:57 
GeneralRe: Taking Screen Shots of PPC Apps Pin
Dominick Marciano6-Feb-10 12:11
professionalDominick Marciano6-Feb-10 12:11 
QuestionHide source code of application Pin
Gagan.205-Feb-10 2:20
Gagan.205-Feb-10 2:20 
AnswerRe: Hide source code of application Pin
Nuri Ismail5-Feb-10 3:14
Nuri Ismail5-Feb-10 3:14 
GeneralRe: Hide source code of application Pin
Gagan.205-Feb-10 3:59
Gagan.205-Feb-10 3:59 
QuestionDifferentiate between a database connection problem and database read problem Pin
Wayne Gaylard5-Feb-10 1:11
professionalWayne Gaylard5-Feb-10 1:11 
AnswerRe: Differentiate between a database connection problem and database read problem Pin
David Skelly5-Feb-10 1:59
David Skelly5-Feb-10 1:59 
GeneralRe: Differentiate between a database connection problem and database read problem Pin
Wayne Gaylard5-Feb-10 3:13
professionalWayne Gaylard5-Feb-10 3:13 
QuestionUpdate VB.NET Windows application ! Pin
jeshra2795-Feb-10 0:44
jeshra2795-Feb-10 0:44 
AnswerRe: Update VB.NET Windows application ! Pin
Dave Kreskowiak5-Feb-10 2:17
mveDave Kreskowiak5-Feb-10 2:17 
QuestionTemporary Files Location Pin
Anubhava Dimri5-Feb-10 0:32
Anubhava Dimri5-Feb-10 0:32 
AnswerRe: Temporary Files Location Pin
Nuri Ismail5-Feb-10 0:42
Nuri Ismail5-Feb-10 0:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.