?
Solved

Sharing functions by storing in a class. Is this right?

Posted on 2005-05-03
7
Medium Priority
?
200 Views
Last Modified: 2012-05-05
Instead of using Include files I'd like to share my functions by creating a class. I thought that the code below (in a .vb file) would be correct but it doesnt seem to work. What am I missing?


Imports Microsoft.VisualBasic

Public Class mrlTools

    Public Shared Function fncCreateDuration(ByVal strProduct As String, ByVal strDuration As String) As String

        If strProduct = "1" Then
            fncCreateDuration = strDuration & " days"
        ElseIf strProduct = "2" Then
            fncCreateDuration = strDuration & " days per trip"
        ElseIf strProduct = "3" Then
            fncCreateDuration = strDuration & " months"
        End If

        Return String.Empty

    End Function


    Public Shared Function fncDestination(ByVal str As String) As String

        If str = "1" Then
            fncDestination = "Europe"
        ElseIf str = "2" Then
            fncDestination = "Worldwide"
        ElseIf str = "3" Then
            fncDestination = "Australia & New Zealand"
        End If

        Return String.Empty

    End Function
End Class

And then the method can be called like this:

[CODE]mrlTools.fncDestination(string)[/CODE]


0
Comment
Question by:gilkesy
  • 3
  • 3
7 Comments
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13919667
It seems fine.
What do you mean by saying it does not work?
0
 

Author Comment

by:gilkesy
ID: 13919718
The function "fncDestination" is used to output a description from a string. So if the string passed to it is "2" then it should output "Worldwide".

So if I pass a session variable to the function containing "2" then it should output the string "Worldwide"

So this code should fill a Label Control with the string "Worldwide"

lblGeographicArea.Text = mrlTools.fncDestination(Session("GeographicArea"))

But when the page is "run", the Label Control is staying blank.

Help?
0
 

Accepted Solution

by:
honda99 earned 300 total points
ID: 13919738
you returning null values then how do you expect?

Return String.Empty

try:

  If strProduct = "1" Then
            fncCreateDuration = strDuration & " days"
        ElseIf strProduct = "2" Then
            fncCreateDuration = strDuration & " days per trip"
        ElseIf strProduct = "3" Then
            fncCreateDuration = strDuration & " months"
        End If

return fncCreateDuration
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Expert Comment

by:laotzi2000
ID: 13919775
since you return String.Empty, you will always get empty string
0
 
LVL 12

Assisted Solution

by:laotzi2000
laotzi2000 earned 200 total points
ID: 13919783
 Public Shared Function fncDestination(ByVal str As String) As String

        If str = "1" Then
            fncDestination = "Europe"
        ElseIf str = "2" Then
            fncDestination = "Worldwide"
        ElseIf str = "3" Then
            fncDestination = "Australia & New Zealand"
        Else
            fncDestination = String.Empty
        End If

    End Function
0
 

Author Comment

by:gilkesy
ID: 13919861
Lol.

Thanks. Another stupid and basic mistake from yours truly.

I'll get there in the end.

Thanks again.
0
 

Author Comment

by:gilkesy
ID: 13920005
Hey guys - one other thing.

I also use include files to show an HTML table depending on a condition (each include file conatins a single file):

                    <% If Session("AgeGroup") = "1" Then%>
                    <% If Session("Product") = "1" Then%>
                    <!--#include file="quote-engine/cover-single.html" -->
                    <% ElseIf Session("Product") = "2" Then%>
                    <!--#include file="quote-engine/cover-annual.html" -->
                    <% ElseIf Session("Product") = "3" Then%>
                    <!--#include file="quote-engine/cover-extended.html" -->
                    <% End If%>
                    <% Else%>
                    <% If Session("Product") = "1" Then%>
                    <!--#include file="quote-engine/cover-senior-single.html" -->
                    <% ElseIf Session("Product") = "2" Then%>
                    <!--#include file="quote-engine/cover-senior-annual.html" -->
                    <% ElseIf Session("Product") = "3" Then%>
                    <!--#include file="quote-engine/cover-senior-extended.html" -->
                    <% End If%>
                    <% End If%>

This is dreaded spaghetti code. How do I tackle this in ASP.net.?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question