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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing Parrameters to Functions and Sub Programs

Status
Not open for further replies.

TheSorceror

Programmer
Jul 29, 2010
11
0
0
US
I Seem to be having a hell of a lot of troubles passing Variables into a Function or Sub Program Call.

For Example: (Extremely simplified).

Declare Sub MySub(Param1 as String, Param2 as String, Param3 as String)

Sub main()
Dim MyVar1 as String
Dim MyVar2 as String
Dim MyVar3 as String.
MyVar1 = "some text"
MyVar2 = "More Text"
MyVar3 = "Yet more Text"

MySub(MyVar1,MyVar2,MyVar3)
End Sub

Sub MySub(Param1 as String, Param2 as String, Param3 as String)
' do whatever with passed in params..
End Sub

When compiling the code it fails with a syntax error on the Sub call..
MySub(MyVar1,MyVar2,MyVar3)

It complains that there are too few arguements for the Sub program MySub

If i pass 1 parameter it compiles and works fine. it seems passing any more than 1 parameter causes it to fail.

Easy enough to work around though by declaring the Variables as Global Variables outside of Main But this is really Messy programming.

Any ideas or is this a limitation of Extra! Basic???

Funnily enough i do have a function(sub) call that does pass in 4 parameters and that works.

Her is the one that works.

Declare Function GetScreenID(yStart,xStart ,yEnd ,xEnd)

Sub Main ()
Dim ScreenName
ScreenName = GetScreenID(1,35,1,36)
End Sub

Function GetScreenID( yStart,xStart,yEnd,xEnd)

'MsgBox "entering GetScreenID Function"
Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object

'reset Sess & MyScreen variables for current screen and tell us where we are.
Set Sys = CreateObject("EXTRA.System")
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen
Set MyArea = MyScreen.Area(yStart,xStart,yEnd,xEnd , ,)
MyArea.Select
MyArea.Copy
GetScreenID = MyArea.Value
End Function

Wierd hey?? it returns the text found at the co-ordinates passed into the function. Which is what it is meant to do..

So why can i pass in 4 variables into this function call but not any others??? And it does not matter if it is a Function or a Sub. The same error occurs regardless.

Any help appreciated.

Al
 


Code:
'call MySub NO PARENTHESES
  MySub MyVar1,MyVar2,MyVar3
'...

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks Skip, I will give that a try. If it works it will save me having to use Global variables.

I will Have to rewrite some lines of code to accomodate the changes. At the moment the macro has over 500 Lines of Code and is growing as i add features. but at least for the most part it does actually Work.
 
just a side note, you might want to specify how you are refrencing your vairables, ie byRef/byVal

I use vb.net but the concept is still the same
Code:
'calling my sub in code, no need for call in .net
SignInClaims(Sess0, TPX, UserID, Password)

Declaration line for the SignInClaims Sub is:
Code:
Private Sub SignInClaims(ByVal Sess0 As Object, ByVal TPX As String, ByVal UserID As String, ByVal Password As String)
'code
End Sub

Additionally, it looks like some of the session stuff you are doing is over-complicated. If you want I would be more than happy to provide some examples of screen scraping functions that could be easily adapted to fit your project. Post back and let me know how you are doing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top