Functions and Procedures for dyslexics

Camerart

Member
Hi,
I'm trying to understand Procedures and Functions (Using Oshonsoft BASIC)
Here is the example for Procedures:

Code:
Dim in_only As Byte
Dim inc_me As Byte
Dim add_inc_me_and_in_only As Byte

in_only = 5
inc_me = 10
Call testbyref(in_only, inc_me, add_inc_me_and_in_only)
'after this call
'inc_me = 11
'add_inc_me_and_in_only = 16
End                                               

Proc testbyref(arg1 As Byte, ByRef arg2 As Byte, ByRefOut arg3 As Byte)
arg2 = arg2 + 1
arg3 = arg1 + arg2
End Proc

This is written in such a way, using 'silly words' that makes it very difficult to follow. Can someone re-write it using more normal words, so it flows better please?

Cheers, Camerart.
 

Darren

Moderator
Staff member
Not really sure what you're after. The variable names are kinda confusing but this is a pretty simple procedure call. I'd just change them to A, B, and C. Did it with a simple find and replace.


Code:
Dim a As Byte
Dim b As Byte
Dim c As Byte


a = 5
b = 10
Call testbyref(a, b, c)
'after this call
'b = 11
'c = 16
End                                            


Proc testbyref(arg1 As Byte, ByRef arg2 As Byte, ByRefOut arg3 As Byte)
arg2 = arg2 + 1
arg3 = arg1 + arg2
End Proc

Basically it's passing A, B, to the function and calculating C.

Arg2 is calculated with arg2 (which is b=10) plus 1. So arg2 = 10 + 1 = 11
Arg3 is calculated by arg1 (which is a=5) plus arg 2 (which is 11). So Arg3 = 5 + 11 = 16

The comments (denoted with ' before the line) show that B = 11 and C = 16 after the function, which matches with arg2 = B and Arg3 = C, that you calculated in the function.

Disclaimer, I haven't really touched programming in 4+ years but this is pretty basic BASIC.
 
Last edited:

Camerart

Member
Hi D,
I also tried changing the variables to suit, but after 1/2 hour had a bag of spaghetti. Two minutes after you reply, we had this:

I wasn't allowed to change [ ByRefOut ], what does it relate to.

This may be basic BASIC to you, but I've only been programming since the 80s, so give me chance :)

Thanks, it's now possible for me to go through it.
Cheers, C.
 

Attachments

  • test.jpg
    test.jpg
    99.9 KB · Views: 3

Camerart

Member
Hi,
Hi D,
I also tried changing the variables to suit, but after 1/2 hour had a bag of spaghetti. Two minutes after you reply, we had this:

I wasn't allowed to change [ ByRefOut ], what does it relate to.

This may be basic BASIC to you, but I've only been programming since the 80s, so give me chance :)

Thanks, it's now possible for me to go through it.
Cheers, C.
I just searched for [ ByRef ] and to my surprise it means something.
Examples in help docs, are supposed to help those that are learning, why add something like [ ByRef ] and got give a link to learn about it?
Anyway, I understand that it doesn't have to be there,( I don't think??)
C
 

Camerart

Member
Hi again D,
I carried on experimenting, and tried removing [ ByRef ] Here's the result:

C.
 

Attachments

  • PROC TEST 1_2.jpg
    PROC TEST 1_2.jpg
    171.2 KB · Views: 1

Darren

Moderator
Staff member
I can't really help you with what seem like homework questions. What are you reading from or trying to do?

Honestly just start googling stuff, there's jillions of programming resources out there. I'm rusty and got away from programming during college and shifted towards more IT/operations than programming/coding. Think only a couple of us around here really do/did much coding.

ByRef I'm guessing is referring to passing values by reference rather than by actual value itself. I forget specifics, you just need to do some reading it sounds like.
 

Camerart

Member
I can't really help you with what seem like homework questions. What are you reading from or trying to do?

Honestly just start googling stuff, there's jillions of programming resources out there. I'm rusty and got away from programming during college and shifted towards more IT/operations than programming/coding. Think only a couple of us around here really do/did much coding.

ByRef I'm guessing is referring to passing values by reference rather than by actual value itself. I forget specifics, you just need to do some reading it sounds like.
Hi D,
That's fine!
Your re-writing the variables, opened the door blocking me, and regarding [ ByRef ] I'll try to ignore it, and see if things work, but if I get odd results, then at least I know where the problem may be.

Cheers, C.
 
Top