|
-
Sep 22nd, 2005, 02:44 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Functions
Can someone explain to me how to make a custom function.
Like a function that takes and returns something.
-
Sep 22nd, 2005, 02:48 PM
#2
Re: Functions
Like this:
VB Code:
'Function FunctionName(arguments) as ReturnType
Function FunctionName(Arg1 As Long, Arg2 As String) As String
'
''Function body
'
FunctionName = ReturnData ' <-- returns ReturnData to caller
End Function
-
Sep 22nd, 2005, 02:53 PM
#3
Lively Member
Re: Functions
it's really easy!
Public Function function_name(var1 as integer, var2 as string) as integer
in the function you can have some calculations. at the end u just write
function_name = solution
End Function
to call a function you use the function like this
variable = function_name(var1, "abc")
or
if function_name(var1,"abc") = true then
-
Sep 22nd, 2005, 02:58 PM
#4
Hyperactive Member
Re: Functions
You can do it within the Form (General) or you create a module
If you have a MSDN try to look for
Function Statement Visual Basic for Applications Reference
Details are well there.
-
Sep 22nd, 2005, 07:26 PM
#5
Thread Starter
Addicted Member
Re: Functions
Ok, I tried one. What is wrong with this it never stops looping when I use it.
Code:
Function LoopSend(txt As String, i As Integer)
Dim i2 As Integer
i2 = 0
Do While (i2 < i)
SendKeys txt
i2 = i2 + 1
Loop
End Function
-
Sep 22nd, 2005, 07:32 PM
#6
Re: Functions
Based on what you posted, it is difficult to say.
What did you pass it for parameters, i.e., what does i equal? What does txt equal?
Also, functions return a value but your function is not set up that way. Basically, what you have is a Sub. To be a true function, you would declare is as something like[Highlight=VB]Private Function LoopSend(txt As String, i As Integer) As ? - what do you want returned? A string? An integer? A long?
-
Sep 22nd, 2005, 07:33 PM
#7
Re: Functions
Why don't you use a For loop? That's what it's for. And be sure to use [VBCODE] tags, not [CODE] tags for VB code 
Also indenting your code makes it easier to read and debug. VB.NET automatically
indents it for you, thank God.
VB Code:
Function LoopSend(txt As String, ByVal i As Long) As Boolean
Dim i2 As Long 'Always best to work with Longs cause its the fastest
'computing data type and there's no worry for overflow.
For i2 = 0 To i
SendKeys txt
Next i
LoopSend = True
End Function
-
Sep 22nd, 2005, 07:44 PM
#8
Thread Starter
Addicted Member
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
|