Qbasicnews.com
define argument types in subs - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: define argument types in subs (/thread-3186.html)

Pages: 1 2 3 4 5 6


define argument types in subs - KiZ - 02-25-2004

hmm... *goes and makes a test program*

Nope, it defitely doesnt work.

It highlights the period and says "Parameter type mismatch"

this is the test I used:
Code:
DECLARE SUB blah (i!, a!)
TYPE bler
  z AS INTEGER
END TYPE
DIM array(10) AS bler

blah i, array(x).z

SUB blah (i, a)
print "hello"
END SUB



define argument types in subs - na_th_an - 02-25-2004

Quote:hmm... *goes and makes a test program*

Nope, it defitely doesnt work.

It highlights the period and says "Parameter type mismatch"

this is the test I used:
Code:
DECLARE SUB blah (i!, a!)
TYPE bler
  z AS INTEGER
END TYPE
DIM array(10) AS bler

blah i, array(x).z

SUB blah (i, a)
print "hello"
END SUB

Of course it does not work. You are declaring your parameters as SINGLE and you are attempting to pass INTEGER parameters.

Change the code to:

Code:
DECLARE SUB blah (i%, a%)
TYPE bler
  z AS INTEGER
END TYPE
DIM array(10) AS bler

blah i%, array(x%).z

SUB blah (i%, a%)
print "hello"
END SUB



define argument types in subs - KiZ - 02-25-2004

...

duh!! I cant believe I didnt see that! Even the error was telling me what was wrong! yeesh. I am too tired to realise these things... sorry nath.


define argument types in subs - TheBigBasicQ - 02-28-2004

Dark you can pass a whole array as well:

Code:
TYPE mytype
   ab  as integer
   cd   as string * 10
END TYPE

SUB mysub(foo() as mytype, n%)
   for i% =  1 to n%
      print foo(i%).ab
      print foo(i%).cd
   next
END SUB

DIM myarr(1 to 20) as mytype

FOR m% = 1 to 20
   myarr(m%).ab = m% + 5
   myarr(m%).cd = CHR$(m% + 5)
NEXT

mysub(myarr(), 20)

Havent tested it but it should work =).


define argument types in subs - KiZ - 02-29-2004

Cool, i see how. ok, thanks.


define argument types in subs - TheBigBasicQ - 02-29-2004

Did my example work? I've to still test it =P.


define argument types in subs - relsoft - 03-01-2004

Quote:I don't comment my code, and I don't think I code sloppy (anymore)... Big Grin I only use comments where I'm approaching a difficult task and need it broken down into steps. I delete the comments afterwards. Tongue

Why do you do that? If I may ask?

:???:


define argument types in subs - TheBigBasicQ - 03-01-2004

Isnt it obvious? He doesnt want anyone to understand what he has written =P.


define argument types in subs - relsoft - 03-01-2004

Well , he can just didtribute w/o the source. :*)


define argument types in subs - TheBigBasicQ - 03-01-2004

no, he will distribut the source.