473,785 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Shared functions vs Non-Shared Functions

I am setting up some of my functions in a class called MyFunctions.

I am not clear as to the best time to set a function as Shared and when not
to. For example, I have the following bit manipulation routines in my
Class:

*************** *************** *************** *************** *************** ****
imports System

NameSpace MyFunctions

Public Class BitHandling

'*----------------------------------------------------------*
'* Name : BitSet *
'*----------------------------------------------------------*
'* Purpose : Sets a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitSet(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H80000000 Or Number
Else
Number = (2 ^ Bit) Or Number
End If
BitSet = Number
End Function

'*----------------------------------------------------------*
'* Name : BitClear *
'*----------------------------------------------------------*
'* Purpose : Clears a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitClear(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H7FFFFFFF And Number
Else
Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
End If

BitClear = Number
End Function

'*----------------------------------------------------------*
'* Name : BitIsSet *
'*----------------------------------------------------------*
'* Purpose : Test if bit 0 to bit 31 is set *
'*----------------------------------------------------------*
Public Shared Function BitIsSet(ByVal Number As Integer, _
ByVal Bit As Integer) As Boolean
BitIsSet = False

If Bit = 31 Then
If Number And &H80000000 Then BitIsSet = True
Else
If Number And (2 ^ Bit) Then BitIsSet = True
End If
End Function

End Class

End Namespace

*************** *************** *************** *************** *************** *****

Now I have these set up as shared so I don't have to create an instance of
the class:

temp = BitHandling.Bit Set(temp,3)

vs.

dim MyBits as new BitHandling
temp = MyBits.BitSet(t emp,3)

I am also setting up my function to send out various emails which entails
reading an Sql Record and reading a text file from disk, as well as sending
the email:

SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)

What would tell me that I need to make this a non-shared function vs a
shared one?

Thanks,

Tom
Nov 19 '05 #1
11 3362
Tom:
Is the function manipulating instance data? Looking at your functions, they
look like they need to be shared.

Think of it this way.

You have a class called Car, which has a property named AirbagDeployed as
boolean

if you have a function named DeployAirbag() it would need to be an
instance (non-shared) method. Why? Because you would have create a new car
instance and would want to deploy that particular car's airbag. in other
words, instnace methods behave against a particular instance. Your
BitHandling class looks like a helper function for dealing with bit
information. You wouldn't create separate instance of them as you don't
need to represent different bithandling (as you would differnent
cars)...ergo your function don't behave against instances.

A case where you might have instances is if your BitHandling was
culture-specific. In which case you might have different bithandling
instances per culture. In this case you'd need to create a new BitHandling
class (specifying the culture) and then your functions would behave against
that particular instance. (As an aside, an alternative would be to pass the
culture information to each shared function so you wouldn't need to create
culture-specific instances which works fine for a single parameter, but
becomes messy when you're talking about more..)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uB******** ******@tk2msftn gp13.phx.gbl...
I am setting up some of my functions in a class called MyFunctions.

I am not clear as to the best time to set a function as Shared and when
not to. For example, I have the following bit manipulation routines in my
Class:

*************** *************** *************** *************** *************** ****
imports System

NameSpace MyFunctions

Public Class BitHandling

'*----------------------------------------------------------*
'* Name : BitSet *
'*----------------------------------------------------------*
'* Purpose : Sets a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitSet(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H80000000 Or Number
Else
Number = (2 ^ Bit) Or Number
End If
BitSet = Number
End Function

'*----------------------------------------------------------*
'* Name : BitClear *
'*----------------------------------------------------------*
'* Purpose : Clears a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitClear(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H7FFFFFFF And Number
Else
Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
End If

BitClear = Number
End Function

'*----------------------------------------------------------*
'* Name : BitIsSet *
'*----------------------------------------------------------*
'* Purpose : Test if bit 0 to bit 31 is set *
'*----------------------------------------------------------*
Public Shared Function BitIsSet(ByVal Number As Integer, _
ByVal Bit As Integer) As Boolean
BitIsSet = False

If Bit = 31 Then
If Number And &H80000000 Then BitIsSet = True
Else
If Number And (2 ^ Bit) Then BitIsSet = True
End If
End Function

End Class

End Namespace

*************** *************** *************** *************** *************** *****

Now I have these set up as shared so I don't have to create an instance of
the class:

temp = BitHandling.Bit Set(temp,3)

vs.

dim MyBits as new BitHandling
temp = MyBits.BitSet(t emp,3)

I am also setting up my function to send out various emails which entails
reading an Sql Record and reading a text file from disk, as well as
sending the email:

SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)

What would tell me that I need to make this a non-shared function vs a
shared one?

Thanks,

Tom

Nov 19 '05 #2
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e5******** ******@TK2MSFTN GP12.phx.gbl...
Tom:
Is the function manipulating instance data? Looking at your functions,
they look like they need to be shared.

Think of it this way.

You have a class called Car, which has a property named AirbagDeployed as
boolean

if you have a function named DeployAirbag() it would need to be an
instance (non-shared) method. Why? Because you would have create a new
car instance and would want to deploy that particular car's airbag. in
other words, instnace methods behave against a particular instance. Your
BitHandling class looks like a helper function for dealing with bit
information. You wouldn't create separate instance of them as you don't
need to represent different bithandling (as you would differnent
cars)...ergo your function don't behave against instances.

A case where you might have instances is if your BitHandling was
culture-specific. In which case you might have different bithandling
instances per culture. In this case you'd need to create a new
BitHandling class (specifying the culture) and then your functions would
behave against that particular instance. (As an aside, an alternative
would be to pass the culture information to each shared function so you
wouldn't need to create culture-specific instances which works fine for a
single parameter, but becomes messy when you're talking about more..)
That's what gets confusing. Trying to figure out the instances bit (no pun
intended) and if it is needed. Here is the other function that I am
creating to put in my MyFunctions Namespace. I would give is a class of
email, I suppose.

This is just my prototype email program that I am putting together to make a
more generalized function from.

It, in essence:
gets the connection to Sql
gets the email record to get the subject and from/to addresses
reads a text file to put into the body of the message
adds a few things to the email
sends the email

I would probably change the function to something like:

public shared sendEmail(filen ame as string, subject as string)

*************** *************** *************** *************** *************** ************
sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_solutions")
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from emailResponse
where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("\new_acco unt_automail.ht m")) then
objStreamReader = File.OpenText(M apPath("\new_ac count_automail. htm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub
*************** *************** *************** *************** *************** **

Would this work as a shared function, or would I need to make this an
instance?

Thanks,

Tom
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uB******** ******@tk2msftn gp13.phx.gbl...
I am setting up some of my functions in a class called MyFunctions.

I am not clear as to the best time to set a function as Shared and when
not to. For example, I have the following bit manipulation routines in
my Class:

*************** *************** *************** *************** *************** ****
imports System

NameSpace MyFunctions

Public Class BitHandling

'*----------------------------------------------------------*
'* Name : BitSet *
'*----------------------------------------------------------*
'* Purpose : Sets a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitSet(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H80000000 Or Number
Else
Number = (2 ^ Bit) Or Number
End If
BitSet = Number
End Function

'*----------------------------------------------------------*
'* Name : BitClear *
'*----------------------------------------------------------*
'* Purpose : Clears a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitClear(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H7FFFFFFF And Number
Else
Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
End If

BitClear = Number
End Function

'*----------------------------------------------------------*
'* Name : BitIsSet *
'*----------------------------------------------------------*
'* Purpose : Test if bit 0 to bit 31 is set *
'*----------------------------------------------------------*
Public Shared Function BitIsSet(ByVal Number As Integer, _
ByVal Bit As Integer) As Boolean
BitIsSet = False

If Bit = 31 Then
If Number And &H80000000 Then BitIsSet = True
Else
If Number And (2 ^ Bit) Then BitIsSet = True
End If
End Function

End Class

End Namespace

*************** *************** *************** *************** *************** *****

Now I have these set up as shared so I don't have to create an instance
of the class:

temp = BitHandling.Bit Set(temp,3)

vs.

dim MyBits as new BitHandling
temp = MyBits.BitSet(t emp,3)

I am also setting up my function to send out various emails which entails
reading an Sql Record and reading a text file from disk, as well as
sending the email:

SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)

What would tell me that I need to make this a non-shared function vs a
shared one?

Thanks,

Tom


Nov 19 '05 #3
You would create an instance class with instance members if you wanted to
create an Email object, set it's properties and have a Send() method, ala:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
you would use a shared member if you wanted to pass everything in as
parameters

EmailHelp.Send( "some subject", "xxx")

I personally prefer the syntax of the 2nd example...but if you wanted to
keep a bunch of different emails, say you wanted to cache them or move them
around between your layers, it'd be necessary to have distinct instances.

Trust your gut feeling.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e5******** ******@TK2MSFTN GP12.phx.gbl...
Tom:
Is the function manipulating instance data? Looking at your functions,
they look like they need to be shared.

Think of it this way.

You have a class called Car, which has a property named AirbagDeployed as
boolean

if you have a function named DeployAirbag() it would need to be an
instance (non-shared) method. Why? Because you would have create a new
car instance and would want to deploy that particular car's airbag. in
other words, instnace methods behave against a particular instance. Your
BitHandling class looks like a helper function for dealing with bit
information. You wouldn't create separate instance of them as you don't
need to represent different bithandling (as you would differnent
cars)...ergo your function don't behave against instances.

A case where you might have instances is if your BitHandling was
culture-specific. In which case you might have different bithandling
instances per culture. In this case you'd need to create a new
BitHandling class (specifying the culture) and then your functions would
behave against that particular instance. (As an aside, an alternative
would be to pass the culture information to each shared function so you
wouldn't need to create culture-specific instances which works fine for a
single parameter, but becomes messy when you're talking about more..)


That's what gets confusing. Trying to figure out the instances bit (no
pun intended) and if it is needed. Here is the other function that I am
creating to put in my MyFunctions Namespace. I would give is a class of
email, I suppose.

This is just my prototype email program that I am putting together to make
a more generalized function from.

It, in essence:
gets the connection to Sql
gets the email record to get the subject and from/to addresses
reads a text file to put into the body of the message
adds a few things to the email
sends the email

I would probably change the function to something like:

public shared sendEmail(filen ame as string, subject as string)

*************** *************** *************** *************** *************** ************
sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_solutions")
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("\new_acco unt_automail.ht m")) then
objStreamReader = File.OpenText(M apPath("\new_ac count_automail. htm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub
*************** *************** *************** *************** *************** **

Would this work as a shared function, or would I need to make this an
instance?

Thanks,

Tom

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uB******** ******@tk2msftn gp13.phx.gbl...
I am setting up some of my functions in a class called MyFunctions.

I am not clear as to the best time to set a function as Shared and when
not to. For example, I have the following bit manipulation routines in
my Class:

*************** *************** *************** *************** *************** ****
imports System

NameSpace MyFunctions

Public Class BitHandling

'*----------------------------------------------------------*
'* Name : BitSet *
'*----------------------------------------------------------*
'* Purpose : Sets a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitSet(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H80000000 Or Number
Else
Number = (2 ^ Bit) Or Number
End If
BitSet = Number
End Function

'*----------------------------------------------------------*
'* Name : BitClear *
'*----------------------------------------------------------*
'* Purpose : Clears a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitClear(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H7FFFFFFF And Number
Else
Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
End If

BitClear = Number
End Function

'*----------------------------------------------------------*
'* Name : BitIsSet *
'*----------------------------------------------------------*
'* Purpose : Test if bit 0 to bit 31 is set *
'*----------------------------------------------------------*
Public Shared Function BitIsSet(ByVal Number As Integer, _
ByVal Bit As Integer) As Boolean
BitIsSet = False

If Bit = 31 Then
If Number And &H80000000 Then BitIsSet = True
Else
If Number And (2 ^ Bit) Then BitIsSet = True
End If
End Function

End Class

End Namespace

*************** *************** *************** *************** *************** *****

Now I have these set up as shared so I don't have to create an instance
of the class:

temp = BitHandling.Bit Set(temp,3)

vs.

dim MyBits as new BitHandling
temp = MyBits.BitSet(t emp,3)

I am also setting up my function to send out various emails which
entails reading an Sql Record and reading a text file from disk, as well
as sending the email:

SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)

What would tell me that I need to make this a non-shared function vs a
shared one?

Thanks,

Tom



Nov 19 '05 #4
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:O%******** ********@tk2msf tngp13.phx.gbl. ..
You would create an instance class with instance members if you wanted to
create an Email object, set it's properties and have a Send() method, ala:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
you would use a shared member if you wanted to pass everything in as
parameters

EmailHelp.Send( "some subject", "xxx")

I personally prefer the syntax of the 2nd example...but if you wanted to
keep a bunch of different emails, say you wanted to cache them or move
them around between your layers, it'd be necessary to have distinct
instances.
I prefer the 2nd example also.

But when you talk about caching or moving them, are you saying that you want
an instance so you could do something like:

sub somefunction (myEmail as Email)
....
myEmail.somemet hod()

end sub

Then using your 1st example:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
....
somefunction(em ail) ' calling the above function
BTW, I took my email function and tried to compile it using:

C:\Inetpub\wwwr oot\staffingwor kshop>vbc /t:library email.vb
/r:system.web.dl l /r:system.data.d ll /r:system.dll
/r:Microsoft.Vis ualBasic.dll

and I get the following errors:

C:\Inetpub\wwwr oot\staffingwor kshop\email.vb( 49) : error BC30469: Reference
to a non-shared member requires an object reference.

I am getting this for request.path and for MapPath.

My file looks like:
*************** *************** *************** *************** *************** *******
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.Sess ionState
Imports System.Web.Mail
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports Microsoft.Visua lBasic

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_ftsolutions" )
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from emailResponse
where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("..\..\aut omail\new_accou nt_automail.htm ")) then
objStreamReader =
File.OpenText(M apPath("..\..\a utomail\new_acc ount_automail.h tm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub

End Class

End Namespace
*************** *************** *************** *************** *************** *********

This happens whether emailSend is Shared or not.

Thanks,

Tom

Trust your gut feeling.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e5******** ******@TK2MSFTN GP12.phx.gbl...
Tom:
Is the function manipulating instance data? Looking at your functions,
they look like they need to be shared.

Think of it this way.

You have a class called Car, which has a property named AirbagDeployed
as boolean

if you have a function named DeployAirbag() it would need to be an
instance (non-shared) method. Why? Because you would have create a new
car instance and would want to deploy that particular car's airbag. in
other words, instnace methods behave against a particular instance.
Your BitHandling class looks like a helper function for dealing with bit
information. You wouldn't create separate instance of them as you don't
need to represent different bithandling (as you would differnent
cars)...ergo your function don't behave against instances.

A case where you might have instances is if your BitHandling was
culture-specific. In which case you might have different bithandling
instances per culture. In this case you'd need to create a new
BitHandling class (specifying the culture) and then your functions would
behave against that particular instance. (As an aside, an alternative
would be to pass the culture information to each shared function so you
wouldn't need to create culture-specific instances which works fine for
a single parameter, but becomes messy when you're talking about more..)


That's what gets confusing. Trying to figure out the instances bit (no
pun intended) and if it is needed. Here is the other function that I am
creating to put in my MyFunctions Namespace. I would give is a class of
email, I suppose.

This is just my prototype email program that I am putting together to
make a more generalized function from.

It, in essence:
gets the connection to Sql
gets the email record to get the subject and from/to addresses
reads a text file to put into the body of the message
adds a few things to the email
sends the email

I would probably change the function to something like:

public shared sendEmail(filen ame as string, subject as string)

*************** *************** *************** *************** *************** ************
sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_solutions")
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("\new_acco unt_automail.ht m")) then
objStreamReader = File.OpenText(M apPath("\new_ac count_automail. htm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub
*************** *************** *************** *************** *************** **

Would this work as a shared function, or would I need to make this an
instance?

Thanks,

Tom

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uB******** ******@tk2msftn gp13.phx.gbl...
I am setting up some of my functions in a class called MyFunctions.

I am not clear as to the best time to set a function as Shared and when
not to. For example, I have the following bit manipulation routines in
my Class:

*************** *************** *************** *************** *************** ****
imports System

NameSpace MyFunctions

Public Class BitHandling

'*----------------------------------------------------------*
'* Name : BitSet *
'*----------------------------------------------------------*
'* Purpose : Sets a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitSet(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H80000000 Or Number
Else
Number = (2 ^ Bit) Or Number
End If
BitSet = Number
End Function

'*----------------------------------------------------------*
'* Name : BitClear *
'*----------------------------------------------------------*
'* Purpose : Clears a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitClear(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H7FFFFFFF And Number
Else
Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
End If

BitClear = Number
End Function

'*----------------------------------------------------------*
'* Name : BitIsSet *
'*----------------------------------------------------------*
'* Purpose : Test if bit 0 to bit 31 is set *
'*----------------------------------------------------------*
Public Shared Function BitIsSet(ByVal Number As Integer, _
ByVal Bit As Integer) As Boolean
BitIsSet = False

If Bit = 31 Then
If Number And &H80000000 Then BitIsSet = True
Else
If Number And (2 ^ Bit) Then BitIsSet = True
End If
End Function

End Class

End Namespace

*************** *************** *************** *************** *************** *****

Now I have these set up as shared so I don't have to create an instance
of the class:

temp = BitHandling.Bit Set(temp,3)

vs.

dim MyBits as new BitHandling
temp = MyBits.BitSet(t emp,3)

I am also setting up my function to send out various emails which
entails reading an Sql Record and reading a text file from disk, as
well as sending the email:

SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)

What would tell me that I need to make this a non-shared function vs a
shared one?

Thanks,

Tom



Nov 19 '05 #5

"tshad" <ts**********@f tsolutions.com> wrote in message
news:u0******** ********@TK2MSF TNGP15.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:O%******** ********@tk2msf tngp13.phx.gbl. ..
You would create an instance class with instance members if you wanted to
create an Email object, set it's properties and have a Send() method,
ala:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
you would use a shared member if you wanted to pass everything in as
parameters

EmailHelp.Send( "some subject", "xxx")

I personally prefer the syntax of the 2nd example...but if you wanted to
keep a bunch of different emails, say you wanted to cache them or move
them around between your layers, it'd be necessary to have distinct
instances.
I prefer the 2nd example also.

But when you talk about caching or moving them, are you saying that you
want an instance so you could do something like:

sub somefunction (myEmail as Email)
...
myEmail.somemet hod()

end sub

Then using your 1st example:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
...
somefunction(em ail) ' calling the above function
BTW, I took my email function and tried to compile it using:

C:\Inetpub\wwwr oot\staffingwor kshop>vbc /t:library email.vb
/r:system.web.dl l /r:system.data.d ll /r:system.dll
/r:Microsoft.Vis ualBasic.dll

and I get the following errors:

C:\Inetpub\wwwr oot\staffingwor kshop\email.vb( 49) : error BC30469:
Reference to a non-shared member requires an object reference.

I am getting this for request.path and for MapPath.

My file looks like:
*************** *************** *************** *************** *************** *******
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.Sess ionState
Imports System.Web.Mail
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports Microsoft.Visua lBasic

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_ftsolutions" )
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("..\..\aut omail\new_accou nt_automail.htm ")) then
objStreamReader =
File.OpenText(M apPath("..\..\a utomail\new_acc ount_automail.h tm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub

End Class

End Namespace
*************** *************** *************** *************** *************** *********

This happens whether emailSend is Shared or not.


I finally got it to work, but not as it should.

To get the MapPath to work I stripped out all but the essential code to
figure it out and plus something I saw on one of the newsgroups.

*************** *************** *************** *************** *************** *************
imports System
imports System.IO
imports System.Web.Http Context

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
If
File.exists(Cur rent.Server.Map Path("..\..\aut omail\new_accou nt_automail.htm "))
then
end if
end sub

End Class

End Namespace
*************** *************** *************** *************** ********

I needed the following:

imports System.Web.Http Context

And the MapPath changed to:

If
File.exists(Cur rent.Server.Map Path("..\..\aut omail\new_accou nt_automail.htm "))
then

Not sure how to get rid of Current and Server (I don't need this in my
normal aspx page).

I still haven't figured out the "request" error yet. But this is all hit or
miss.

The MSDN is no help at all. I found this by accident. Isn't there a place
to find this? I should have to play games to get this to work.

MSDN says MapPath is part of the Server object, but nowhere (that I can
find) does it show how to define it in your code.

Tom
Thanks,

Tom

Trust your gut feeling.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e5******** ******@TK2MSFTN GP12.phx.gbl...
Tom:
Is the function manipulating instance data? Looking at your functions,
they look like they need to be shared.

Think of it this way.

You have a class called Car, which has a property named AirbagDeployed
as boolean

if you have a function named DeployAirbag() it would need to be an
instance (non-shared) method. Why? Because you would have create a
new car instance and would want to deploy that particular car's airbag.
in other words, instnace methods behave against a particular instance.
Your BitHandling class looks like a helper function for dealing with
bit information. You wouldn't create separate instance of them as you
don't need to represent different bithandling (as you would differnent
cars)...ergo your function don't behave against instances.

A case where you might have instances is if your BitHandling was
culture-specific. In which case you might have different bithandling
instances per culture. In this case you'd need to create a new
BitHandling class (specifying the culture) and then your functions
would behave against that particular instance. (As an aside, an
alternative would be to pass the culture information to each shared
function so you wouldn't need to create culture-specific instances
which works fine for a single parameter, but becomes messy when you're
talking about more..)

That's what gets confusing. Trying to figure out the instances bit (no
pun intended) and if it is needed. Here is the other function that I am
creating to put in my MyFunctions Namespace. I would give is a class of
email, I suppose.

This is just my prototype email program that I am putting together to
make a more generalized function from.

It, in essence:
gets the connection to Sql
gets the email record to get the subject and from/to addresses
reads a text file to put into the body of the message
adds a few things to the email
sends the email

I would probably change the function to something like:

public shared sendEmail(filen ame as string, subject as string)

*************** *************** *************** *************** *************** ************
sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_solutions")
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("\new_acco unt_automail.ht m")) then
objStreamReader = File.OpenText(M apPath("\new_ac count_automail. htm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub
*************** *************** *************** *************** *************** **

Would this work as a shared function, or would I need to make this an
instance?

Thanks,

Tom

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uB******** ******@tk2msftn gp13.phx.gbl...
>I am setting up some of my functions in a class called MyFunctions.
>
> I am not clear as to the best time to set a function as Shared and
> when not to. For example, I have the following bit manipulation
> routines in my Class:
>
> *************** *************** *************** *************** *************** ****
> imports System
>
> NameSpace MyFunctions
>
> Public Class BitHandling
>
> '*----------------------------------------------------------*
> '* Name : BitSet *
> '*----------------------------------------------------------*
> '* Purpose : Sets a given Bit in Number *
> '*----------------------------------------------------------*
> Public Shared Function BitSet(Number As Integer, _
> ByVal Bit As Integer) As Long
> If Bit = 31 Then
> Number = &H80000000 Or Number
> Else
> Number = (2 ^ Bit) Or Number
> End If
> BitSet = Number
> End Function
>
> '*----------------------------------------------------------*
> '* Name : BitClear *
> '*----------------------------------------------------------*
> '* Purpose : Clears a given Bit in Number *
> '*----------------------------------------------------------*
> Public Shared Function BitClear(Number As Integer, _
> ByVal Bit As Integer) As Long
> If Bit = 31 Then
> Number = &H7FFFFFFF And Number
> Else
> Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
> End If
>
> BitClear = Number
> End Function
>
> '*----------------------------------------------------------*
> '* Name : BitIsSet *
> '*----------------------------------------------------------*
> '* Purpose : Test if bit 0 to bit 31 is set *
> '*----------------------------------------------------------*
> Public Shared Function BitIsSet(ByVal Number As Integer, _
> ByVal Bit As Integer) As Boolean
> BitIsSet = False
>
> If Bit = 31 Then
> If Number And &H80000000 Then BitIsSet = True
> Else
> If Number And (2 ^ Bit) Then BitIsSet = True
> End If
> End Function
>
> End Class
>
> End Namespace
>
> *************** *************** *************** *************** *************** *****
>
> Now I have these set up as shared so I don't have to create an
> instance of the class:
>
> temp = BitHandling.Bit Set(temp,3)
>
> vs.
>
> dim MyBits as new BitHandling
> temp = MyBits.BitSet(t emp,3)
>
> I am also setting up my function to send out various emails which
> entails reading an Sql Record and reading a text file from disk, as
> well as sending the email:
>
> SmtpMail.SmtpSe rver = mailServer
> smtpMail.Send(m essage)
>
> What would tell me that I need to make this a non-shared function vs a
> shared one?
>
> Thanks,
>
> Tom
>



Nov 19 '05 #6
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OH******** ******@tk2msftn gp13.phx.gbl...

"tshad" <ts**********@f tsolutions.com> wrote in message
news:u0******** ********@TK2MSF TNGP15.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:O%******** ********@tk2msf tngp13.phx.gbl. ..
You would create an instance class with instance members if you wanted
to create an Email object, set it's properties and have a Send() method,
ala:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
you would use a shared member if you wanted to pass everything in as
parameters

EmailHelp.Send( "some subject", "xxx")

I personally prefer the syntax of the 2nd example...but if you wanted to
keep a bunch of different emails, say you wanted to cache them or move
them around between your layers, it'd be necessary to have distinct
instances.
I prefer the 2nd example also.

But when you talk about caching or moving them, are you saying that you
want an instance so you could do something like:

sub somefunction (myEmail as Email)
...
myEmail.somemet hod()

end sub

Then using your 1st example:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
...
somefunction(em ail) ' calling the above function
BTW, I took my email function and tried to compile it using:

C:\Inetpub\wwwr oot\staffingwor kshop>vbc /t:library email.vb
/r:system.web.dl l /r:system.data.d ll /r:system.dll
/r:Microsoft.Vis ualBasic.dll

and I get the following errors:

C:\Inetpub\wwwr oot\staffingwor kshop\email.vb( 49) : error BC30469:
Reference to a non-shared member requires an object reference.

I am getting this for request.path and for MapPath.

My file looks like:
*************** *************** *************** *************** *************** *******
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.Sess ionState
Imports System.Web.Mail
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports Microsoft.Visua lBasic

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_ftsolutions" )
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("..\..\aut omail\new_accou nt_automail.htm ")) then
objStreamReader =
File.OpenText(M apPath("..\..\a utomail\new_acc ount_automail.h tm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub

End Class

End Namespace
*************** *************** *************** *************** *************** *********

This happens whether emailSend is Shared or not.


I finally got it to work, but not as it should.

To get the MapPath to work I stripped out all but the essential code to
figure it out and plus something I saw on one of the newsgroups.

*************** *************** *************** *************** *************** *************
imports System
imports System.IO
imports System.Web.Http Context

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
If
File.exists(Cur rent.Server.Map Path("..\..\aut omail\new_accou nt_automail.htm "))
then
end if
end sub

End Class

End Namespace
*************** *************** *************** *************** ********

I needed the following:

imports System.Web.Http Context

And the MapPath changed to:

If
File.exists(Cur rent.Server.Map Path("..\..\aut omail\new_accou nt_automail.htm "))
then

Not sure how to get rid of Current and Server (I don't need this in my
normal aspx page).

I still haven't figured out the "request" error yet. But this is all hit
or miss.


It turns out the same import is used and you have to do code as:

Current.Server. Request.Path

Again, makes no sense and was found by trial and error. If you do just the
request.Path (where request is one of the members) you get the error.

Tom

The MSDN is no help at all. I found this by accident. Isn't there a
place to find this? I should have to play games to get this to work.

MSDN says MapPath is part of the Server object, but nowhere (that I can
find) does it show how to define it in your code.

Tom

Thanks,

Tom

Trust your gut feeling.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e5******** ******@TK2MSFTN GP12.phx.gbl...
> Tom:
> Is the function manipulating instance data? Looking at your
> functions, they look like they need to be shared.
>
> Think of it this way.
>
> You have a class called Car, which has a property named AirbagDeployed
> as boolean
>
> if you have a function named DeployAirbag() it would need to be an
> instance (non-shared) method. Why? Because you would have create a
> new car instance and would want to deploy that particular car's
> airbag. in other words, instnace methods behave against a particular
> instance. Your BitHandling class looks like a helper function for
> dealing with bit information. You wouldn't create separate instance
> of them as you don't need to represent different bithandling (as you
> would differnent cars)...ergo your function don't behave against
> instances.
>
> A case where you might have instances is if your BitHandling was
> culture-specific. In which case you might have different bithandling
> instances per culture. In this case you'd need to create a new
> BitHandling class (specifying the culture) and then your functions
> would behave against that particular instance. (As an aside, an
> alternative would be to pass the culture information to each shared
> function so you wouldn't need to create culture-specific instances
> which works fine for a single parameter, but becomes messy when you're
> talking about more..)

That's what gets confusing. Trying to figure out the instances bit (no
pun intended) and if it is needed. Here is the other function that I
am creating to put in my MyFunctions Namespace. I would give is a
class of email, I suppose.

This is just my prototype email program that I am putting together to
make a more generalized function from.

It, in essence:
gets the connection to Sql
gets the email record to get the subject and from/to addresses
reads a text file to put into the body of the message
adds a few things to the email
sends the email

I would probably change the function to something like:

public shared sendEmail(filen ame as string, subject as string)

*************** *************** *************** *************** *************** ************
sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_solutions")
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("\new_acco unt_automail.ht m")) then
objStreamReader = File.OpenText(M apPath("\new_ac count_automail. htm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub
*************** *************** *************** *************** *************** **

Would this work as a shared function, or would I need to make this an
instance?

Thanks,

Tom
>
> Karl
>
>
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "tshad" <ts**********@f tsolutions.com> wrote in message
> news:uB******** ******@tk2msftn gp13.phx.gbl...
>>I am setting up some of my functions in a class called MyFunctions.
>>
>> I am not clear as to the best time to set a function as Shared and
>> when not to. For example, I have the following bit manipulation
>> routines in my Class:
>>
>> *************** *************** *************** *************** *************** ****
>> imports System
>>
>> NameSpace MyFunctions
>>
>> Public Class BitHandling
>>
>> '*----------------------------------------------------------*
>> '* Name : BitSet *
>> '*----------------------------------------------------------*
>> '* Purpose : Sets a given Bit in Number *
>> '*----------------------------------------------------------*
>> Public Shared Function BitSet(Number As Integer, _
>> ByVal Bit As Integer) As Long
>> If Bit = 31 Then
>> Number = &H80000000 Or Number
>> Else
>> Number = (2 ^ Bit) Or Number
>> End If
>> BitSet = Number
>> End Function
>>
>> '*----------------------------------------------------------*
>> '* Name : BitClear *
>> '*----------------------------------------------------------*
>> '* Purpose : Clears a given Bit in Number *
>> '*----------------------------------------------------------*
>> Public Shared Function BitClear(Number As Integer, _
>> ByVal Bit As Integer) As Long
>> If Bit = 31 Then
>> Number = &H7FFFFFFF And Number
>> Else
>> Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
>> End If
>>
>> BitClear = Number
>> End Function
>>
>> '*----------------------------------------------------------*
>> '* Name : BitIsSet *
>> '*----------------------------------------------------------*
>> '* Purpose : Test if bit 0 to bit 31 is set *
>> '*----------------------------------------------------------*
>> Public Shared Function BitIsSet(ByVal Number As Integer, _
>> ByVal Bit As Integer) As Boolean
>> BitIsSet = False
>>
>> If Bit = 31 Then
>> If Number And &H80000000 Then BitIsSet = True
>> Else
>> If Number And (2 ^ Bit) Then BitIsSet = True
>> End If
>> End Function
>>
>> End Class
>>
>> End Namespace
>>
>> *************** *************** *************** *************** *************** *****
>>
>> Now I have these set up as shared so I don't have to create an
>> instance of the class:
>>
>> temp = BitHandling.Bit Set(temp,3)
>>
>> vs.
>>
>> dim MyBits as new BitHandling
>> temp = MyBits.BitSet(t emp,3)
>>
>> I am also setting up my function to send out various emails which
>> entails reading an Sql Record and reading a text file from disk, as
>> well as sending the email:
>>
>> SmtpMail.SmtpSe rver = mailServer
>> smtpMail.Send(m essage)
>>
>> What would tell me that I need to make this a non-shared function vs
>> a shared one?
>>
>> Thanks,
>>
>> Tom
>>
>
>



Nov 19 '05 #7
You've lost me a bit with the mass amounts of code.

That's exactly what I'm saying about moving it around (as a parameter).

As for your error. Objects which you typically program with in your page
and user controls such as Request, Response, Server, ... are there because
they are exposed as part of the System.Web.UI.C ontrol class your page/user
control inherits from (couple levels deep).

Your email class inherits directly from Object, so Request, Response, Server
are meaningless. To get references to these objects within your class
functions, you need to use System.Web.Http Context.Current which returns the
current context (ie the web request) which exposes the Response, Request,
Server, ...

so you would do:

dim context as HttpContext = HttpContext.Cur rent
if context is nothing then 'possible if someone is trying to use this
class outside of a web-scope
throw new InvalidOperatio nException("MyF unc needs to be called from web
request") 'maybe you can do something other than throw an exception?
end if
'now you have access to your request and response objects, here's an example
dim request as HttpRequest = context.Request
dim someValue as string =Request.QueryS tring("blah")
hope that helps..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:u0******** ********@TK2MSF TNGP15.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:O%******** ********@tk2msf tngp13.phx.gbl. ..
You would create an instance class with instance members if you wanted to
create an Email object, set it's properties and have a Send() method,
ala:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
you would use a shared member if you wanted to pass everything in as
parameters

EmailHelp.Send( "some subject", "xxx")

I personally prefer the syntax of the 2nd example...but if you wanted to
keep a bunch of different emails, say you wanted to cache them or move
them around between your layers, it'd be necessary to have distinct
instances.


I prefer the 2nd example also.

But when you talk about caching or moving them, are you saying that you
want an instance so you could do something like:

sub somefunction (myEmail as Email)
...
myEmail.somemet hod()

end sub

Then using your 1st example:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
...
somefunction(em ail) ' calling the above function
BTW, I took my email function and tried to compile it using:

C:\Inetpub\wwwr oot\staffingwor kshop>vbc /t:library email.vb
/r:system.web.dl l /r:system.data.d ll /r:system.dll
/r:Microsoft.Vis ualBasic.dll

and I get the following errors:

C:\Inetpub\wwwr oot\staffingwor kshop\email.vb( 49) : error BC30469:
Reference to a non-shared member requires an object reference.

I am getting this for request.path and for MapPath.

My file looks like:
*************** *************** *************** *************** *************** *******
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.Sess ionState
Imports System.Web.Mail
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports Microsoft.Visua lBasic

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_ftsolutions" )
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("..\..\aut omail\new_accou nt_automail.htm ")) then
objStreamReader =
File.OpenText(M apPath("..\..\a utomail\new_acc ount_automail.h tm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub

End Class

End Namespace
*************** *************** *************** *************** *************** *********

This happens whether emailSend is Shared or not.

Thanks,

Tom

Trust your gut feeling.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e5******** ******@TK2MSFTN GP12.phx.gbl...
Tom:
Is the function manipulating instance data? Looking at your functions,
they look like they need to be shared.

Think of it this way.

You have a class called Car, which has a property named AirbagDeployed
as boolean

if you have a function named DeployAirbag() it would need to be an
instance (non-shared) method. Why? Because you would have create a
new car instance and would want to deploy that particular car's airbag.
in other words, instnace methods behave against a particular instance.
Your BitHandling class looks like a helper function for dealing with
bit information. You wouldn't create separate instance of them as you
don't need to represent different bithandling (as you would differnent
cars)...ergo your function don't behave against instances.

A case where you might have instances is if your BitHandling was
culture-specific. In which case you might have different bithandling
instances per culture. In this case you'd need to create a new
BitHandling class (specifying the culture) and then your functions
would behave against that particular instance. (As an aside, an
alternative would be to pass the culture information to each shared
function so you wouldn't need to create culture-specific instances
which works fine for a single parameter, but becomes messy when you're
talking about more..)

That's what gets confusing. Trying to figure out the instances bit (no
pun intended) and if it is needed. Here is the other function that I am
creating to put in my MyFunctions Namespace. I would give is a class of
email, I suppose.

This is just my prototype email program that I am putting together to
make a more generalized function from.

It, in essence:
gets the connection to Sql
gets the email record to get the subject and from/to addresses
reads a text file to put into the body of the message
adds a few things to the email
sends the email

I would probably change the function to something like:

public shared sendEmail(filen ame as string, subject as string)

*************** *************** *************** *************** *************** ************
sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_solutions")
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("\new_acco unt_automail.ht m")) then
objStreamReader = File.OpenText(M apPath("\new_ac count_automail. htm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub
*************** *************** *************** *************** *************** **

Would this work as a shared function, or would I need to make this an
instance?

Thanks,

Tom

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uB******** ******@tk2msftn gp13.phx.gbl...
>I am setting up some of my functions in a class called MyFunctions.
>
> I am not clear as to the best time to set a function as Shared and
> when not to. For example, I have the following bit manipulation
> routines in my Class:
>
> *************** *************** *************** *************** *************** ****
> imports System
>
> NameSpace MyFunctions
>
> Public Class BitHandling
>
> '*----------------------------------------------------------*
> '* Name : BitSet *
> '*----------------------------------------------------------*
> '* Purpose : Sets a given Bit in Number *
> '*----------------------------------------------------------*
> Public Shared Function BitSet(Number As Integer, _
> ByVal Bit As Integer) As Long
> If Bit = 31 Then
> Number = &H80000000 Or Number
> Else
> Number = (2 ^ Bit) Or Number
> End If
> BitSet = Number
> End Function
>
> '*----------------------------------------------------------*
> '* Name : BitClear *
> '*----------------------------------------------------------*
> '* Purpose : Clears a given Bit in Number *
> '*----------------------------------------------------------*
> Public Shared Function BitClear(Number As Integer, _
> ByVal Bit As Integer) As Long
> If Bit = 31 Then
> Number = &H7FFFFFFF And Number
> Else
> Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
> End If
>
> BitClear = Number
> End Function
>
> '*----------------------------------------------------------*
> '* Name : BitIsSet *
> '*----------------------------------------------------------*
> '* Purpose : Test if bit 0 to bit 31 is set *
> '*----------------------------------------------------------*
> Public Shared Function BitIsSet(ByVal Number As Integer, _
> ByVal Bit As Integer) As Boolean
> BitIsSet = False
>
> If Bit = 31 Then
> If Number And &H80000000 Then BitIsSet = True
> Else
> If Number And (2 ^ Bit) Then BitIsSet = True
> End If
> End Function
>
> End Class
>
> End Namespace
>
> *************** *************** *************** *************** *************** *****
>
> Now I have these set up as shared so I don't have to create an
> instance of the class:
>
> temp = BitHandling.Bit Set(temp,3)
>
> vs.
>
> dim MyBits as new BitHandling
> temp = MyBits.BitSet(t emp,3)
>
> I am also setting up my function to send out various emails which
> entails reading an Sql Record and reading a text file from disk, as
> well as sending the email:
>
> SmtpMail.SmtpSe rver = mailServer
> smtpMail.Send(m essage)
>
> What would tell me that I need to make this a non-shared function vs a
> shared one?
>
> Thanks,
>
> Tom
>



Nov 19 '05 #8

"tshad" <ts**********@f tsolutions.com> wrote in message
news:uD******** ******@TK2MSFTN GP12.phx.gbl...
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OH******** ******@tk2msftn gp13.phx.gbl...

"tshad" <ts**********@f tsolutions.com> wrote in message
news:u0******** ********@TK2MSF TNGP15.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:O%******** ********@tk2msf tngp13.phx.gbl. ..
You would create an instance class with instance members if you wanted
to create an Email object, set it's properties and have a Send()
method, ala:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
you would use a shared member if you wanted to pass everything in as
parameters

EmailHelp.Send( "some subject", "xxx")

I personally prefer the syntax of the 2nd example...but if you wanted
to keep a bunch of different emails, say you wanted to cache them or
move them around between your layers, it'd be necessary to have
distinct instances.

I prefer the 2nd example also.

But when you talk about caching or moving them, are you saying that you
want an instance so you could do something like:

sub somefunction (myEmail as Email)
...
myEmail.somemet hod()

end sub

Then using your 1st example:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
...
somefunction(em ail) ' calling the above function
BTW, I took my email function and tried to compile it using:

C:\Inetpub\wwwr oot\staffingwor kshop>vbc /t:library email.vb
/r:system.web.dl l /r:system.data.d ll /r:system.dll
/r:Microsoft.Vis ualBasic.dll

and I get the following errors:

C:\Inetpub\wwwr oot\staffingwor kshop\email.vb( 49) : error BC30469:
Reference to a non-shared member requires an object reference.

I am getting this for request.path and for MapPath.

My file looks like:
*************** *************** *************** *************** *************** *******
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.Sess ionState
Imports System.Web.Mail
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports Microsoft.Visua lBasic

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_ftsolutions" )
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("..\..\aut omail\new_accou nt_automail.htm "))
then
objStreamReader =
File.OpenText(M apPath("..\..\a utomail\new_acc ount_automail.h tm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub

End Class

End Namespace
*************** *************** *************** *************** *************** *********

This happens whether emailSend is Shared or not.
I finally got it to work, but not as it should.

To get the MapPath to work I stripped out all but the essential code to
figure it out and plus something I saw on one of the newsgroups.

*************** *************** *************** *************** *************** *************
imports System
imports System.IO
imports System.Web.Http Context

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
If
File.exists(Cur rent.Server.Map Path("..\..\aut omail\new_accou nt_automail.htm "))
then
end if
end sub

End Class

End Namespace
*************** *************** *************** *************** ********

I needed the following:

imports System.Web.Http Context

And the MapPath changed to:

If
File.exists(Cur rent.Server.Map Path("..\..\aut omail\new_accou nt_automail.htm "))
then

Not sure how to get rid of Current and Server (I don't need this in my
normal aspx page).

I still haven't figured out the "request" error yet. But this is all hit
or miss.


It turns out the same import is used and you have to do code as:

Current.Server. Request.Path


Actually, it's "Current.Reques t.Path" - no server.

Tom
Again, makes no sense and was found by trial and error. If you do just
the request.Path (where request is one of the members) you get the error.

Tom

The MSDN is no help at all. I found this by accident. Isn't there a
place to find this? I should have to play games to get this to work.

MSDN says MapPath is part of the Server object, but nowhere (that I can
find) does it show how to define it in your code.

Tom

Thanks,

Tom
Trust your gut feeling.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
> net> wrote in message news:e5******** ******@TK2MSFTN GP12.phx.gbl...
>> Tom:
>> Is the function manipulating instance data? Looking at your
>> functions, they look like they need to be shared.
>>
>> Think of it this way.
>>
>> You have a class called Car, which has a property named
>> AirbagDeployed as boolean
>>
>> if you have a function named DeployAirbag() it would need to be an
>> instance (non-shared) method. Why? Because you would have create a
>> new car instance and would want to deploy that particular car's
>> airbag. in other words, instnace methods behave against a particular
>> instance. Your BitHandling class looks like a helper function for
>> dealing with bit information. You wouldn't create separate instance
>> of them as you don't need to represent different bithandling (as you
>> would differnent cars)...ergo your function don't behave against
>> instances.
>>
>> A case where you might have instances is if your BitHandling was
>> culture-specific. In which case you might have different bithandling
>> instances per culture. In this case you'd need to create a new
>> BitHandling class (specifying the culture) and then your functions
>> would behave against that particular instance. (As an aside, an
>> alternative would be to pass the culture information to each shared
>> function so you wouldn't need to create culture-specific instances
>> which works fine for a single parameter, but becomes messy when
>> you're talking about more..)
>
> That's what gets confusing. Trying to figure out the instances bit
> (no pun intended) and if it is needed. Here is the other function
> that I am creating to put in my MyFunctions Namespace. I would give
> is a class of email, I suppose.
>
> This is just my prototype email program that I am putting together to
> make a more generalized function from.
>
> It, in essence:
> gets the connection to Sql
> gets the email record to get the subject and from/to addresses
> reads a text file to put into the body of the message
> adds a few things to the email
> sends the email
>
> I would probably change the function to something like:
>
> public shared sendEmail(filen ame as string, subject as string)
>
> *************** *************** *************** *************** *************** ************
> sub sendEmail ( )
> dim webMasterEmail As String
> dim emailSubject As String
> Dim mailServer As String
> Dim contactEmail As String
> Dim screenTestSubje ct As String
>
> Dim emailReader As SqlDataReader
>
> Dim ConnectionStrin g as String
> =System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_solutions")
> Dim objConn as New SqlConnection (ConnectionStri ng)
> Dim CommandText as String = "Select
> MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
> emailResponse where ClientID = '1234'"
> Dim objCmd as New SqlCommand(Comm andText,objConn )
>
> objConn.Open()
>
> emailReader = objCmd.ExecuteR eader
>
> if emailReader.Rea d then
> mailServer = emailReader("Ma ilServer")
> webMasterEmail = emailReader("We bMasterEmail")
> contactEmail = emailReader("Co ntactEmail")
> screenTestSubje ct = emailReader("Sc reenTestSubject ")
> end If
>
> objConn.close()
>
> dim URLPath As String = _
> Left(request.pa th, InStrRev(reques t.path, "/") - 1)
>
> Dim objStreamReader as StreamReader
> Dim strInput As String
> Dim strBuffer As String
>
> If File.exists(Map Path("\new_acco unt_automail.ht m")) then
> objStreamReader = File.OpenText(M apPath("\new_ac count_automail. htm"))
> strInput = objStreamReader .ReadLine()
> while strInput <> nothing
> strBuffer = strBuffer & strInput
> strInput = objStreamReader .ReadLine()
> end while
> objStreamReader .Close
> end if
>
> Dim Message As New MailMessage()
> message.To = contactEmail
> message.From = webMasterEmail
> message.Subject = screenTestSubje ct
> message.Body = "This is line 1<br><br>"
> message.Body = message.Body & "This is line 2<br><br>"
> strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
> strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
> message.Body = strInput
> message.BodyFor mat = MailFormat.Html
> SmtpMail.SmtpSe rver = mailServer
> smtpMail.Send(m essage)
> end sub
> *************** *************** *************** *************** *************** **
>
> Would this work as a shared function, or would I need to make this an
> instance?
>
> Thanks,
>
> Tom
>>
>> Karl
>>
>>
>>
>> --
>> MY ASP.Net tutorials
>> http://www.openmymind.net/ - New and Improved (yes, the popup is
>> annoying)
>> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more
>> to
>> come!)
>> "tshad" <ts**********@f tsolutions.com> wrote in message
>> news:uB******** ******@tk2msftn gp13.phx.gbl...
>>>I am setting up some of my functions in a class called MyFunctions.
>>>
>>> I am not clear as to the best time to set a function as Shared and
>>> when not to. For example, I have the following bit manipulation
>>> routines in my Class:
>>>
>>> *************** *************** *************** *************** *************** ****
>>> imports System
>>>
>>> NameSpace MyFunctions
>>>
>>> Public Class BitHandling
>>>
>>> '*----------------------------------------------------------*
>>> '* Name : BitSet *
>>> '*----------------------------------------------------------*
>>> '* Purpose : Sets a given Bit in Number *
>>> '*----------------------------------------------------------*
>>> Public Shared Function BitSet(Number As Integer, _
>>> ByVal Bit As Integer) As Long
>>> If Bit = 31 Then
>>> Number = &H80000000 Or Number
>>> Else
>>> Number = (2 ^ Bit) Or Number
>>> End If
>>> BitSet = Number
>>> End Function
>>>
>>> '*----------------------------------------------------------*
>>> '* Name : BitClear *
>>> '*----------------------------------------------------------*
>>> '* Purpose : Clears a given Bit in Number *
>>> '*----------------------------------------------------------*
>>> Public Shared Function BitClear(Number As Integer, _
>>> ByVal Bit As Integer) As Long
>>> If Bit = 31 Then
>>> Number = &H7FFFFFFF And Number
>>> Else
>>> Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
>>> End If
>>>
>>> BitClear = Number
>>> End Function
>>>
>>> '*----------------------------------------------------------*
>>> '* Name : BitIsSet *
>>> '*----------------------------------------------------------*
>>> '* Purpose : Test if bit 0 to bit 31 is set *
>>> '*----------------------------------------------------------*
>>> Public Shared Function BitIsSet(ByVal Number As Integer, _
>>> ByVal Bit As Integer) As Boolean
>>> BitIsSet = False
>>>
>>> If Bit = 31 Then
>>> If Number And &H80000000 Then BitIsSet = True
>>> Else
>>> If Number And (2 ^ Bit) Then BitIsSet = True
>>> End If
>>> End Function
>>>
>>> End Class
>>>
>>> End Namespace
>>>
>>> *************** *************** *************** *************** *************** *****
>>>
>>> Now I have these set up as shared so I don't have to create an
>>> instance of the class:
>>>
>>> temp = BitHandling.Bit Set(temp,3)
>>>
>>> vs.
>>>
>>> dim MyBits as new BitHandling
>>> temp = MyBits.BitSet(t emp,3)
>>>
>>> I am also setting up my function to send out various emails which
>>> entails reading an Sql Record and reading a text file from disk, as
>>> well as sending the email:
>>>
>>> SmtpMail.SmtpSe rver = mailServer
>>> smtpMail.Send(m essage)
>>>
>>> What would tell me that I need to make this a non-shared function vs
>>> a shared one?
>>>
>>> Thanks,
>>>
>>> Tom
>>>
>>
>>
>
>



Nov 19 '05 #9

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:uH******** *****@TK2MSFTNG P12.phx.gbl...
You've lost me a bit with the mass amounts of code.

That's exactly what I'm saying about moving it around (as a parameter).

As for your error. Objects which you typically program with in your page
and user controls such as Request, Response, Server, ... are there because
they are exposed as part of the System.Web.UI.C ontrol class your page/user
control inherits from (couple levels deep).

Your email class inherits directly from Object, so Request, Response,
Server are meaningless. To get references to these objects within your
class functions, you need to use System.Web.Http Context.Current which
returns the current context (ie the web request) which exposes the
Response, Request, Server, ...

so you would do:

dim context as HttpContext = HttpContext.Cur rent
if context is nothing then 'possible if someone is trying to use this
class outside of a web-scope
throw new InvalidOperatio nException("MyF unc needs to be called from web
request") 'maybe you can do something other than throw an exception?
end if
'now you have access to your request and response objects, here's an
example
dim request as HttpRequest = context.Request
dim someValue as string =Request.QueryS tring("blah")

I may be a little dense here.

If I do this:

*************** *************** *************** *************** *************** ***
Imports System.Web.HTTP Context
Imports Microsoft.Visua lBasic

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
dim URLPath As String = Left(Current.re quest.path,
InStrRev(Curren t.request.path, "/") - 1)
end sub

End Class

End Namespace
*************** *************** *************** *************** *************** ***

Where I use "Current.reques t.path" - it works fine.
If I do this:
*************** *************** *************** *************** *************** ***
Imports System.Web.HTTP Context
Imports System.Web.HTTP Context.Current
Imports Microsoft.Visua lBasic

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
dim URLPath As String = Left(request.pa th, InStrRev(reques t.path, "/") -
1)
end sub

End Class

End Namespace
*************** *************** *************** *************** *************** ***
Where I have "Imports System.Web.HTTP Context.Current ", I get 2 errors:

C:\Inetpub\wwwr oot\staffingwor kshop\emailold3 .vb(2) : error BC30466:
Namespace or type 'Current' for the Imports 'System.Web.HTT PContext.Curren t'
cannot be found.

Imports System.Web.HTTP Context.Current

and

C:\Inetpub\wwwr oot\staffingwor kshop\emailold3 .vb(10) : error BC30469:
Reference to a non-shared member requires an object reference.

dim URLPath As String = Left(request.pa th,
InStrRev(reques t.path, "/") - 1)

You, and the error, say I need to have an object reference. But when I
create an aspx page (where I am using code inside), I don't need this. I
can reference request (and MapPath) directly.

I understood that the difference between code-inside and code-behind was
that you had to explicitly do the imports in a code-behind file). But in
this case, it is even more than that.

That is where I am confused.

Thanks,

Tom
hope that helps..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:u0******** ********@TK2MSF TNGP15.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:O%******** ********@tk2msf tngp13.phx.gbl. ..
You would create an instance class with instance members if you wanted
to create an Email object, set it's properties and have a Send() method,
ala:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
you would use a shared member if you wanted to pass everything in as
parameters

EmailHelp.Send( "some subject", "xxx")

I personally prefer the syntax of the 2nd example...but if you wanted to
keep a bunch of different emails, say you wanted to cache them or move
them around between your layers, it'd be necessary to have distinct
instances.


I prefer the 2nd example also.

But when you talk about caching or moving them, are you saying that you
want an instance so you could do something like:

sub somefunction (myEmail as Email)
...
myEmail.somemet hod()

end sub

Then using your 1st example:

dim email as new Email("some subject")
email.Body = "xxx"
email.Send()
...
somefunction(em ail) ' calling the above function
BTW, I took my email function and tried to compile it using:

C:\Inetpub\wwwr oot\staffingwor kshop>vbc /t:library email.vb
/r:system.web.dl l /r:system.data.d ll /r:system.dll
/r:Microsoft.Vis ualBasic.dll

and I get the following errors:

C:\Inetpub\wwwr oot\staffingwor kshop\email.vb( 49) : error BC30469:
Reference to a non-shared member requires an object reference.

I am getting this for request.path and for MapPath.

My file looks like:
*************** *************** *************** *************** *************** *******
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.Sess ionState
Imports System.Web.Mail
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports Microsoft.Visua lBasic

NameSpace MyFunctions

Public Class Email

Public Shared sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_ftsolutions" )
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("..\..\aut omail\new_accou nt_automail.htm ")) then
objStreamReader =
File.OpenText(M apPath("..\..\a utomail\new_acc ount_automail.h tm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub

End Class

End Namespace
*************** *************** *************** *************** *************** *********

This happens whether emailSend is Shared or not.

Thanks,

Tom

Trust your gut feeling.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e5******** ******@TK2MSFTN GP12.phx.gbl...
> Tom:
> Is the function manipulating instance data? Looking at your
> functions, they look like they need to be shared.
>
> Think of it this way.
>
> You have a class called Car, which has a property named AirbagDeployed
> as boolean
>
> if you have a function named DeployAirbag() it would need to be an
> instance (non-shared) method. Why? Because you would have create a
> new car instance and would want to deploy that particular car's
> airbag. in other words, instnace methods behave against a particular
> instance. Your BitHandling class looks like a helper function for
> dealing with bit information. You wouldn't create separate instance
> of them as you don't need to represent different bithandling (as you
> would differnent cars)...ergo your function don't behave against
> instances.
>
> A case where you might have instances is if your BitHandling was
> culture-specific. In which case you might have different bithandling
> instances per culture. In this case you'd need to create a new
> BitHandling class (specifying the culture) and then your functions
> would behave against that particular instance. (As an aside, an
> alternative would be to pass the culture information to each shared
> function so you wouldn't need to create culture-specific instances
> which works fine for a single parameter, but becomes messy when you're
> talking about more..)

That's what gets confusing. Trying to figure out the instances bit (no
pun intended) and if it is needed. Here is the other function that I
am creating to put in my MyFunctions Namespace. I would give is a
class of email, I suppose.

This is just my prototype email program that I am putting together to
make a more generalized function from.

It, in essence:
gets the connection to Sql
gets the email record to get the subject and from/to addresses
reads a text file to put into the body of the message
adds a few things to the email
sends the email

I would probably change the function to something like:

public shared sendEmail(filen ame as string, subject as string)

*************** *************** *************** *************** *************** ************
sub sendEmail ( )
dim webMasterEmail As String
dim emailSubject As String
Dim mailServer As String
Dim contactEmail As String
Dim screenTestSubje ct As String

Dim emailReader As SqlDataReader

Dim ConnectionStrin g as String
=System.Configu ration.Configur ationSettings.A ppSettings("MM_ CONNECTION_STRI NG_solutions")
Dim objConn as New SqlConnection (ConnectionStri ng)
Dim CommandText as String = "Select
MailServer,WebM asterEmail,Cont actEmail,Screen TestSubject from
emailResponse where ClientID = '1234'"
Dim objCmd as New SqlCommand(Comm andText,objConn )

objConn.Open()

emailReader = objCmd.ExecuteR eader

if emailReader.Rea d then
mailServer = emailReader("Ma ilServer")
webMasterEmail = emailReader("We bMasterEmail")
contactEmail = emailReader("Co ntactEmail")
screenTestSubje ct = emailReader("Sc reenTestSubject ")
end If

objConn.close()

dim URLPath As String = _
Left(request.pa th, InStrRev(reques t.path, "/") - 1)

Dim objStreamReader as StreamReader
Dim strInput As String
Dim strBuffer As String

If File.exists(Map Path("\new_acco unt_automail.ht m")) then
objStreamReader = File.OpenText(M apPath("\new_ac count_automail. htm"))
strInput = objStreamReader .ReadLine()
while strInput <> nothing
strBuffer = strBuffer & strInput
strInput = objStreamReader .ReadLine()
end while
objStreamReader .Close
end if

Dim Message As New MailMessage()
message.To = contactEmail
message.From = webMasterEmail
message.Subject = screenTestSubje ct
message.Body = "This is line 1<br><br>"
message.Body = message.Body & "This is line 2<br><br>"
strInput = strBuffer.repla ce("#MESSAGE#", message.Body)
strInput = strInput.replac e("#MAILTITLE#" ,"Screen Test Confirmation")
message.Body = strInput
message.BodyFor mat = MailFormat.Html
SmtpMail.SmtpSe rver = mailServer
smtpMail.Send(m essage)
end sub
*************** *************** *************** *************** *************** **

Would this work as a shared function, or would I need to make this an
instance?

Thanks,

Tom
>
> Karl
>
>
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "tshad" <ts**********@f tsolutions.com> wrote in message
> news:uB******** ******@tk2msftn gp13.phx.gbl...
>>I am setting up some of my functions in a class called MyFunctions.
>>
>> I am not clear as to the best time to set a function as Shared and
>> when not to. For example, I have the following bit manipulation
>> routines in my Class:
>>
>> *************** *************** *************** *************** *************** ****
>> imports System
>>
>> NameSpace MyFunctions
>>
>> Public Class BitHandling
>>
>> '*----------------------------------------------------------*
>> '* Name : BitSet *
>> '*----------------------------------------------------------*
>> '* Purpose : Sets a given Bit in Number *
>> '*----------------------------------------------------------*
>> Public Shared Function BitSet(Number As Integer, _
>> ByVal Bit As Integer) As Long
>> If Bit = 31 Then
>> Number = &H80000000 Or Number
>> Else
>> Number = (2 ^ Bit) Or Number
>> End If
>> BitSet = Number
>> End Function
>>
>> '*----------------------------------------------------------*
>> '* Name : BitClear *
>> '*----------------------------------------------------------*
>> '* Purpose : Clears a given Bit in Number *
>> '*----------------------------------------------------------*
>> Public Shared Function BitClear(Number As Integer, _
>> ByVal Bit As Integer) As Long
>> If Bit = 31 Then
>> Number = &H7FFFFFFF And Number
>> Else
>> Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
>> End If
>>
>> BitClear = Number
>> End Function
>>
>> '*----------------------------------------------------------*
>> '* Name : BitIsSet *
>> '*----------------------------------------------------------*
>> '* Purpose : Test if bit 0 to bit 31 is set *
>> '*----------------------------------------------------------*
>> Public Shared Function BitIsSet(ByVal Number As Integer, _
>> ByVal Bit As Integer) As Boolean
>> BitIsSet = False
>>
>> If Bit = 31 Then
>> If Number And &H80000000 Then BitIsSet = True
>> Else
>> If Number And (2 ^ Bit) Then BitIsSet = True
>> End If
>> End Function
>>
>> End Class
>>
>> End Namespace
>>
>> *************** *************** *************** *************** *************** *****
>>
>> Now I have these set up as shared so I don't have to create an
>> instance of the class:
>>
>> temp = BitHandling.Bit Set(temp,3)
>>
>> vs.
>>
>> dim MyBits as new BitHandling
>> temp = MyBits.BitSet(t emp,3)
>>
>> I am also setting up my function to send out various emails which
>> entails reading an Sql Record and reading a text file from disk, as
>> well as sending the email:
>>
>> SmtpMail.SmtpSe rver = mailServer
>> smtpMail.Send(m essage)
>>
>> What would tell me that I need to make this a non-shared function vs
>> a shared one?
>>
>> Thanks,
>>
>> Tom
>>
>
>



Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
4430
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few characters as possible will be matched. the regular expression module fails to perform non-greedy matches as described in the documentation: more than "as few characters as possible"
5
3755
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence their dtor is called immediately and not at the end of the function. to be able to use return objects (to avoid copying) i often assign them to a const reference. now, casting a const return object from a function to a non-const reference to this...
3
12270
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in nonblocking mode in c++? I did something ugly like --- c/c++ mixture --- mkfifo( "testpipe", 777);
25
7646
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
4527
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
3516
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
2
6119
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my pointers, but I'm not sure. Please help. The code: void equate(matrix *A, matrix *B) { int i, j; assert(A.row_dim == B.col_dim && A.col_dim == B.col_dim); for(i=0; i < A.row_dim; i++) for(j=0; j < A.col_dim; j++)
0
2345
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome jobs. When a non-secure page references a secure page with relative URL, the web server generates error until absolute URL with https prefix is used. On the other hand when a secure page references a non-secure page, the non-secure page will be...
399
12939
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or to python-3000@python.org In summary, this PEP proposes to allow non-ASCII letters as identifiers in Python. If the PEP is accepted, the following identifiers would also become valid as class, function, or variable names: Löffelstiel,...
12
29916
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.