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!

Still with not working Module! 3

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
Okay, so I created a new Web, completely from scratch, completely from within VS. I go, add a new module file, paste my code in, create my web form, paste my code in. Visual Studio hasn't given me any errors, in fact, if I right click on the module function in my web form, and click go to definition, it opens my module file, so visual studio sees my module okay.

When I go to my browser, and access that web form, I get the message:
Name 'newWebNum' is not declared.

This is really starting to bug me, cause VS isn't telling me what's up. It says it's okay.
 
What is newWebNum? (i.e. String, Int, Object, Class, . . . )
Is it actually declared?
Does the declaration have the correct scope?

I saw a forum post the other week of clearing out some file so that VS.NET will rescan the file to check for problems, but I do not remember what the file was.

Kris
 
newWebNum is declared in the module file as:
Code:
Public Function newWebNum(ByVal ordType As String) As String

The module file is named 'comFunc.vb'.

I am wondering if I need to compile this as a dll? or what?

All I want is a file with a few commands that all my pages are going to use so I don't have to retype/paste the same code over and over again.
 
I have not used a module file in .NET and I do more work in VB.NET than ASP.NET so I may be off base, but if the modules are really classes then you need to do some things.

In each class that you want to use the variable you must declare a new instance of that class

Private xVariables As New comFunc
Private xTemp As String
xTemp = xVariables.newWebNum("3")

If I am off base then someone will let you know.

Kris
- Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic.
 
Kris:
no, module files are not classes. They're like module files in old school vb6.0: code pages that hold functions that can be available to all members of a project without having to instantiate anything to get at them.

I like that ark/titanic analogy btw
:)

qwert:
ok, lets try and nip this in the bud once and for all.
To start, no: you shouldn't need to compile it as a DLL.
Let's try baby steps first though, and we'll see if its a vs.net bug-type-thing, or something in the code, k?

Here's what I want you to do:
1. Create a new webform. all I want you to put on it is a textbox, nothing else.
2. Create a new module. In it, create the following function:

Public Function HelloWorld() as string
HelloWorld = "HelloWorld"
End Function

3. Now go back to your webform, and in the page_load sub, put this:

TextBox1.Text = HelloWorld()

4. Set the new webform as the start page and run the project.

If that works, then we know that vs can (and i'm guessing it will) be able to access a public function within a module and display the result in the textbox. That also means that we know its something in your code and not something buggy with vs.net

if it doesn't work, then we'll have to do a bit more digging. But lets try and eliminate as many possibilities first before trying to dive in and fix something
:)

D'Arcy
 
K, so, it's my code. Hmmm... (I did as you said and it worked.)

So, what is wrong with my code. VS doesn't report anything? Hmmm... The module file I am trying to use is in my \Secure\ application folder. Should it be in the root folder of the web, as my test was? Also, let me post my code, and you can critique it.

BTW THANK YOU VERY MUCH FOR HELPING ME. I do appreciate it. I just hope I can help you some day, tho, that seems like a long shot.

\secure\comFunc.vb
Code:
Imports System.Data
Imports System.Data.OleDb

Public Module comFunc

#Region "Properties"
 Public dbAccess As String = "someDatabase.mdb" 'Change to working access database string.
 Public dbSQL As String = "SomeSQLString" 'Change to working SQL database string.
 Private mainReq As String = "1st@address"
 Private secReq As String = "2nd@address"
#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
 
Your module looks fine, there's nothing I can see that would cause your code to say the function name is "undeclared".

I'm not sure that just having the module in a different sub folder would change anything either, unless you've done somethign to the permissions for that "secure" folder.

k, lets try something else then:

in your project, create two new modules:
one at the root level and another in the same directory as your comFunc.vb

In the root one, put the function:

Public Function IsInRoot() as string
IsInRoot = "This is from the Root Module"
End Function

and in the other one put:

Public Function IsInSecure() as string
IsInSecure = "This is from teh secure module"
End Function

Then create a webpage with two textboxes, and in the page load put

TextBox1.Text = IsInRoot()
TextBox2.Text = IsInSecure()

If you get an error message on the IsInSecure, then it could be an issue with the files in that folder. However, if it checks out, then we know that its not a permission problem, and we should look further into the code.

And np man, I'm just glad I could help.
:)

D
 
Try declaring the methods as static
penny1.gif
penny1.gif
 
D, that worked, so that mean's it's code somewhere.

Link, you mean, instead of this:
Code:
Public Module comFunc
do this:
Code:
Public Static Module comFunc
 
Link, Modules cannot be declared Static. (as per VS)
I tried Static Module comFunc
 
Could I set a Namespace for the module and Import that Namespace into my codebehind.
 
K, tried this in my module:
Code:
Namespace myFuncs

Added this to my codebehind:
Code:
Imports myFuncs

But get this: Namespace or type 'myFuncs' for the Imports 'myFuncs' cannot be found.
 
K, don't worry about the namespace thing. Let's just walk this puppy thrugh one step at a time.

now, we know that its code somewhere. so lets try a few things:

1. In one of the new webpages you created, try and add a referene to newWebNum
i.e. in the page load for one of hte pages, put
TextBox1.Text = newWebNum
It'll crap out, but thats ok: the goal is to see if it will recognize your function.

2. If you get the same "newWebNum not declared" error, then take the code from newWebNum, and put it in a function named newWebNum2 that you'll crete in one of the code module files we created earlier. Then, try step 1 again but with the different module
i.e.
TextBox1.Text = newWebNum2
Again, it may crap out, but the goal is to NOT get the "newWebNum2 not declared" error.

D

 
K, I left it in the original module file, comFunc.vb (step 1), changed my test page to this:
Code:
  TextBox1.Text = IsInRoot()
  TextBox2.Text = newWebNum("a")

And guess what, crap? No crap, it worked!!! So what gives?
 
If I have this:
Protected WithEvents timeLeft As System.Web.UI.WebControls.Label
Protected WithEvents img1 As System.Web.UI.WebControls.Image
Protected WithEvents jobLbl As System.Web.UI.WebControls.Label
Protected WithEvents ordLkp As System.Web.UI.WebControls.TextBox

Do I still need to Import System.Web.UI.WebControls?

Could that be throwing it off?
 
YAY! Hey, thats great though: we know that its NOT your module at all! Now we need to look at your actual code page and find out why it doesn't like your module.

So lets try this next:

In your real web form (the one giving you the error), comment (not delete, just comment) out all your stuff in the page load. Then pick a textbox and do this:

TextBoxWhatever.Text = newWebNum("a")

then run it and see what happens. If it conks out, then we know that its something with the entire page. If it doesn't, then maybe its something with the actual sub/function calling it.

D
 
Had a couple of labels while I'm debugging. Here it is:
Msg2.Text = newWebNum("y")
testCode1.Text = newWebNum("w")

Errors out on the first one.

Just for kicks, changed it to this:
TextBox1.Text = newWebNum("y")
Still not declared.
 
Just curious:

If you type newWebNum(

does intellisense comeup with a tool-tip saying what paramter it expects?
 
Yes. Also tried this, dropped all the HTML onto my test web form that had been working... and let it create all the declarations for all the controls in the codebehind, so it's just that, and the command:
TextBox1.Text = newWebNum("y")

And guess what! It doesn't work anymore.
 
HEY!!! Something new. You know how when I dropped my real webform HTML into the test web form it broke! Well, I removed the Src= section and it worked!

However, I go back to my original code and do the same thing and I get a Parser Error:
Could not load type 'seniors'.

<%@ Page Language=&quot;vb&quot; Debug=&quot;True&quot; Inherits=&quot;seniors&quot; CodeBehind=&quot;seniors.aspx.vb&quot; %>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top