Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Where to put Sub functions?
Message
From
23/10/2003 17:20:25
 
 
To
22/10/2003 18:06:55
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00841315
Message ID:
00841852
Views:
17
>I'm a C#'er so not 100% sure of the VB syntax. But, the fact of the method being static isn't what makes it callable from both pages, I guess I kinda misstated that. Making it static allows you to call it without instanciating the class. So, in your code you can just do...
>
>MyResult = WebCommon.MyStaticMethod(Whatever)
>
>without having to createobj, or whatever you do to instanciate in VB.Net.
>
>If the webcommon class is in the same project and the same namespace as your aspx pages it should be callable. If you want to put your webcommon in another project you would have to add a reference to that project from your webpage's project to use it.

I created a class named Function.vb. It is in the same project. I put the class in it. It's like this:
Public Class _Function


   ' Add a speaker
   ' expN1 Speaker ID
   ' expL1 If the speaker picture is available
   ' expC1 Speaker name
   ' expM1 Speaker bio
   Private Function AddSpeaker(ByVal tnSpeakerID, ByVal tlPicture, ByVal tcName, ByVal tmBio)
      Dim lcHtml As String
      Dim lcUniversalThread As String

      lcHtml = ""

      ' Universal Thread url
      lcUniversalThread = "http://www.levelextreme.com/"

      If tnSpeakerID > 0 Then
         lcHtml = lcHtml + "<TABLE CELLSPACING=0 CELLPADDING=0>"
         lcHtml = lcHtml + "<TR VALIGN=TOP>"
         lcHtml = lcHtml + "<TD ALIGN=CENTER WIDTH=90>"
         If tlPicture Then
            lcHtml = lcHtml + "<IMG SRC=" + lcUniversalThread + _
             "Photo/" + tnSpeakerID.ToString().PadLeft(6, "0") + ".jpg>"
         Else
            lcHtml = lcHtml + "<IMG SRC=" + lcUniversalThread + "Photo/PictureNotAvailable.jpg>"
         End If
         lcHtml = lcHtml + "<TD WIDTH=4>"
         lcHtml = lcHtml + "<TD>"
         lcHtml = lcHtml + tmBio
         lcHtml = lcHtml + "</TABLE>"
      End If
      lcHtml = lcHtml + "<P>"
      Return lcHtml
   End Function


End Class
In the ASPX files, I remove the Sub function AddSpeaker(). Now, wherever AddSpeaker() is present, I see that we have a problem. So, I put the line like this:
            ' Speaker 1
            lcHtml = lcHtml + Function.AddSpeaker(lnSpeaker1, _
             loData.Tables("Temp").Rows(lnCompteur)("SpeakerPicture1"), _
             loData.Tables("Temp").Rows(lnCompteur)("Speaker1"), _
             loData.Tables("Temp").Rows(lnCompteur)("SpeakerBio1"))
It doesn't work as we have an unknown reference.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform