Results 1 to 19 of 19

Thread: Call Call Call Call Call Call Call Call Call Call

  1. #1

    Thread Starter
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Question

    Why using Call when its not necessary?
    Code:
    'DoSomething is a sub
    'Why this:
    call DoSomething
    'or this:
    DoSomething
    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    Why :
    Code:
    'Why this
    Dim hello as String
    'or
    Dim hello$
    I think it's just a matter of preferences!

  3. #3
    Guest
    IS the same like, why using a pencil. if you can use a pen.

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I think it's sometimes easier to see you're calling an outside function (hmm.. that's what I use it for ) and not just VB code, but as sebs said, it's just a matter of preferences.

    and sebs, I use Dim str$ because it's shorter and I think it looks cool


    Why use a pencil if you can use a pen
    'Cause you can make changes when you've done something wrong
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Lively Member
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    96
    It aids readability.

    Have you ever tried to debug/test/update/evaluate someone elses code....

    nightmare.

    These little niceties help loads

    H.
    Just trying to muddle through...

  6. #6
    Member
    Join Date
    Oct 2000
    Posts
    39
    hmm, dont you need to use the call feature if using api.
    I tried to do some functions w.out calling anything and it didnt work. Instead I used the Call and it worked fine.

    I wasnt actually calling the function on the form, but writing an if then statement w. api calls.


  7. #7
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    I agree with Jop!
    Chemically Formulated As:
    Dr. Nitro

  8. #8
    Addicted Member Ramandeep's Avatar
    Join Date
    Feb 2000
    Posts
    158
    I agree with Jop & Hollie, it's just easer for another programmer (if your working in a team) to see that you are calling a sub or function and makes his life a bit simpler etc...

    Don't forget is you use call you must inclose arguments in brackets "()"

  9. #9
    Guest
    I also agree with Hollie on the readability issue.

    One of my more miserable tasks at work is maintaining other peoples code when it is unreadable and difficult to follow. Believe it or not some people don't even indent! I'm begging all you coders to put in comments so I know what you were thinking when you wrote the stuff. I do it and find it actually helps me nut out tricky algorithms

  10. #10
    Guest
    Basically, Call makes your source code more organized. When you use call, you enclose your arguments in brackets.
    Code:
    Call MyFunc(Arg1, 0, 0, 0, 0, &H54)
    If you omit the Call keyword, you cannot enclose it in brackets, which in some people's opinion is sloppy coding.
    Code:
    MyFunc Arg1, 0, 0, 0, 0, &H54

  11. #11
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    Call uses less memory when calling a function if you don't need the return value (in the case of the api). This is because you don't need to allocate a variable to store the data, as Call discards it.

    I'm actually pretty good at reading others' code. I indent all code before trying to figure out what it does. If you have a piece of code that is absolutly unreadable, I can usually decipher it. I decipher other people's code when I get bored with what ever project I'm working on.

  12. #12
    Lively Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    82
    I remember that in earlier versions of VB, before Option Explicit, I was never sure that a statement DoSomething was a call to a Sub or just an undeclared variable; whereas Call DoSomething is totally unambiguous.

    Adrian.

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    agent - all the API functions return a value for a good reason. Technically, you should always check for an error code, though very few do.

    My personal preferences:
    Code:
    Dim x As String
    
    x = MyFunc(10, 10)
    MySub 10, 10
    I just don't like seeing Call around, since I've always been used to minimising code length for the sake of readability.

    Adrian brought up a good point about Option Explicit. Does anyone here always use it? (I do)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14
    Lively Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    82

    Option Explicit

    Best thing since sliced bread for me. I'm a classic for mis-typing variables. DOH!

    Adrian.

  15. #15
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362

    i'm with parksie

    minimalist code makes for elegance.


    td
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Not always, though. Quick C++ example (good for minimising code size):
    Code:
    if(i) {
        y = 10;
    } else {
        y = 20;
    }
    ...can be condensed to:
    Code:
    y = i ? 10 : 20;
    But that doesn't make it any more readable .
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  17. #17
    Guest
    In my opinion, the Call statement makes code easier to understand.

    Call MyFunc(1,2,3,4,5)

    rather than:

    MyFunc 1,2,3,4,5

    Makes it easier to read and understand.
    But both ways work the same.

  18. #18
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132
    Hi all !!!

    I agree with your statements about readable code from
    another coder but in all your examples I'am missing that each function or sub call can also be written with named parameter for better reading e.g.

    iRet = fktMyfunction (Para1:=1,Para2:=3)
    DoSomething Para1:=1,Para2:=3

    so in my opinion you didn't need the CALL Statement if you use the naming convention and named parameters.

    -cu TheOnly


  19. #19
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    the trouble with that is that if the reader is unfarmiiar with the calling convention he/she may wonder what iRet is, it's definetley nowhere near as obvious as a big blue call sign, also it probably doesn't matter in most vb apps but if you are going to use a return value you have to declare it which makes the code a little slower, and if you want it to accept more than one data type you have to make it a variant or go throgh conversions, which can slow the code down quite considerably and even cause errors, if you ever need to look at iRet you should really give it a different name so the reader knows what it is. Although it's only a little sloppy as coding practices go if you're writing a time critical or recursive function iRet shouldn't be used. which can mean 2 seperate coding conventions in the same module. unless there is a serious advantage of iRet in your code there's no point using it and it is harmful. So Call is definatley the better option there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width