Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 20th, 2006, 07:49 AM
Authorized User
 
Join Date: Mar 2006
Location: , , United Arab Emirates.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to call a sub in a sub

I want to call a Sub Routine from within a Sub Routine but ended up in error: How can I do it correctly.

The Sub which is called is like this :-
===========================
  Sub Upload(s As Object, e As EventArgs)
    If Not (txtUpload.PostedFile Is Nothing) Then
      Dim postedFile As HttpPostedFile = txtUpload.PostedFile

      Dim filename As String = Path.GetFileName(postedFile.FileName)
      postedFile.SaveAs("C:\Uploadfiles\" & filename)
      lblMessage.Text = "Contract File has been uploaded"
    End If
  End Sub
================

The error I got is like this :

Compiler Error Message: BC30451: Name 'a' is not declared.

Source Error:

Line 143: objConn.open()
Line 144:
Line 145: upload(a,b)
Line 146: objCmd.ExecuteNonQuery()
Line 147: objConn.Close()
===============================
How do I declare it ? How to call the sub with parameters in a sub ?



  #2 (permalink)  
Old March 20th, 2006, 10:47 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What do you expect the values of A and B to be would be a better question? Judging from your Methods signature im assuming an htmlInputFile and its event args??

You can't call a method inside of a methods signature because methods dont return values they only do something, instead you should declare 2 functions, so something like this:

Private sub upload(ByVal a as string, byVal b as string)
'Do something
End Sub

Private Function getA (byVal i as integer) as string
Dim strA as string
'Do something
Return strA
End Function

Private Function getB (byVal i as integer) as string
Dim strB as string
'Do something
Return strB
End Function

then you can do

Upload(getA(intValue1), getB(intValue2))


Alternatively you can call a sub inside of a sub like this:

Private Sub Upload()
  AnotherSub([signature])
End Sub
Hope this helps.

"The one language all programmers understand is profanity."
  #3 (permalink)  
Old March 21st, 2006, 04:44 AM
Authorized User
 
Join Date: Mar 2006
Location: , , United Arab Emirates.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanx dparsons, but help me again.
What I do is saving quite some data from a screen to a database as well as uploading a file which is a contract.

The Upload subroutine does the job of uploading by the onserverclick attribute of a seperate button control calling a method.

But since I have to save other data also from the form while clicking the save data button. How to combine these 2 tasks at one click.



  #4 (permalink)  
Old March 21st, 2006, 08:48 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Busybee,
   In your OnServerClick method, handle all of the form data (textboxes, dropdownlists, etc) for your file upload write a method similiar to this:

Private Sub FileUpload(ByVal fileUp as HTMLInputFile)
 '//Process the file to your database
End Sub

in your onServerClick method do this

Sub onServerClick(ByVal Sender as Object, e as EventArgs)
fileUpload([YourHtmlInput Control])
'//Process form Data
End Sub

Hope this helps you.

"The one language all programmers understand is profanity."
  #5 (permalink)  
Old March 22nd, 2006, 01:39 AM
Authorized User
 
Join Date: Mar 2006
Location: , , United Arab Emirates.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx Doug
I curse me for not thinking this way :D

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call Outlook snufse Visual Studio 2005 0 March 11th, 2008 11:10 AM
How to Call Sub in ASP dpkbahuguna Classic ASP Basics 8 January 31st, 2007 03:46 PM
don't know how to call it stasnikov Access 2 January 17th, 2007 04:02 AM
Call a Function stealthdevil Access VBA 2 November 2nd, 2006 10:38 AM
how to call the form? hussar91404 C# 2 June 11th, 2006 08:10 AM



All times are GMT -4. The time now is 05:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.