Creating a Function

Jennifer_28

New member
Joined
May 12, 2008
Messages
2
Programming Experience
1-3
I have a function I'd like to create, however, I'm not sure if you ALWAYS have to DIM something. Can anyone shed some light?

VB.NET:
Private Function PerCorp() As Boolean
    If CType(m_screenContact.ResData, Res).IS_CORP_YN.Equals("N") Then
        MsgBox("Please Select C or P", MsgBoxStyle.Exclamation Or MsgBoxStyle.SystemModal Or MsgBoxStyle.OkOnly, "Missing Information")
        Return False
        If CType(m_screenContact.ResData, Res).IS_CORP_YN.Equals("C") Then

        ElseIf CType(m_screenContact.Mas, Mas).COMPANY Is Nothing OrElse CType(m_screenContact.MasData, Mas).COMPANY.Trim.Length = 0 Then
            MsgBox("Please Enter the Corporate Name.", MsgBoxStyle.Exclamation Or MsgBoxStyle.SystemModal Or MsgBoxStyle.OkOnly, "Missing Information")
            Return False
        Else
            Return True
        End If
    End If
End Function
 
I am not sure what you mean exactly but if it is what I am thinking you mean...

No, you don't. You can have functions that do not instantiate/dim anything.
 
At least where I am in programming vb.net I haven't had to do a lot of fuctions, either because the math part isn't that long or I just don't need to.

But in tough situations functions can become a great option.

Hopefully this post works, this site is bad for new users or something;anyone else have a log in problem???
 
You don't "Dim" subs and functions, but it's always good to give them a scope (Private, Protected, Friend, Public)
 
what i am guessing op is talking about is whether there is a need to dim a variable on every function?

like for example he is not dimming and boolean value to be returned and juz returning true or false

there is no need dim for simple things like the above function op have there like for example

VB.NET:
private function subtract(byval a as integer, byval b as integer) as integer
        return a-b
end function

there is no need to dim a variable to like
VB.NET:
private function subtract(byval a as integer, byval b as integer) as integer
     dim ans as integer = a-b   
     return ans
end function

but for more complicated things i suppose variables shld be defined
 
Back
Top