Weekly Qbasic and Qb64 Lesson Topics
April 19, 2024, 04:02:35 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

welcome

Pages: [1] 2
  Print  
Author Topic: welcome  (Read 849 times)
659_minifly
Guest
« on: June 02, 2011, 12:54:29 pm »

Thanks Oldoslover for your welcome
I found the site very interesting.
It is "every thing you want to know and you never ask".
I have things who are in the dark for me and is that the correct place to ask it ?
those things are not hard ( not x rd).
exemple :
in a sub for declaring it . what are the differents way to do it

sub redraw (x,y) or sub redraw ((x),(y)) and to call it
redraw (x,y) or redraw ((x),(y)) or redraw 10,10 or redraw x,y or call redraw(x,y) and what are the difference.
thanks for existing.
Report Spam   Logged

Share on Facebook Share on Twitter

OlDosLover
Guest
« Reply #1 on: June 02, 2011, 05:33:07 pm »

Hi all,
    Welcome to the forum 659_minifly. Thank you for the description.
Quote
It is "every thing you want to know and you never ask".
This is exactly the sort of thing we are trying to achieve here. Here we want to share code and the spirit of coding regardless of your expertise. After all we were all once ,newcomers. Please feel free to contribute any way you see fit. There are no "authority's" on this site that are considered as "GODS".
OlDosLover.
Report Spam   Logged
OlDosLover
Guest
« Reply #2 on: June 02, 2011, 06:35:01 pm »

Hi all,
Quote
in a sub for declaring it . what are the differents way to do it

sub redraw (x,y) or sub redraw ((x),(y)) and to call it
redraw (x,y) or redraw ((x),(y)) or redraw 10,10 or redraw x,y or call redraw(x,y) and what are the difference.
    Well this confused me greatly for many years. Why have two different bloody ways to do it and why?

In QB45
A Sub Routine must be declared.(appears as DECLARE SUBxxxxx at top of program)
If you use the word CALL the parameter list must be enclosed with brackets
If you DONOT use the word CALL the parameter list must NOT be enclosed with brackets.
e.g.
CALL Redraw(x,y)
Redraw x,y

In QB64
A SubRoutine is named not declared.
SUB SaveImage (image AS LONG, filename AS STRING)
  ...
  .(Galleons save screen as bmp routine)
  ...
END SUB
To call it:(the screen handle must exist)
SaveImage ScreenHandle&,MyScreenshot.bmp

SUB Redraw (x as INTEGER,y as INTEGER)
  ...
END SUB
To call it:
Redraw x,y

OlDosLover.
« Last Edit: June 02, 2011, 06:39:47 pm by OlDosLover » Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #3 on: June 02, 2011, 06:53:22 pm »

Welcome, 659_minifly,
 Is this what you are wanting to know about ?

Quote
in a sub for declaring it . what are the differents way to do it

sub redraw (x,y) or sub redraw ((x),(y)) and to call it
redraw (x,y) or redraw ((x),(y)) or redraw 10,10 or redraw x,y or call redraw(x,y) and what are the difference.
Or was it just a example ? Any way welcome,...sorry I don't know much on subs or declareing them yet either,....There may already be something in some of the tutorials Olddoslover has posted, if not he may be able to help you,
 I am still struggleing with some of the most basic stuff, in _putimage, _loadimage,...But yea don't worry, even if it is a question as basic as , Where do I start, how can I display "hello world" ?........
  Sometimes it may be helpful, if you have some code that works (for example),
but want to add a sub and declare it,...Post what code you have so far, and/ or a description as to what you are trying to accomplish.
 If you are unsure as to where the best place to post is, just go ahead and post here, in the general discussion,..then once we see whats on your mind, if it seems like it would be better in a different place, or special topic, there is no problem, moveing stuff around,....
 Guess thats about it,..enjoy, and welcome,....
from Garry
Report Spam   Logged

659_minifly
Guest
« Reply #4 on: June 03, 2011, 12:20:09 am »

Thanks oldos


in the wiki we have :

Variable names within the procedure do not have to match the names used in the CALL, just the value types.

Does that mean :

sub definition:

sub translate (x,y)

def....

end sub

and to use it

1) translate x,y ' That one is direct

Disx=x+10
DisY=Y+50

2) translate DisX,DisY :Rem name of the variable have change

The name of the variable can be change. when we use the sub ?




Report Spam   Logged
OlDosLover
Guest
« Reply #5 on: June 03, 2011, 12:29:15 am »

Hi all,
   
Quote
Variable names within the procedure do not have to match the names used in the CALL, just the value types.
Real clear and makes great sense dont it! NO!. Lol. Try this example
Code:
REM
DEFLNG A-Z
SCREEN 12

Cash% = 100: Items% = 5: Value% = 0


Spend Cash%, Items%, Value%
PRINT "You can buy "; Value%; " presents!"
Dummy$ = INPUT$(1)
SLEEP
SYSTEM

'------------- subprocedures
SUB Spend (Money AS INTEGER, Object AS INTEGER, Price AS INTEGER)
Cost% = Money% \ Object%
Price% = Cost%
END SUB

As you can see the names that i use to pass the integers are different to the names used inside the subroutine. I believe this is what that statement means. Note i have to assign Price to equal the result to pass back.

It seems it should say that the Call Name should be the same but the parameter names passed could be different from the parameter names used inside the sub as long as the parameter TYPES are the same.

OlDosLover.
« Last Edit: June 03, 2011, 12:56:43 am by OlDosLover » Report Spam   Logged
OlDosLover
Guest
« Reply #6 on: June 03, 2011, 12:48:52 am »

Hi all,
    659_minifly could you post the link to that statement in the wiki please.
Quote
Variable names within the procedure do not have to match the names used in the CALL, just the value types.
Questions and queries can also be done by Personal Mesaging by clicking on the member names PM bubble.
OlDosLover.
Report Spam   Logged
659_minifly
Guest
« Reply #7 on: June 03, 2011, 03:19:35 am »

Thanks you Old that clearing one point.
In fact at first that i was thinking but in my program it was not working. My variables was not corrects. So i have to do :
x=x+10. It is possible i had other problems.
i declare allthe sub.
Declare sub (x as integer,y as integer)

sub (x as integer,y as integer)

bla bla bla

end sub

could it be my problem ?

you can see it in grid sample in qb64 sample.

Report Spam   Logged
OlDosLover
Guest
« Reply #8 on: June 03, 2011, 03:50:11 am »

Hi all,
    I'll have a look and get back to you.
OlDosLover.
Report Spam   Logged
OlDosLover
Guest
« Reply #9 on: June 04, 2011, 07:10:33 pm »

Hi all,
    minifly could you quote the part of the code that you are asking about please. I dont understand the question that you ask!
OlDosLover.
« Last Edit: June 04, 2011, 07:20:55 pm by OlDosLover » Report Spam   Logged
659_minifly
Guest
« Reply #10 on: June 04, 2011, 09:28:27 pm »

Hi oldos


yes
In the line where we found

"B_num  = Previous_Bnum"
I have to pass the variable Previous_Bnum into B_num

because the call to the sub with Previous_Bnum wasn't working

Draw_editbox Previous_Bnum,X_deb+2,Y_deb+2,X_fin-3,Y_Fin-2

That why my question "do we need to use the original variable use in the sub declaration" ?.



Code:
 sub Focus_editBox(B_Num As Integer)


 Save_bnum=B_num

    if   Flag_Focus=0  then
                       Flag_Focus=1
             Draw_editbox B_num,X_deb+2,Y_deb+2,X_fin-3,Y_Fin-2
               choice_key B_num
    end if

       if   Flag_Focus=1 and Previous_Bnum<>0 then
                               Flag_Focus=0
                               B_num  = Previous_Bnum
                               Bnum_Coord B_Num
             Draw_editbox, B_num,X_deb+2,Y_deb+2,X_fin-3,Y_Fin-2
       end if
              Previous_Bnum=Save_bnum
              Flag_Focus=0

  End Sub

And i also did that modification on other SUB.

But when we know that doens't bother me anymore

I thank you for your help.





« Last Edit: June 04, 2011, 09:32:24 pm by 659_minifly » Report Spam   Logged
OlDosLover
Guest
« Reply #11 on: June 04, 2011, 09:47:20 pm »

Hi all,
Quote
sub Focus_editBox(B_Num As Integer)
    At the moment the ONLY variable passed is B_Num%. Inside the sub you reference other variables. Unless any of those referenced variables inside the sub are (declared) GLOBAL they automatically become LOCAL. LOCAL = only seen by this sub and they disappear after exit of sub.
    To preserve a value of a variable inside a sub make it one of these
1] STATIC
2] GLOBAL
3] Pass it back like this sub Focus_editBox(B_Num As Integer,Previous_Bnum AS INTEGER)

   If you decide on 3] then you send an empty variable Previous_Bnum to the SUB and record its value once you exit the sub and return to the main.
OlDosLover.

Report Spam   Logged
OlDosLover
Guest
« Reply #12 on: June 04, 2011, 10:01:16 pm »

Hi all,
    Here's an example program that shows the difference between 2 SUBs that DO and DONT know about AOUT. Press SPACEBAR and then ENTER to see the differences.
Code:
REM
DEFINT A-Z

SCREEN 12
AINN = 5: AOUT = 9
DO
  _LIMIT 30
  PRINT AINN, AOUT
  IF _KEYDOWN(32) THEN ' spacebar key
    Flow1 AINN, AOUT
    PRINT AIN, AOUT
    _DELAY 1
  END IF
  IF _KEYDOWN(13) THEN 'enter key
    Flow2 AINN
    PRINT AIN, AOUT
    _DELAY 1
  END IF

  _DISPLAY
LOOP UNTIL _KEYDOWN(27) 'escape key to exit
SLEEP
SYSTEM

SUB Flow1 (AINN AS INTEGER, AOUT AS INTEGER)
AINN = AINN * 2
AOUT = AOUT * 2
END SUB

SUB Flow2 (AINN AS INTEGER)
AINN = AINN * 2
AOUT = AOUT * 2
END SUB

    Everytime you press spacebar BOTH figures DOUBLE. When you press ENTER then ONLY AINN doubles!
OlDosLover.
Report Spam   Logged
659_minifly
Guest
« Reply #13 on: June 04, 2011, 10:18:44 pm »

Hi oldos

I declared them in the header file

DiM SHARED          B_num                                      As Integer
DiM SHARED          Previous_Bnum                           As Integer
DIM SHARED          Save_bnum                               As INTEGER

That was not correct ?
Report Spam   Logged
OlDosLover
Guest
« Reply #14 on: June 04, 2011, 10:35:17 pm »

Hi all,
    If they are shared then it should work correctly. Id suggest that you have a logic problem or other that is not creating the condition you think should happen. Id try this

Modify your program to test the section not working correctly. Place a _DELAY 1 at the place of the call and print out B_num ,Previous_Bnum and see what values are before going in. Do the same with a delay at the end of the sub. Place a _DELAY 1 at the end of the sub and print out B_num ,Previous_Bnum and compare the two sets of values.
OlDosLover.
Report Spam   Logged

Pages: [1] 2
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy