|
-
Jul 12th, 2009, 01:29 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] confusion abt function.
hi all,
i am a little confused abt function and a public sub .please take a look at the below examples.
vb Code:
Private Sub Command_Click() Call intO(5, 6) Debug.Print intO End Sub Public Function intO(intL As Integer, intX As Integer) As Integer intO = intL + intX Exit Function End Function
here i get an error on debug.print intO although this can be over come by adding these lines
vb Code:
Private Sub Command_Click() dim intOut as integer intOut = Call intO(5, 6) Debug.Print intOut End Sub
my question is i am trying to return the value from the public function . but i get errors.. i tried to use the return statement but still i get errors. although i have publicly declared intO as an integer then why do i have to assign it to a variable again?
-
Jul 12th, 2009, 01:52 AM
#2
Re: confusion abt function.
When you put: Debug.Print intO you're calling the intO function again, and not giving it any parameters...
Debug.Print intO(5, 6) would have worked...
And: intOut = Call intO(5, 6) should be: intOut = intO(5, 6)
-
Jul 12th, 2009, 03:24 PM
#3
Re: confusion abt function.
It's not recommended to use hungarian notation on functions because it can lead to confusion with variables.
-
Jul 21st, 2009, 03:47 AM
#4
Thread Starter
Hyperactive Member
Re: confusion abt function.
hey.. everything was working well until i encountered another problem.
i have a sub
vb Code:
private sub form(Load)
call sortData("apple","ball","cat","dog")
end sub
public function sortData(strOne as string,strTwo as string, strThree as string,strFour as string)
'rest o'da codes here..
end function
but i cannot call sortData as it says sortData argument not optional.. i changed the function to a sub yet it don't work.. i am confused..
i am in China and no body teaches me VB6 
-
Jul 21st, 2009, 04:07 AM
#5
Re: confusion abt function.
The code you showed should not give that error, but this minor change would:
Code:
call sortData("apple","ball","cat")
The error means that the sub/function needs a certain amount of arguments (aka parameters), and your call has less.
-
Jul 21st, 2009, 04:22 AM
#6
Re: confusion abt function.
Fewer!
I've noticed that television seems to have collectively decided that fewer is no longer a word, and it drives me nuts. "More taste, less calories." Gah!
Less of a whole
Fewer in number
For example, you could have less pie by having fewer slices of pie.
-
Jul 21st, 2009, 10:51 AM
#7
New Member
Re: confusion abt function.
Now I'm confused. Although actually there is nothing wrong with calling a function that way you don't have to. You could use Fewer words (LOL) and just say
sortData "apple","ball","cat","dog"
However, normally if you aren't returning a value you would use a Sub not a function, and I'm confused about what the representative SortData function does when you pass it arguments and get no return value.
And Si is correct, if you executed your code EXACTLY as you've shown it will work. You must have a typo either in the function declaration or in the call.
-
Jul 21st, 2009, 01:16 PM
#8
Re: confusion abt function.
I'm assuming it's just a made-up example to give us the basic idea, and that there is no SortData function in his project. Setting up a sort function where the inidividual elements get passed as parameters is bad enough, but then to not even use a parameter array? The mind boggles.
-
Jul 21st, 2009, 10:22 PM
#9
Thread Starter
Hyperactive Member
Re: confusion abt function.
 Originally Posted by Ellis Dee
I'm assuming it's just a made-up example to give us the basic idea, and that there is no SortData function in his project. Setting up a sort function where the inidividual elements get passed as parameters is bad enough, but then to not even use a parameter array? The mind boggles.
yes, Ellis you are correct.. my Os is windows 7 and i was using a vd addin that would split long lines of codes to shorter lines to make it readable.. unfortunately a parameter was being deleted in the process and i kept on getting errors. now, its fine. thank you all.
i am in China and no body teaches me VB6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|