Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 20th, 2006, 11:40 AM
murthyspd murthyspd is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 49 murthyspd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 48 m 13 sec
Reputation Power: 4
Can a subroutine return a value

Hi ,

Can a subroutine return a value ? or can it be made to do so ?

for eg

Private Sub multi() as Integer

End Sub

this statement gives an error "end of statement" at "as" though.

Reply With Quote
  #2  
Old June 20th, 2006, 12:24 PM
ProEdge's Avatar
ProEdge ProEdge is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2004
Location: Somewhere I belong
Posts: 1,565 ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level)ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level)ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level)ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level)ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level)ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 17 h 7 m 15 sec
Reputation Power: 39
No it cannot. You need to create a Function to return a value. Subroutines are only used to execute something while Functions can actually execute and return a value.
Comments on this post
Nocturns2 agrees: straight to the point.
__________________
Keep it Prodigy, Keep it Real

Reply With Quote
  #3  
Old June 21st, 2006, 10:56 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
Quote:
Originally Posted by murthyspd
Hi ,

Can a subroutine return a value ? or can it be made to do so ?

for eg

Private Sub multi() as Integer

End Sub

this statement gives an error "end of statement" at "as" though.


As ProEdge said, as you put the instructions it can't work, the right way is

Function multi() as Integer

End Function

but sub can return a value if the parameter is refered as by reference not as a value, but the syntax is.

Sub muti(byref AN_INT as integer)

end sub

The vaue will be returned in the AN_INT variable

Reply With Quote
  #4  
Old June 21st, 2006, 11:13 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,871 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 16 h 47 m 27 sec
Reputation Power: 500
Quote:
Originally Posted by Darius
As ProEdge said, as you put the instructions it can't work, the right way is

Function multi() as Integer

End Function

but sub can return a value if the parameter is refered as by reference not as a value, but the syntax is.

Sub muti(byref AN_INT as integer)

end sub

The vaue will be returned in the AN_INT variable

Actually, the variable AN_INT isn't returned, when passing ByRef you are actually sending the Procedure the memory address of the object to be affected. The sub does whatever it's going to do, then control is returned back to the code that originally called the Sub.

So the object (variable) itself isn't being passed to or from the procedure, only the memory address is getting passed.

ByVal - means a copy of the the original object is being used.

ByRef - means the original object itself is being used.

Reply With Quote
  #5  
Old June 22nd, 2006, 02:28 PM
vb_programmer vb_programmer is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 18 vb_programmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 52 sec
Reputation Power: 0
Yes. Use ByRef variables as args for your Sub.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Can a subroutine return a value


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT