Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cross over from C to Basic

Status
Not open for further replies.

realm22

Programmer
Mar 3, 2003
7
0
0
IE
I have written code in C for years and years but am having some trouble adapting to Assess/Basic syntax.

How Do
I return data from a function?
Access data in one form from another?

Need Leason in Syntax :) Help!
 
Set the function name to the return value if using a function.
Use Exit Sub or Exit Function to exit.

Be very careful when referring to controls on one form from another. If the form you are referencing is not visible, you will get an error.

Use:
[Forms]![frmFormName]![txtMyControl] to reference the value.

You can also check the Access help files for the term "OpenArgs". This gives you a method of opening a form and passing it a value.

Good luck. The more you work with this stuff, the easier it gets.
 
Let's say you have created this function or a much more elaborate one. After you have performed the manipulation of data you have to make an assignment of the result to the name of the Function.(see Red)
Function YourFunction()
vVariable = X * Y
YourFunction = vVariable
End Function

Now in an Control Source, Event Procedure's VBA code, a query etc. you make a call to that function like this:
YourFunction()
The value of vVariable or (X * Y) will be returned. Bob Scriver
 
Many many Thanks KornGeek and scriverb
I needed the help. Seem a little more difficult learning !Basic! when you programmed in C for years.. tis a strange language

Mike

Just a note. Does this mean a function can only return 1 value.. Also I make sure that all form I reference are opened (normally hidden) but am still getting some errors (Access Can't find form etc.)
Can I alter the Table directly and update ( ? Requery ) before the user can do anything?

Thanks again

 
scriverb,
Thank you for so eloquently making the point that I was trying to make. I'm a little fuzzy-headed from too many late nights, and so my communications aren't as clear as I'd like them to be.

realm22,
A function can only return a single value, however you can modify the parameters that are passed to it, which has the effect of other returned values. (I believe this is the same in C, isn't it?)

For example:
Function MyFunkyFunction(ValA, ValB)
'This is a variation of one of the first functions I ever wrote
'It was for extra credit in a programming class.
ValA = ValA + ValB
ValB = ValA - ValB
ValA = ValA - ValB
MyFunkyFunction = ValA + ValB
End Function

The function would only return the value of ValA + ValB, but in the process, ValA and ValB would be swapped.
 
Yep… Same in C. I am so use to C that I can modify the whole world from inside a function it doesn’t seem so restricted. I suppose the beauty of passing a pointer to a structure and being able to modify the contents of the structure give the appearance of… but I suppose Basic, once you master it can do the same.

It all boils down to learning more Basic. What I need is a C to Basic compiler :)

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top