Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with my module.

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
Well, I did it, I went to Project|Add Item and got me a module file. I put my common code in there and my common strings for database connectivity... and when I go back to my codebehind, I can start typing and autofil picks up that I'm talking about my module, and offers me my settings. However, when I go to run the page, I get a Compilation error!

Here is the code it pukes on:
Code:
nowJob.Text = "W" & comFunc.newWebNum("w")

It says 'comFunc' is not declared.

I think this is something I haven't done to register the module correctly or something... any ideas?
 
Check and make sure your sub is declared as Public.

One other thing: Is comFunc the name of your module? If it is, you don't actually need it. You can just call the actual sub/procedure directly (its not like a class whre you need to specify the class first, then the sub/function belonging to it)

D
 
I have 1 sub and 1 function... both declared as public. Also, I have tried accessing it both ways. Still newWebNum is not declared.
Here is what I have:
Code:
Imports System.Data
Imports System.Data.OleDb

Module comFunc

#Region "Properties"
 Public dbAccess As String = "Access DB Connection String"
 Public dbSQL As String = "SQL Connection String"
 Private mainReq As String = "an e-mail"
 Private secReq As String = "another e-mail"
#End Region

#Region "Methods"

 Public Sub doCmd(ByVal strSql As String, ByVal refDb As String)
  Dim connStr As String
  If refDb = "A" Or refDb = "a" Then
   connStr = dbAccess
  ElseIf refDb = "S" Or refDb = "s" Then
   connStr = dbSQL
  Else
   Exit Sub
  End If

  Dim objConn As New OleDbConnection(connStr)
  Dim objCmd As New OleDbCommand(strSql, objConn)
  objConn.Open()
  objCmd.ExecuteNonQuery()
  objConn.Close()
 End Sub

 Public Function newWebNum(ByVal ordType As String) As String
  Dim strSql As String = "SELECT * FROM tblNewOrderNum"
  Dim objData As New DataSet()
  Dim objConn As New OleDbConnection(dbAccess)
  Dim objAdapt As New OleDbDataAdapter(strSql, objConn)
  Dim objTable As DataTable
  Dim objRow As DataRow
  Dim strNewNumI, strNewNum, srcColumn As String
  objAdapt.Fill(objData, "NewOrders")
  objTable = objData.Tables("NewOrders")
  objRow = objTable.Rows(0)
  If ordType = "y" Then
   srcColumn = "yOrders"
  Else
   srcColumn = "wOrders"
  End If
  strNewNum = objRow(srcColumn)
  strNewNumI = strNewNum + 1
  Try
   strSql = "UPDATE tblNewOrderNum SET " & srcColumn & " = '" & strNewNumI & "' "
   doCmd(strSql, "A")
  Catch ex As Exception
  End Try
  Return strNewNum
 End Function

#End Region

End Module
 
Okay, I'm back for the week, but I am still having this problem. One thing I noted, when VS built the module file it placed it in my root folder of this web, instead of the folder of the application I am going to be using it in. Is this a problem? I put the files up that are using it... lRollReorder.aspx and associated files, as well as my comFunc.vb module file. Check it out here:
 
Did you declare comFunc in the place where you are trying to use it?

Dim comFunc as new comFunc()

comFunc.newWebNum("w")
penny1.gif
penny1.gif
 
I try, but it says:
Module 'comFunc' cannot be used as a type.

Hmmm... is it because this is a module, and not a Function? Do I need to compile it as a .Dll?
 
Now, no messages in VS, but the page gives me:
Type 'comFunc' is not defined.

Code:
Private Sub lkpBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkpBtn.Click
  Dim comFunc As New comFunc()
  oldJob.ReadOnly = True
  newOrdLbl.Visible = True
  lkpBtn.Visible = False
  nowJob.Visible = True
  nowJob.Text = "W" & comFunc.newWebNum("w")
 End Sub

You can see the full code under my folder on the Tek-Tips workspace.
 
qwert I am not sure exactly what your error was. But I may have a solution for you.

I downloaded your module comFunc.vb
I put it into the folder for a test web app.
I hit "show all files"
I right clicked the file and "include in project"

Then all I did was type newWebNum("stuff") in my page load and it worked. Besides not being able to find the database but it did work. You don't need to declare the module as a type just use the methods within it.

They do pop up with the intellisense as well.

Hope that works for you That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top