Board Logo
« Search Results »

Welcome Guest. Please Login or Register.
Nov 20th, 2017, 6:47pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ


Search Results

Total results: 10


 1   Novice / Re: Random number generator  on: Today at 2:45pm
Started by SilverSurfer | Post by tsh73
Quote:
Secondly, how do I stop it from creating numbers with up to 8 decimal places?


Function to round to any number of decimal places
Code:
for n = -5 to 5
print "Rounds to ";(n);" decimal places"
for i = 1 to 4
    rand=rnd(0)*1e6
    x = round(rand, n)
    print rand, x, using ( "#########.######", x)  'without USING you'll have only 7 digits printed
next
next

function round(x, n)    'rounds x to n-th digith (involves 1/10^n, obviously
    round=int(x*10^n+.5)/10^n  '+0.5 for rounding to nearest
end function

 

 
  Reply Quote Notify of replies

 2   Novice / Re: Random number generator  on: Today at 11:28am
Started by SilverSurfer | Post by bplus
Code:
function rand(lo, hi)
    rand = int((hi - lo + 1) * rnd(0)) + lo
end function 


This function will return an integer between lo and hi inclusive.

So 6 between 1 and 59 is (with the above function listed below the main code):

Code:
for i = 1 to 6
   print rand(1, 59)
next 


Of course it is no problem to modify this for fixed decimals as well.

Welcome to the forum!
 
  Reply Quote Notify of replies

 3   Novice / Random number generator  on: Today at 09:19am
Started by SilverSurfer | Post by SilverSurfer
Hello all,

Now retired after 40 years in the I.T. industry and without ever having been involved with programming, Iíve decided to try and learn how to do it. I chose Just Basic because it seemed perfect for someone like me. Iíve had some success with very simple programs Iíve done, however, Iíve now encountered a problem I cannot resolve. Your help please.

It concerns the Random Number Generator. I have two questions about its use. Firstly, can I get it to create more than 1 number each time I run it, Iíd like it to generate 6 random numbers between 1 and 59. Secondly, how do I stop it from creating numbers with up to 8 decimal places?

 
  Reply Quote Notify of replies

 4   Novice / Re: Window in Window  on: Yesterday at 1:17pm
Started by Bonemaster | Post by Bonemaster
Thank you, all. I am getting things working. My project is alive and well! thank you all so much... i couldn't be happier!
 
  Reply Quote Notify of replies

 5   Novice / Re: Window in Window  on: Yesterday at 06:59am
Started by Bonemaster | Post by tsh73
Quote:
he button creation code must be set just before the open window command so setting it once at the head of the program and then later opening and closing windows wont cut it.

That is, just move
Code:
button #One.buttonTwo, "BoxTwo", [Two], UL, 25, 250, 100, 25 

after
Code:
[One] 

label.
 
  Reply Quote Notify of replies

 6   Novice / Re: Window in Window  on: Yesterday at 03:13am
Started by Bonemaster | Post by Rod
Using multiple Windows might not be the best solution to your problem. You can show and hide controls in a single window for example.

If you are using multiple windows you have to open them in strict order and close them in strict order. The button creation code must be set just before the open window command so setting it once at the head of the program and then later opening and closing windows wont cut it.

There are demos on the LBPE and the sample files have multiwin.bas But be sure you really need multiple windows, it just makes coding twice as hard.

http://lbpe.wikispaces.com/Managing+Multiple+Windows
 
  Reply Quote Notify of replies

 7   Novice / Re: Window in Window  on: Nov 18th, 2017, 11:08pm
Started by Bonemaster | Post by bplus
OK I did get this to work in JB 2.0

Code:
[start]
nomainwin

WindowWidth = 800
WindowHeight = 500
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)

button #One.buttonTwo, "BoxTwo", [Two], UL, 25, 250, 100, 25
button #main.buttonOne, "BoxOne", [One], UL, 22, 301, 100, 25

loadbmp "BMP1", "bmp\Button01.bmp"
menu #main, "Options", "&quit", [quit]

OPEN "This Box One" FOR GRAPHICS_NSB_FS as #main
print #main, "font ms_sans_serif 0 16"
print #main, "trapclose [quit]"

print #main, "background BMP1"
print #main, "drawsprites"

wait


[One]
loadbmp "BMP2", "bmp\Button02.bmp" 'The RED window in upper left corner
OPEN "BoxOne" FOR graphics AS #One
PRINT #One, "trapclose [quitOne]"

print #One, "drawbmp BMP2 10 10"

#One, "flush"
wait
[quitOne]
CLOSE #One

WAIT

[Two]
loadbmp "BMP3", "bmp\Button03.bmp"
OPEN "BoxTwo" FOR graphics AS #Two
Print #Two, "trapclose [quitTwo]"

print #Two, "drawbmp BMP3 100 100"

#Two, "flush"

WAIT
[quitTwo]
CLOSE #Two

WAIT



[quit]

CLOSE #main

end
 


Oh, I see I can go back and forth from 2nd and 3rd windows but going from 1 to 2 a second time, that is when the button on #2 to go to #3 does not appear.
 
  Reply Quote Notify of replies

 8   Novice / Re: Window in Window  on: Nov 18th, 2017, 10:54pm
Started by Bonemaster | Post by bplus
Man if this your first code post congratulations! it is way, way more advanced than my first.

In the future you should put your code in code tags so it reads and copies from a code box. Look for the # button in the forum editor, it is in the 2nd row 5th from the right. Click it first and paste your code between <code> and </code> or select all your code and click the # button.

I am having problems accessing bmp files I can use to substitute for what you may be using, I assume any bmp would do.

I am sure someone more qualified with multi-windows will see right away why buttons are not showing when close a window. Having the code is great help! My guess is you would need some sort of refresh when a window on top is closed, perhaps a flush for each window after they are drawn?

 
  Reply Quote Notify of replies

 9   Novice / Re: Window in Window  on: Nov 18th, 2017, 9:00pm
Started by Bonemaster | Post by Bonemaster
Hey all thx for the responses already here is my code im totally new to this and a little self conscious as this is my work so here it is thanks again



[start]
nomainwin

WindowWidth = 800
WindowHeight = 500
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)

button #One.buttonTwo, "BoxTwo", [Two], UL, 25, 250, 100, 25
button #main.buttonOne, "BoxOne", [One], UL, 22, 301, 100, 25
loadbmp "BMP2", "BMP2.bmp"
loadbmp "BMP1", "BMP1.bmp"
menu #main, "Options", "&quit", [quit]

OPEN "This Box One" FOR GRAPHICS_NSB_FS as #main
print #main, "font ms_sans_serif 0 16"
print #main, "trapclose [quit]"

print #main, "background BMP1"
print #main, "drawsprites"

wait


[One]
loadbmp "BMP2", "BMP2.bmp" 'The RED window in upper left corner
OPEN "BoxOne" FOR graphics AS #One
PRINT #One, "trapclose [quitOne]"

print #One, "drawbmp BMP2 10 10 1000 1000; flush"

wait
[quitOne]
CLOSE #One

WAIT

[Two]
loadbmp "BMP3", "BMP3.bmp"
OPEN "BoxTwo" FOR graphics AS #Two
Print #Two, "trapclose [quitTwo]"

print #Two, "drawbmp BMP3 10 10 1000 1000 ;flush"

WAIT
[quitTwo]
CLOSE #Two

WAIT



[quit]

CLOSE #main

end




PLS HELP with my disappearing buttons
thank you!



 
  Reply Quote Notify of replies

 10   Novice / Re: Window in Window  on: Nov 18th, 2017, 4:26pm
Started by Bonemaster | Post by bplus
Yes some code is worth thousands of words and breaks right through language barriers.

Or perhaps you can copy and strip down code to essential problem... might make things clear for yourself as well!
 
  Reply Quote Notify of replies


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Just BASIC wiki
Wikispaces

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls