I can't see a functions between classes

P

Pepehammer

Hi guys!

I got two classes, class1 and class2.

I'm trying to call a function defined in class1 from class2, but I get the
following error:

BC30451: Name 'WriteString' is not declared

How I can solve this issue?

Thanks a lot!
 
B

Bryant Hankins

This is most likely a scope issue:

Is class1 in a namespace? If so ensure you fully qualify class1 with the
namespace like: mynamespace.class1

Are class 1 and class 2 in different assemblies? If so, make sure one is
referencing the other.

Is the method static? if not, make sure you have created an instance of the
object.

Does class 1 compile? If not, you won't be able to "see" it's method.

If none of these help can you post some sample code?
 
J

John Saunders

Bryant Hankins said:
This is most likely a scope issue:

Is class1 in a namespace? If so ensure you fully qualify class1 with the
namespace like: mynamespace.class1

Are class 1 and class 2 in different assemblies? If so, make sure one is
referencing the other.

Is the method static? if not, make sure you have created an instance of the
object.

Does class 1 compile? If not, you won't be able to "see" it's method.

If none of these help can you post some sample code?

Also, is the method (function) declared as Public? If not, is it both
declared Friend and are both classes in the same assembly?
 
P

Pepehammer

The problem apperas when i call WriteString() function
Thanks

Imports System

Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient


'---------- // CLASS : StringComponents
Public Class StringComponents
Inherits Page

'---------- // SUB : WriteString
Public Sub WriteString(SayItNow as String)
Response.Write(SayItNow)
End Sub

End Class

'---------- // CLASS : DataComponents
Public Class DataComponents
Inherits Page

'---------- // FUNCTION : OpenOleDbConnection
Public Function OpenOleDbConnection(ByVal MyConnection As
OleDbConnection, ByVal connString As String) As Boolean
Dim bReturn As Boolean
Try
If MyConnection.State <> ConnectionState.Open Then
With MyConnection
.ConnectionString = connString
.Open()
bReturn = True
End With
Else
WriteString("ERROR: Trying to open connection " &
MyConnection.Database.ToString & ". Connection is already open.")
bReturn = False
End If
Catch ex As Exception
WriteString(ex.Message & ex.StackTrace)
bReturn = False
Finally
OpenOleDbConnection = bReturn
End Try
End Function

'---------- // FUNCTION : CloseOleDbConnection
Public Function CloseOleDbConnection(ByVal MyConnection As
OleDbConnection) As Boolean
Dim bReturn As Boolean
Try
If MyConnection.State <> ConnectionState.Closed Then
With MyConnection
.Close()
.Dispose()
bReturn = True
End With
Else
WriteString("ERROR: Closing connection. Connection already
closed.")
bReturn = False
End If
Catch ex As Exception
WriteString(ex.Message & ex.StackTrace)
bReturn = False
Finally
CloseOleDbConnection = bReturn
End Try
End Function


End Class
 
B

Bryant Hankins

You just need to create an instance of the class before you call it like so:


Dim com As StringComponents = New StringComponents
com.WriteString("TEST")
 
P

Pepehammer

Thanks!

Bryant Hankins said:
You just need to create an instance of the class before you call it like so:


Dim com As StringComponents = New StringComponents
com.WriteString("TEST")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top