Function question from a beginner...please help! 
Author Message
 Function question from a beginner...please help!

Hi.  My name's Josh.  I have a simple question involving functions that I
was hoping someone could help me answer.

I have some code that goes like this:

---START OF CODE---

For t = 1 to 8 step 2

text2(t).text = Form1.text(t).text

('and some other lines just like the one above)

Next t

---END OF CODE---

  I was thinking...rather than make this a for/next loop, could I put it
into a function, and just pass the function the number I wanted t to equal?
(This would help me later on in the program, where I have to do this same
code block again.  Currently I am using another for/next loop to do it
again, which seems to be a waste of code).

  My custom-made function went like this:

---START FUNCTION---

Function Josh (t)

text2(t).text = Form1.text(t).text

End Function

---END FUNCTION

...but it didn't work.  Could someone help me out with the proper way to
declare and format a function?  I have looked at the MSDN disk, tried to do
it like it was presented there, but am still baffled.

  Thanks for your help!!

  Josh DeWinter
  Spokane, WA




Sat, 05 Jan 2002 03:00:00 GMT  
 Function question from a beginner...please help!
Josh,

If you want the function to be available to other forms in the project,
declare it public :

Public Function Josh(t as integer).
....(your code)
End Function

If you only want it to be available to the form it's declared in, declare it
private :

Private Function Josh(t as integer).
....(your code)
End Function

Declare parameter t as an integer because if you don't it will be assumed a
variant, (code will work but it is common practice, check out the par about
'Option Explicit')

If you're always using the same for/next loop, why not put it in the
function as well ?

Public Function Josh(T as integer)                ' T is the upper value of
the for/next loop
    Dim I as integer
    For I = 1 to T step 2
            text2(I).text = Form1.text(I).text
    Next I
End Function

Yours truly,
Bonehead



Sat, 05 Jan 2002 03:00:00 GMT  
 Function question from a beginner...please help!
Functions are supposed to take an argument or arguments and manipulate them to
return a value. What you are trying to do looks more like a job for a sub.
Don't functions usually end with

nameOfTheFunction = expressionWhichReturnsValueOfTheFunction ?

I recommend a sub.

Pulat

Quote:

> Hi.  My name's Josh.  I have a simple question involving functions that I
> was hoping someone could help me answer.

> I have some code that goes like this:

> ---START OF CODE---

> For t = 1 to 8 step 2

> text2(t).text = Form1.text(t).text

> ('and some other lines just like the one above)

> Next t

> ---END OF CODE---

>   I was thinking...rather than make this a for/next loop, could I put it
> into a function, and just pass the function the number I wanted t to equal?
> (This would help me later on in the program, where I have to do this same
> code block again.  Currently I am using another for/next loop to do it
> again, which seems to be a waste of code).

>   My custom-made function went like this:

> ---START FUNCTION---

> Function Josh (t)

> text2(t).text = Form1.text(t).text

> End Function

> ---END FUNCTION

> ...but it didn't work.  Could someone help me out with the proper way to
> declare and format a function?  I have looked at the MSDN disk, tried to do
> it like it was presented there, but am still baffled.

>   Thanks for your help!!

>   Josh DeWinter
>   Spokane, WA





Sat, 05 Jan 2002 03:00:00 GMT  
 Function question from a beginner...please help!
You need the loop to access all the objects in your array. Using a function
makes your code more readable, but slows down (this slowdown is totally
unnoticable) the execution of the app. I would put it in a function.


Quote:
> Hi.  My name's Josh.  I have a simple question involving functions that I
> was hoping someone could help me answer.

> I have some code that goes like this:

> ---START OF CODE---

> For t = 1 to 8 step 2

> text2(t).text = Form1.text(t).text

> ('and some other lines just like the one above)

> Next t

> ---END OF CODE---

>   I was thinking...rather than make this a for/next loop, could I put it
> into a function, and just pass the function the number I wanted t to
equal?
> (This would help me later on in the program, where I have to do this same
> code block again.  Currently I am using another for/next loop to do it
> again, which seems to be a waste of code).

>   My custom-made function went like this:

> ---START FUNCTION---

> Function Josh (t)

> text2(t).text = Form1.text(t).text

> End Function

> ---END FUNCTION

> ...but it didn't work.  Could someone help me out with the proper way to
> declare and format a function?  I have looked at the MSDN disk, tried to
do
> it like it was presented there, but am still baffled.

>   Thanks for your help!!

>   Josh DeWinter
>   Spokane, WA





Sun, 06 Jan 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

2. PLease help - beginner question

3. PLease help - beginner question

4. Please help! Beginner seek/find question

5. Beginner question, please help

6. Please help - beginner question

7. Please help! Beginner database question

8. Beginner-Question, please help

9. Beginner question concerning VB .dlls - Please help

10. Beginner Question...Please Help.

11. Beginner Question...Please Help.

12. Help with dll use please... (Beginners question)

 

 
Powered by phpBB® Forum Software