• Print

Author Topic: Array in sub (resolved)  (Read 505 times)

659_minifly

  • Full Member
  • ***
  • Posts: 120
Array in sub (resolved)
« on: December 02, 2010, 02:38:54 AM »
hello i am new in programming with QB64.
i am trying to call a sub with array for parameters and i have an error
and i would like to know if it is possible to do it?
ex :
k=1
Form Tbl_NC(k),Tbl_NL(k),Tbl_LG(k),Tbl_HT(k),Tbl_EC(k),Tbl_EL(k),Tbl_OX(k),Tbl_OY(k)
Thanks by advance.

Resolved
i fact after reading wiki i found that is not necessary to use parameters if we declared them as shared.
ok i am sorry thank
« Last Edit: December 02, 2010, 03:18:03 AM by 659_minifly »

DarthWho

  • Hero Member
  • *****
  • Posts: 3853
  • Timelord of the Sith
Re: Array in sub (resolved)
« Reply #1 on: December 02, 2010, 05:05:13 AM »
conversely you could call the sub like this:
Form (Tbl_NC(),Tbl_NL(),Tbl_LG(),Tbl_HT(),Tbl_EC(),Tbl_EL(),Tbl_OX(),Tbl_OY(),k)
if the sub uses arrays itself with K acting as the variable that decides the values actually used or if the sub does not this should work:

Call  Form (Tbl_NC(k),Tbl_NL(k),Tbl_LG(k),Tbl_HT(k),Tbl_EC(k),Tbl_EL(k),Tbl_OX(k),Tbl_OY(k))
Rassilon: My lord Doctor; My lord Master; My lord DarthWho
The Doctor and the master at the same time :WHAT!?!?!

FastMath 1.1.0 released: http://dl.dropbox.com/u/12359848/fastmath.h

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Array in sub (resolved)
« Reply #2 on: December 02, 2010, 10:30:24 AM »
In fact, since the arrays are all of the same TYPE, you could make it into a multi-dimensional array perhaps. Instead of using different names, use different element numbers.
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

659_minifly

  • Full Member
  • ***
  • Posts: 120
Re: Array in sub (resolved)
« Reply #3 on: December 02, 2010, 10:31:07 AM »
Thank you for your reply.It is a good information, i could not to find out by myself.

659_minifly

  • Full Member
  • ***
  • Posts: 120
Re: Array in sub (resolved)
« Reply #4 on: December 02, 2010, 10:40:54 AM »
@Clippy
In fact i could, but for a better hunderstanding for my self ,i prefer having some littles tables instead a big one.
 I will post the program i'm doing when it will be finish ( hope one day).
thank for your answer by the way.

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Array in sub (resolved)
« Reply #5 on: December 02, 2010, 10:49:35 AM »
No problem. Perhaps you can use that solution another day.
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

codeguy

  • Hero Member
  • *****
  • Posts: 3552
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Array in sub (resolved)
« Reply #6 on: December 02, 2010, 12:39:03 PM »
TYPE Table
    whatever AS SINGLE
    someotherelement AS STRING * 12
    result AS LONG
END TYPE

DIM Tbl(255, 99) AS Table
FOR TableNum& = 0 TO 255
    FOR whatnum% = 0 TO 99
        WorkWithThisTable Tbl(), TableNum&, whatnum%
    NEXT
NEXT

SUB WorkWithThisTable (R() AS Table, TableIndex, Tnum%)
R(TableIndex, Tnum%).result = R(TableIndex, Tnum%).whatever * VAL(R(TableIndex, Tnum%).someotherelement)
END SUB

here's my submission for what it'll help ya!

or ya could even do this:

TYPE Table
    whatever AS SINGLE
    someotherelement AS STRING * 12
    result AS LONG
END TYPE

DIM Tbl(255, 99) AS Table
FOR TableNum& = 0 TO 255
    FOR whatnum% = 0 TO 99
        WorkWithThisTable Tbl(TableNum&, whatnum%)
    NEXT
NEXT

SUB WorkWithThisTable (R AS Table)
R.result = R.whatever * VAL(R.someotherelement)
END SUB
as they say in programming, whatever floats your boat ;D
« Last Edit: December 02, 2010, 12:50:57 PM by codeguy »
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

659_minifly

  • Full Member
  • ***
  • Posts: 120
Re: Array in sub (resolved)
« Reply #7 on: December 02, 2010, 02:02:40 PM »
i thaught it was not possible to work with table in type definition.
It is a very good way to turn around this problem.
great.
thanks

codeguy

  • Hero Member
  • *****
  • Posts: 3552
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Array in sub (resolved)
« Reply #8 on: December 02, 2010, 02:08:06 PM »
qb64 enables us to do some pretty fantastic stuff code-wise that would make qbxx choke. i find a lot of these kinds of things very handy. i'm a huge (539N) fan of type variables as they make coding far easier to follow when used correctly.
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

659_minifly

  • Full Member
  • ***
  • Posts: 120
Re: Array in sub (resolved)
« Reply #9 on: December 02, 2010, 02:24:02 PM »
i do not have the expertise and the background to do that.
But for the programmeur how like it that make shorter development.
for me a = a+1 is ok ;D ;D

codeguy

  • Hero Member
  • *****
  • Posts: 3552
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Array in sub (resolved)
« Reply #10 on: December 02, 2010, 02:37:54 PM »
TYPE Table
    NC AS INTEGER
    NL AS INTEGER
    LG AS INTEGER
    ht AS INTEGER
    ec AS INTEGER
    el AS INTEGER
    ox AS INTEGER
    oy AS INTEGER
END TYPE

DIM MyStuff(0 TO 255) AS Table

FOR k = 0 TO 255
    Form2 MyStuff(), k
    form Tbl_NC(), Tbl_NL(), Tbl_LG(), Tbl_HT(), Tbl_EC(), Tbl_EL(), Tbl_OX(), Tbl_OY(), k
NEXT

SUB form (T_NC(), T_NL(), T_LG(), T_HT(), T_EC(), T_EL(), T_OX(), T_OY(), k)
T_NC(k) = foo
T_NL(k) = bird
T_LG(k) = ifthefoocraps
T_HT(k) = wearit
END SUB

SUB Form2 (PassedStuff() AS Table, whichone)
PassedStuff(whichone).NC = foo
PassedStuff(whichone).NL = bird
PassedStuff(whichone).LG = ifthefoocraps
PassedStuff(whichone).ht = wearit
PassedStuff(whichone).ec = yes
PassedStuff(whichone).el = this
PassedStuff(whichone).ox = isthesameas
PassedStuff(whichone).oy = theotherway
END SUB
« Last Edit: December 02, 2010, 02:55:02 PM by codeguy »
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

659_minifly

  • Full Member
  • ***
  • Posts: 120
Re: Array in sub (resolved)
« Reply #11 on: December 02, 2010, 02:57:02 PM »
i am looking for:
i have one grid on the windows and i would like to move it with the curseur
what should do
1 record the background  into memory
2 draw the form into memory
3 draw  the form from memory on the background
4 move the form on the background ( like a sprite)
5 redraw the background
6 redraw the form on the new place

is that the correct way to do it ?
or there is a better way to do it ?
what do you think about it

codeguy

  • Hero Member
  • *****
  • Posts: 3552
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Array in sub (resolved)
« Reply #12 on: December 02, 2010, 03:04:06 PM »
not the only way, but this is how i'd do it.
draw background. store in memory
draw form. store in memory
do
cls
draw background from image stored in memory
move form or forms if ya got a bunch
_display
_limit 30
loop until itstimetostop
free all your images
system
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

659_minifly

  • Full Member
  • ***
  • Posts: 120
Re: Array in sub (resolved)
« Reply #13 on: December 02, 2010, 03:10:45 PM »
ok
why do you put a timer ?

Sorry my question is stupid.
Excuse me to spend your time with me you certainly have more interesting things to do.


codeguy

  • Hero Member
  • *****
  • Posts: 3552
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Array in sub (resolved)
« Reply #14 on: December 02, 2010, 03:33:35 PM »
_limit xx
just keeps the cpu usage reasonable. it is not actually meant to be a timer, so much as a "throttle," which helps to keep your programs from slowing the rest of the sytem. make sure to activate task manager and you'll be able to see how this affects overall cpu usage.
take for example this program:
Code: [Select]
h& = _SCREENIMAGE
sw% = _WIDTH(h&)
sh% = _HEIGHT(h&)

SCREEN h&
CLS
DIM SHARED count&
recurse 0, 0, sw% + 1, sh% + 1, 0
SUB recurse (x1, y1, x2, y2, level)

count& = count& + 1
IF x2 - 1 > x1 + 1 THEN
    IF y2 - 1 > y1 + 1 THEN
        LINE (x1, y1)-(x2, y2), _RGB(63 * level, 15 * level, count&), BF
        mx = x1 + (x2 - x1) \ 2
        my = y1 + (y2 - y1) \ 2
        recurse x1, y1, mx, my, level + 1
        recurse mx, my, x2, y2, level + 1
        recurse x1, y1, mx, y2, level + 1
        recurse mx, y1, x2, y2, level + 1
    END IF
ELSE
    IF y2 > y1 THEN
        'mx = x1 + (x2 - x1) \ 2
        my = y1 + (y2 - y1) \ 2
        recurse x1, y1, x2, my, level + 1
        recurse x1, my + 1, x2, y2, level + 1
    END IF
END IF
_LIMIT 2 ^ 17
level = level - 1
END SUB
then this one
Code: [Select]
h& = _SCREENIMAGE
sw% = _WIDTH(h&)
sh% = _HEIGHT(h&)

SCREEN h&
CLS
DIM SHARED count&
recurse 0, 0, sw% + 1, sh% + 1, 0
SUB recurse (x1, y1, x2, y2, level)

count& = count& + 1
IF x2 - 1 > x1 + 1 THEN
    IF y2 - 1 > y1 + 1 THEN
        LINE (x1, y1)-(x2, y2), _RGB(63 * level, 15 * level, count&), BF
        mx = x1 + (x2 - x1) \ 2
        my = y1 + (y2 - y1) \ 2
        recurse x1, y1, mx, my, level + 1
        recurse mx, my, x2, y2, level + 1
        recurse x1, y1, mx, y2, level + 1
        recurse mx, y1, x2, y2, level + 1
    END IF
ELSE
    IF y2 > y1 THEN
        'mx = x1 + (x2 - x1) \ 2
        my = y1 + (y2 - y1) \ 2
        recurse x1, y1, x2, my, level + 1
        recurse x1, my + 1, x2, y2, level + 1
    END IF
END IF
'_LIMIT 2 ^ 17
level = level - 1
END SUB
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

  • Print