QBasic and QB64 Discussion Board

[QB Forum Archives (1999-2009)/ ] [QB FAQ] [QB Links and Downloads] [Subforums and Chat Room] [Search]

QB64.Net Homepage   QB/QB64 Keywords   QB Graphics Forum   Homework Policy



.bas to Java..?

by (no login)

Hello guys and girls,

I am pretty pleased with QB - it's just about the only programming language I can handle, and the 'make exe' feature works fine for me, but I'd like to be able to make my programs a little more 'OS-independant', but having read about this, I've found out, that converting *.exe files to java does not work.

Would someone be able (and willing) to make a java compiler for either *.bas files, or something else, that qb64 can create from the initial basic code?

Any other suggestions as to how I get to make a working java, from my basic projects (that is, without learning to write java code)?



    
This message has been edited by Solitaire1 on Jul 17, 2011 5:21 PM

Posted on Jul 17, 2011, 1:30 AM

Respond to this message   

Return to Index


I removed the * that was placed in the above title post, which included text

by Solitaire (Login Solitaire1)
S

Note to Lars:

Welcome to the forum.  The * is placed in the title only to notify readers that there is no text enclosed, so they won't bother opening it.

I don't believe anyone has ever written a QBasic to Java converter.

 

Posted on Jul 17, 2011, 5:25 PM

Respond to this message   

Return to Index


Why Java?

by (Login MCalkins)
Moderator

I guess it's a matter of opinion, but I'm not sure if I would recommend such a thing in the first place. I don't know how "OS-independent" your programs need to be, but, unless I am mistaken, QB64 already targets Win32, Linux, and Mac OS X. If I recall correctly, QB64 uses SDL, a cross platform library.

There are other cross platform libraries also, such as GTK+, Allegro, pdcurses, OpenGL, etc. Of course, the program would have to be compiled and linked separately for each platform.

Also, just because a program is compiled for one platform doesn't mean it can't run on another. For example, Wine allows Win32 programs to run on Linux and FreeBSD, and also, FreeBSD can run Linux programs.

I am not very familiar with Java, other than what little I've read about it. However, it sounds like you aren't a Java programmer yet. So, it doesn't seem like you should have any attachment to it.

Just how cross platform do you need your programs to be? What kind of capabilities do they need to have?

Regards,
Michael



    
This message has been edited by MCalkins on Jul 17, 2011 9:52 PM
This message has been edited by MCalkins on Jul 17, 2011 9:51 PM

Posted on Jul 17, 2011, 9:51 PM

Respond to this message   

Return to Index


RE: Why Java?

by (no login)

Well you're right, that I'm not a Java programmer.

The reason for asking for a converter/compiler to Java is, that I see Java used just about everywhere these days, on computers, for web-apps, on smartphones and so on.

The present project, is intended to run from my homepage, as kind of a "lottery machine" where the user can input i.e. that he has a car, a bicycle and a skateboard in a 'transport' category - and that he has a cat, a dog, and a turtle for pets, in a 'pet' category, and finally that he has a grocery store, a supermarket, and a bakery shop within reach, in a 'target' category.
The joke being, that he will get a randomized selection, like i.e. "Ride your bicycle to the supermarket, with your cat on a leash".

For this project the app should be able to handle (almost) any number of text strings, and for some of the strings, a numeric value (1-10) attached to the string, as well as handling a randomize.

Does this answer your question? ;oD

Posted on Jul 18, 2011, 12:01 AM

Respond to this message   

Return to Index


RE: Why Java?

by (no login)

Well, by the way, I'd actually like the program to be able to send the result, as 1-3 email(s) to adresses entered by the user.

Posted on Jul 18, 2011, 12:22 AM

Respond to this message   

Return to Index


If you're familiar with Basic, then you can try using Visual Basic.NET

by Solitaire (Login Solitaire1)
S

A free Express version of the program is available for download from:

http://www.microsoft.com/express/download/

There is a learning curve involved since it makes use of the .NET framework, but MS has many tutorials and demos you can follow.  There is a WPF Browser App selection in the Visual Basic edition.  However, I don't have experience with this mode so you may need to make inquiries at this forum:

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/threads

There is also a web-developer Express version available at the download site above, but I don't think it uses Basic.



    
This message has been edited by Solitaire1 on Jul 18, 2011 9:26 AM
This message has been edited by Solitaire1 on Jul 18, 2011 9:12 AM

Posted on Jul 18, 2011, 9:09 AM

Respond to this message   

Return to Index


It sounds like you could use a server side application.

by (Login MCalkins)
Moderator

CGI allows programs to be executed on the server. I have no experience with it, but I believe it is possible to get a QB program to work in such a way. (I guess if the server runs Linux, it might need DOSEMU???. Or perhaps use FreeBASIC to compile the program for Linux? I don't think QB64 would work, because I don't think QB64 programs use Stdout.)

http://en.wikipedia.org/wiki/Common_Gateway_Interface

So, basically, when someone visits your website, the server executes your program. Your program runs, and outputs HTML to Stdout, which is sent back to the user. You would need an understanding of HTTP headers and HTML, including forms. CSS wouldn't hurt either. You might even use JavaScript if you need any client side scripting.

To email the results back, you would need access to an email account, and an SMTP server. QB doesn't support sockets, but there is probably an easier way. Perhaps a command line SMTP client:

http://en.wikipedia.org/wiki/SendEmail

You would need to be able to run it on the server. I'm not sure how much configuration that would require. If you use an email account provided by the web host, the SMTP server might be on the same computer.

In short, I don't think you need Java. And, with all due respect to Solitaire, I don't think you need .NET either.

My recommendation is to find out how to use CGI on your server. If you expect a lot of traffic, FastCGI might be better, except that it would require a socket, if I understand correctly, and sockets aren't directly supported in QB.

Regards,
Michael

Here is something qbguy wrote about CGI:

http://www.network54.com/Forum/13959/thread/1211932698/More+Info

Here is something shellreef wrote a long time ago:

http://www.network54.com/Forum/13959/message/946947003/More+detail



    
This message has been edited by MCalkins on Jul 21, 2011 8:53 PM

Posted on Jul 18, 2011, 12:48 PM

Respond to this message   

Return to Index


*2 more links(URL)

by (Login MCalkins)
Moderator

http://www.petesqbsite.com/sections/express/issue27/cgi_and_qbasic.txt

http://www.petesqbsite.com/sections/express/issue29/CGI_Part_2.rtf

Posted on Jul 18, 2011, 1:07 PM

Respond to this message   

Return to Index


Java is the wrong choice for this, IMHO

by Pharoah (no login)

If there were a hell, there'd be a special circle reserved for Java applets on webpages. They're slow to load and always display like crap. This is why Flash seems to have won the battle for web-dominance.

It might be that you're thinking of JavaScript, which is a sort of scripting language used to make webpages interactive. It's what gmail uses, for example. JavaScript isn't too difficult to learn, but you also need to learn HTML and CSS to do anything much with it. The other problem with JavaScript is that you have to write a bunch of hacks if you want the code to be cross-browser compatible.

Posted on Jul 21, 2011, 5:14 PM

Respond to this message   

Return to Index


I'm still not exactly sure what he is trying to do.

by (Login MCalkins)
Moderator

Everything you mentioned would be client side, I think. I guess he could accomplish most of what he said with a client side script or application. The part where he wants to email the results is the part that I think would be best done server side. (Whom are the results going to be emailed to? To the user? Why not just tell the user? To a third party? They'd probably consider it unwanted spam...) I guess the results could be emailed from the client's computer, but that would probably depend on the user's email account and client. Also, he called it a lottery. I guess if there will be one winner, I guess that would need to be kept track of server side also.

As for server side execution, scripting seems to be a common choice. Some of the main choices seem to be Perl, PHP, and Python. However, CGI allows compiled C programs to be used (and QB/FreeBASIC programs also). I'd say the best option for server side execution would be a compiled C program using CGI or FastCGI.

Regards,
Michael

Posted on Jul 21, 2011, 6:51 PM

Respond to this message   

Return to Index


I agree that server side would be the best choice for this

by Pharoah (no login)

Any number of things would work for the application as described, since it's pretty simple. If Lars is running on a shared host, though, he might well find that he's stuck with using PHP, since most of the less expensive shared hosts seem to only support PHP and possibly Perl/Python.

The good news in that case would be that PHP is pretty user friendly, and it's got a low bar to entry (although it's easy to shoot yourself in the foot, too). Also, PHP has some of the best documentation I've ever seen.

>Lars

If you're interested in learning one of the client side scripting languages, I have experience in the common ones. Let me know and I can put together some links, but be sure to look up what your host can support first.

Posted on Jul 21, 2011, 8:43 PM

Respond to this message   

Return to Index


pic data

by (no login)

is there a way of taking of putting text into a photo ( .bmp ) that no one can see with out using a program to extract it ..

eg

i have a photo and i want to play a game with someone where the txt is hidden..

i give them the photo and say theres something
hidden in it and you have to find it ( sort of like a water mark )



now with the program ( if there is one ) i want to be able to extract the txt too

Posted on Jul 16, 2011, 3:38 AM

Respond to this message   

Return to Index


It wouldn't be necessary to actually "hide" the text...

by (Login qb432l)
R

The information about text and where it is located could be established apart from the photo itself in a separate file. Depending on how you test for a message, for example mouse location, the location would then simply relate to data in the file.

It's a pretty simple thing to accomplish if you understand QBasic programming. The question is, do you? Or perhaps this is just a general question.

-Bob

Posted on Jul 16, 2011, 1:09 PM

Respond to this message   

Return to Index


a couple of ideas.

by (Login MCalkins)
Moderator

the first one that comes to mind is to use a palette. draw the text on on a background, such that the text and the background use distinct color attributes, but both assigned to the same color.

Some file formats are loose enough that you can put extra information in them without disrupting the file. For example, an early version of the Stuxnet virus used a combination autorun.inf / PE file, such that the file was both a valid PE file, and a valid autorun.inf file. I'm thinking that you could probably append text to the end of a .BMP without disrupting it. However, it's been long enough since I've messed with the BMP format, I don't remember. It should be pretty easy to test, with the copy command in binary mode.

Perhaps if you have a 24 bit color photograph, you could hide a binary message by setting or clearing the least significant bit of certain arbitrarily chosen data bytes. Doing so would cause minimal visual difference in the photo. However, a careful comparison with the unmodified photo would reveal the data.

Regards,
Michael

Posted on Jul 16, 2011, 4:02 PM

Respond to this message   

Return to Index


You could put the message in the Palette info

by (Login burger2227)
R

Since text uses ASCII characters and so does the palette in a bitmap, you could add text there. The palette can have values from 0 to 255 just like ASCII. The palette starts at byte 55 so PUT the message after black at 59.

OPEN "filename.bmp" FOR BINARY AS #1
text$ = "Hello World! Isn't this fun!"
PUT #1, 59, text$
CLOSE #1

Try the above in any 4 or 8 bit bitmap and open it in Notepad to see the message. You can use the code below to read it:

OPEN "filename.bmp" FOR BINARY AS #1
text$ = SPACE$(28)
GET #1, 59, text$
PRINT text$
CLOSE #1

You can have a message up to 60 characters in 4 BPP or 1020 characters in 8 BPP bitmaps. DON'T USE 24 BPP bitmaps! You can find the BPP in the Properties summary of most bitmaps as the Bit Depth.

This will throw the colors off, but give you a message that can be read by another program using the same format to decode it. The shorter the message, the less color changes.

http://qb64.net/wiki/index.php?title=Bitmaps

I would recommend that you make a copy of the bitmap first so that you don't destroy the original.

Ted



    
This message has been edited by burger2227 on Jul 16, 2011 10:05 PM
This message has been edited by burger2227 on Jul 16, 2011 10:00 PM
This message has been edited by burger2227 on Jul 16, 2011 9:58 PM
This message has been edited by burger2227 on Jul 16, 2011 9:54 PM
This message has been edited by burger2227 on Jul 16, 2011 9:50 PM

Posted on Jul 16, 2011, 9:40 PM

Respond to this message   

Return to Index


You could also hide another image in the image

by Pharoah (no login)

If you used an indexed BMP format and had duplicate palette entries for every color (e.g. color 1 is the same as color 51, color 2 is the same as color 52). Then you could make something that looks like a normal color image, but actually hides a second monochrome image inside it if you set colors 0-50 to black and colors 51-100 to white.

I usually just lurk here, but this was an interesting idea I had lately, so I thought I'd post it.

Posted on Jul 17, 2011, 12:55 PM

Respond to this message   

Return to Index


New To QBasic, Need Help WIth Program

by (no login)

Hello everyone, I'm new to Qbaisc and I have been working on this problem for the past week and have been unable to get it to run. I continually get an error message. can anyone help.

Here is the scenario I was given:

1. Assume you have a company called Rampage Seminar Inc., which offers programming seminars to companies. Your price per person depends on the number of people the company registers. (For example, if the company registers 7 people, then the total amount owed by the company is $560). Use the following charges.

1-4 $100/person
5-10 $80/person
11 or more $60/person
Less than 1 $0/person.

Write a basic program using If then else and Do loop with sub routines to print what each company owes?

Use read data statement with the following data. The program stops when it encounters an End statement.

Read nam$, numberofpersons
Data ABC company, 5
Data NBC Corporation, 7
Data XLR company, 8
Data Lucent corp, 12
Data Ameritech, 3
Data Rambo Mart, 0
Data end, 0



OK this is what I came up with but I'm unable to get the program to run. Any ideas or suggestions would be appreciated.

Thanks

Justin


'***************************************************************************
' This program will produce the Revenue
' generated for seminar booked
'***************************************************************************

' Variable used:
' Nam$ Company name
' NamSave$ Save company name for subtotals
' Size$ Number of people
' Hours Number of hours
' Revenue Amount of revenue
' HoursSubtot Calculated seminar hours
' RevenueSubtot Calculated seminar revenue
' HoursTot Calculated report total
' RevenueTot Calculated report total revenue
' LineCt Line Count
' PageCt Page Count
' MaxLines Maximum number of lines per page
' T1$, H1$, H2$, D1$ Print Images
' ST$, TL$ Print Images
' TotHours Total'

'****************************************************************************
'* Program Mainline *
'****************************************************************************

CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB PrintTotals
END

'****************************************************************************
'* Initialize Variables *
'****************************************************************************

InitializeVariables:
LET PageCt = 0
LET Rate = 0
LET Num = 0
LET Numtot = 0
LET AmountTot = 0
LET T1$ = " Seminar Revenue June 2011"
LET H1$ = " Seminar Seminar"
LET H2$ = " Name Size Hours Revenue"
LET D1$ = "\ \ ## ## $#,###.##"
LET ST$ = "\ SUBTOTAL ## $#,###.##"
LET TL$ = "\ TOTALS ## $#,###.##"
LET MaxLines = 30
RETURN

'****************************************************************************
'* LPRINT HEADINGS *
'****************************************************************************

PrintHeadings:
LET PageCt = PageCt + 1 'Add to page counter
LPRINT CHR$(12); 'Advance to top of page
LPRINT USING T1$; PageCt 'Print title line
LPRINT
LPRINT H1$ 'Print column headings, line 1
LPRINT H2$ 'Print column headings, line 2
LPRINT
LPRINT
LET LineCt = 0 'Reset line counter
RETURN

'****************************************************************************
'* PROCESS DETAIL *
'****************************************************************************

ProcessDetail:
GOSUB ReadData 'Prime the data read
LET NamSav$ = Nam$ 'Save company name
DO UNTIL Nam$ = "END" 'Loop until data done
GOSUB CalculateRevenue 'Loop until data done
GOSUB CalculateSubtotal 'Keep running subtotals
IF LineCt >= MaxLines THEN
GOSUB PrintHeadings
END IF
GOSUB PrintDetail
GOSUB ReadData
IF Num < 1 THEN
LET Rate = 0
ELSEIF Num >= 1 AND Num <= 4 THEN
LET Rate = 100
ELSEIF Num >= 5 AND Num <= 10 THEN
LET Rate = 80
ELSEIF Num >= 11 THEN
LET Rate = 100
END IF
LOOP
RETURN

'****************************************************************************
'* READ DATA *
'****************************************************************************

ReadData:
READ Nam$, Size
DATA ABC Company,5
DATA NBC Corporation,7
DATA XLR Company,8
DATA LUCENT Corp,12
DATA RAMBO MART,0
DATA END,0
RETURN

'****************************************************************************
'* CALCULATE REVENUE *
'****************************************************************************

CalculateRevenue:
LET AmountOwed = Rate * Size
RETURN

'****************************************************************************
'* CALCULATE SUBTOTALS *
'****************************************************************************

CalculateSubtotal:
LET SeminarHours = SeminarHours + Hours
LET RevenueSubtot = RevenueSubtot = Revenue
RETURN

'****************************************************************************
'* CALCULATE TOTALS *
'****************************************************************************

CalculateTotals:
LET Numtot = Numtot + Num
LET AmountTot = AmountTot + AmountOwed
RETURN

'****************************************************************************
'* PRINT DETAIL *
'****************************************************************************

PrintDetail:
LPRINT USING D1$; Nam$; Size; Revenue 'print details
LET LineCt = LineCt + 1
RETURN

'****************************************************************************
'* LPRINT SUBTOTALS *
'****************************************************************************

PrintSubtotals:
LPRINT
LPRINT USING D1$; Nam$; HoursSubtot; RevenueSubtot 'Print Subtotal Line
LPRINT
LET HoursTot = HoursSubtot + HoursTot 'Add to hours total
LET RevenueTot = RevenueSubtot + RevenueTot 'Add to revenue total
LET HoursSubtot = 0 'Reset hrs subt to 0
LET RevenueSubtot = 0 'Reset rev subt to 0
LET LineCt = LineCt + 3 'Add to line counter
LET NamSave$ = Nam$ 'Save new group
RETURN

'****************************************************************************
'* LPRINT TOTALS *
'****************************************************************************

PrintTotals:
LPRINT
LPRINT USING TL$; HoursTot; RevenueTot 'Print totals line
RETURN

'****************************************************************************
'* END OF PROGRAM *
'****************************************************************************








Posted on Jul 2, 2011, 1:29 PM

Respond to this message   

Return to Index


Hello, Justin.

by (Login MCalkins)
Moderator

Welcome to the forum.

With all due respect to you, it seems that someone is teaching you an archaic programming style. Most people don't use the LET statement anymore. Assignment can be done as:

variable = expression.

Note that the equals sign can be an assignment operator or an equality testing operator depending on the context. For example:

a = b = c

is valid. The expression b = c returns true (-1) if b is equal to c, and false (0) otherwise. The value of that expression is assigned to a.

Also, you aren't dimensioning your variables with the DIM statement. Doing so isn't necessary, but some people consider it good practice. Variables will be SINGLE unless you specify otherwise, using DIM, DEFxxx, or a data type suffix.

Be advised that when posting to this forum, all white space is lost. This includes indentation, which is eliminated, and any spaces that are next to each other, which are combined into one space. To preserve white space when posting, replace spaces (Unicode: hex: 0x20, decimal: 32) with No Break Spaces (Unicode: hex: 0x00a0, decimal: 160). I think some spacing in your PRINT or PRINT USING strings was lost.

I don't have an LPT printer hooked up, so I changed all the LPRINTs to PRINT. When I ran your program, I got an "Illegal function call" on:

PRINT USING T1$; PageCt'Print title line

I assume that that is the error to which you were refering.

I am not very familiar with PRINT USING. However, I almost think you put USING by mistake in this case, as T1$ doesn't seem to be a format string in this case.

Your program is hard to read due to excessive usage of subroutines. Again, this is probably evidence of being taught archaic programming style.

However, if I am not mistaken, you are attempting to CalculateRevenue before you determine Rate, in the case of the first company. I think:

IF Num < 1 THEN
LET Rate = 0
ELSEIF Num >= 1 AND Num <= 4 THEN
LET Rate = 100
ELSEIF Num >= 5 AND Num <= 10 THEN
LET Rate = 80
ELSEIF Num >= 11 THEN
LET Rate = 100
END IF

should be moved to immediately after:

DO UNTIL Nam$ = "END" 'Loop until data done

And all those ELSEIFs could be replaced by a SELECT CASE, except that your archaic teacher specified otherwise.

I don't think DATA lines are executable, so they could be at the end of the program, outside of any subroutine. I'm not sure if it is necessary, but I'd put quotation marks around text values out of principle.

I'll look over it more later, and post again if necessary.

Regards,
Michael



    
This message has been edited by MCalkins on Jul 2, 2011 2:24 PM

Posted on Jul 2, 2011, 2:22 PM

Respond to this message   

Return to Index


also (Size, Num, Hours, Revenue, NamSave$, and NamSav$))

by (Login MCalkins)
Moderator

you are not assigning anything to Num except 0. I am pretty sure it ought to be assigned the value of Size at some point, or else it can be merged with Size. It almost looks like Size and Num ought to be the same thing. Be advised that in your comments you refer to Size$ which would be a string variable, but in you program, Size is a numeric variable, a SINGLE.

Also, you are not assigning anything to Hours. I don't see any mention of hours in the specification.

Also, you have:

LET RevenueSubtot = RevenueSubtot = Revenue

I'm pretty sure that should be:

RevenueSubtot = RevenueSubtot + Revenue

Except that you are not assigning anything to Revenue either. Perhaps Revenue is the same as AmountOwed, the same way Size is the same as Num, presumably?

Also, you have both NamSav$ and NamSave$, but you don't use the values that you assign to them...

Regards,
Michael



    
This message has been edited by MCalkins on Jul 2, 2011 2:44 PM
This message has been edited by MCalkins on Jul 2, 2011 2:40 PM
This message has been edited by MCalkins on Jul 2, 2011 2:35 PM
This message has been edited by MCalkins on Jul 2, 2011 2:33 PM
This message has been edited by MCalkins on Jul 2, 2011 2:31 PM

Posted on Jul 2, 2011, 2:31 PM

Respond to this message   

Return to Index


so appreciated

by (no login)

Thanks for the input. I will review my program and make the changes you recommended. The LET statement is what is being taught to us, I wish we were given more assistance in this class but the teacher rarly is available when we have questions. I'm glad to have found this forum. I will let you know what happen. Again thanks for the help!

Posted on Jul 2, 2011, 2:53 PM

Respond to this message   

Return to Index


you're welcome.

by (Login MCalkins)
Moderator

Also, if the size is >= 11, then the Rate needs to be 60, not 100.

I'm thinking that your program uses way too many variables, some of which seem to duplicate each other. My advice is to go through the program and rethink whether you really need certain variables, or whether they very closely duplicate the role of ones you already have. Make sure you are doing something sensible with each one.

Unless your teacher insists otherwise, I would recommend moving some of the smaller subroutines inline, that is, don't make them subroutines if they are small and only called from one place.

I didn't see any mention of Hours in the spec, which makes me wonder why you're working with them. Was it part of the spec that the results had to be printed onto paper, or separated into multiple pages?

I've modified your program a bit, to see how it could be written much more simply. I'm reluctant to post it, because this is homework. Since it doesn't do a number of things that your program does, such as formatting the output the way yours did, I'm tempted to post it, at least as a demonstration. I'll refrain for now, and maybe post it after you've posted some modifications yourself.

Regards,
Michael

Posted on Jul 2, 2011, 3:10 PM

Respond to this message   

Return to Index


Changes Made

by (no login)

Hello Michael thanks again for the pointers, yeah I looked at it completely and made changes. I used an old project I had done previously as a guide and that is where some of the "hours" data was coming from. I have removed some parts of the program as you had advised since I did not see any bearing in the outcome. I have e-mailed you my revised program. Could you look at it. Seems the revenue is not populating. Not sure if the data fields are being captured to come up with the revenue totals.

Posted on Jul 2, 2011, 6:24 PM

Respond to this message   

Return to Index


Post your adjusted code

by Solitaire (Login Solitaire1)
S

Justin, it's a good idea to post your code on the forum rather than send it to one person.  That way others on the forum can observe and make recommendations as needed.

By the way, do you actually have an old parallel port printer that will work with the LPRINT command?  Most of us ditched those old printers ages ago and QB will not work with our new USB printers, since QB was discontinued before USB came into general use.

Curious -- are you using a textbook with your course?  If so, what is the title and author?  Is this for a high school or a college course?  (I'm guessing high school.  I can't imagine any college still using QB in this day and age.)  Is your teacher simply blindly following the textbook?  Has he been teaching this course exactly the same way for the last 20 years?  If so, he really needs to get up to date.

You seem to be a serious student who really wants to succeed in your studies.  Good luck to you.  It's too bad you didn't get started with something more modern, but it's still a good experience.

Make note of the variable declarations suggested by Michael.  There are other recommendations I would make (especially regarding type conversions) but this was not specifed by your assignment and I don't want to lead you off track.

 



    
This message has been edited by Solitaire1 on Jul 2, 2011 8:33 PM
This message has been edited by Solitaire1 on Jul 2, 2011 8:27 PM

Posted on Jul 2, 2011, 8:19 PM

Respond to this message   

Return to Index


what he emailed...

by (Login MCalkins)
Moderator

'
'***************************************************************************
'                       This program will produce the Revenue
'                       generated for seminar booked
'***************************************************************************

'           Variable used:
'           Nam$                        Company name
'           NamSave$                    Save company name for subtotals
'           Size                        Number of people
'           Revenue                     Calculated seminar revenue
'           RevenueTot                  Calculated report total revenue
'           LineCt                      Line Count
'           PageCt                      Page Count
'           MaxLines                    Maximum number of lines per page
'           T1$, H1$, H2$, D1$, TL$     Print Images

'****************************************************************************
'*                          Program Mainline                                *
'****************************************************************************

CLS
GOSUB InitializeVariables
GOSUB PrintHeadings

GOSUB ProcessDetail
GOSUB PrintTotals
END

'****************************************************************************
'*                          Initialize Variables                            *
'****************************************************************************

InitializeVariables:
LET PageCt = 0
LET Rate = 0
LET Num = 0
LET Numtot = 0
LET AmountTot = 0
LET T1$ = "             Seminar Revenue June 2011"
LET H1$ = "                     Seminar                        Seminar    "
LET H2$ = "     Name             Size                         Revenue"
LET D1$ = " \                 \  ##                           $#,###.##"
LET TL$ = "                          Revenue Total            $#,###.##"
LET MaxLines = 30
RETURN

'****************************************************************************
'*                          LPRINT HEADINGS                                 *
'****************************************************************************

PrintHeadings:
LET PageCt = PageCt + 1 'Add to page counter
PRINT CHR$(12); 'Advance to top of page
PRINT
PRINT H1$ 'Print column headings, line 1
PRINT H2$ 'Print column headings, line 2
PRINT
PRINT
LET LineCt = 0 'Reset line counter
RETURN

'****************************************************************************
'*                          PROCESS DETAIL                                  *
'****************************************************************************

ProcessDetail:
GOSUB ReadData 'Prime the data read
LET NamSav$ = Nam$ 'Save company name
DO UNTIL Nam$ = "END" 'Loop until data done
    GOSUB CalculateRevenue 'Loop until data done
    IF Num < 1 THEN
        LET Rate = 0
    ELSEIF Num >= 1 AND Num <= 4 THEN
        LET Rate = 100
    ELSEIF Num >= 5 AND Num <= 10 THEN
        LET Rate = 80
    ELSEIF Num >= 11 THEN
        LET Rate = 60
    END IF
    GOSUB PrintDetail
    GOSUB ReadData
LOOP
RETURN

'****************************************************************************
'*                              READ DATA                                   *
'****************************************************************************

ReadData:
READ Nam$, SeminarSize$
DATA "ABC Company",5
DATA "NBC Corporation",7
DATA "XLR Company",8"
DATA "LUCENT Corp",12"
DATA "RAMBO MART",0
DATA "END",0
RETURN

'****************************************************************************
'*                      CALCULATE REVENUE                                   *
'****************************************************************************

CalculateRevenue:
LET Revenue = Rate * Size
RETURN

'****************************************************************************
'*                      CALCULATE TOTALS                                    *
'****************************************************************************

CalculateTotals:
LET Numtot = Numtot + Num
LET RevenueTot = RevenueTot + Revenue
RETURN

'****************************************************************************
'*                      PRINT DETAIL                                      *
'****************************************************************************

PrintDetail:
PRINT USING D1$; Nam$; Size; Revenue 'print details
LET LineCt = LineCt + 1
RETURN

'****************************************************************************
'*                      LPRINT TOTALS                                       *
'****************************************************************************

PrintTotals:
PRINT
PRINT USING TL$; SizeTot; RevenueTot 'Print totals line
RETURN

'****************************************************************************
'*                      END OF PROGRAM                                      *
'****************************************************************************

Posted on Jul 3, 2011, 9:18 AM

Respond to this message   

Return to Index


a little better....

by (Login MCalkins)
Moderator

but some of the same issues are still present...

First:

Change all instances of Num to Size.

Change all instances of NumTot to SizeTot.

I had advised you to move your IF...ELSEIF block to immediately after the DO line. You attempted to fix the problem, but you pasted it in the wrong place.

In your first program, you have:

ProcessDetail:
GOSUB ReadData 'Prime the data read
LET NamSav$ = Nam$ 'Save company name
DO UNTIL Nam$ = "END" 'Loop until data done
GOSUB CalculateRevenue 'Loop until data done
GOSUB CalculateSubtotal 'Keep running subtotals
IF LineCt >= MaxLines THEN
GOSUB PrintHeadings
END IF
GOSUB PrintDetail
GOSUB ReadData
IF Num < 1 THEN
LET Rate = 0
ELSEIF Num >= 1 AND Num <= 4 THEN
LET Rate = 100
ELSEIF Num >= 5 AND Num <= 10 THEN
LET Rate = 80
ELSEIF Num >= 11 THEN
LET Rate = 100
END IF
LOOP
RETURN

Do you see what happens? You call ReadData once before the start of the loop. The reason is that the "END" might be the first data entry, and there is no reason to go through the loop in that instance. So that is okay. Then, inside the loop, you call CalculateRevenue, which relies on Rate. But it isn't until the end of the loop that Rate is calculated. So, for the first entry, Rate will be 0. After that, you call ReadData followed by Rate, which is correct. You have the concept of the Rate calculation coming after ReadData correct, except for the first data entry.

In your revised program, you have:

ProcessDetail:
GOSUB ReadData 'Prime the data read
LET NamSav$ = Nam$ 'Save company name
DO UNTIL Nam$ = "END" 'Loop until data done
    GOSUB CalculateRevenue 'Loop until data done
    IF Num < 1 THEN
        LET Rate = 0
    ELSEIF Num >= 1 AND Num <= 4 THEN
        LET Rate = 100
    ELSEIF Num >= 5 AND Num <= 10 THEN
        LET Rate = 80
    ELSEIF Num >= 11 THEN
        LET Rate = 60
    END IF
    GOSUB PrintDetail
    GOSUB ReadData
LOOP
RETURN

Again, you call ReadData once before entering the loop. When you enter the loop, you call CalculateRevenue, which requires Rate, but, still, you haven't yet determined Rate. In attempting to implement my suggestion, you moved the IF block up, but not far enough. Now, it is after CalculateRevenue in all iterations of the loop, instead of just the first.

The IF block that calculates the Rate needs to immediately follow ReadData in all iterations of the loop, including the first.

Have a look:

ProcessDetail:
GOSUB ReadData 'Prime the data read
LET NamSav$ = Nam$ 'Save company name
DO UNTIL Nam$ = "END" 'Loop until data done
    IF Size < 1 THEN
        LET Rate = 0
    ELSEIF Size >= 1 AND Size <= 4 THEN
        LET Rate = 100
    ELSEIF Size >= 5 AND Size <= 10 THEN
        LET Rate = 80
    ELSEIF Size >= 11 THEN
        LET Rate = 60
    END IF
    GOSUB CalculateRevenue 'Loop until data done
    GOSUB CalculateTotals
    GOSUB PrintDetail
    GOSUB ReadData
LOOP
RETURN

In this case, ReadData is called once before entering the loop (in case "END" is the first entry). Then, immediately, Rate is determined. Then, CalculateRevenue is called. The last part of the loop is a call to ReadData, which sets up the next iteration of the loop. This is correct. I took the liberty of adding a call to CalculateTotals, as your revised program had none.

In ReadData, you implemented my suggestion to use quotation marks. However, you accidentally added some to the numeric values. Then, to avoid a "Syntax error" you changed Size to a string:

ReadData:
READ Nam$, SeminarSize$
DATA "ABC Company",5
DATA "NBC Corporation",7
DATA "XLR Company",8"
DATA "LUCENT Corp",12"
DATA "RAMBO MART",0
DATA "END",0
RETURN

Size needs to be a numeric variable:

ReadData:
READ Nam$, Size
DATA "ABC Company",5
DATA "NBC Corporation",7
DATA "XLR Company",8
DATA "LUCENT Corp",12
DATA "RAMBO MART",0
DATA "END",0
RETURN

Note that DATA statements are not executable, so they don't need to be in a subroutine.

ReadData:
READ Nam$, Size
RETURN

DATA "ABC Company",5
DATA "NBC Corporation",7
DATA "XLR Company",8
DATA "LUCENT Corp",12
DATA "RAMBO MART",0
DATA "END",0

would work just as well.

After making those changes, your program should actually work. I think it still has some remnants of unused variables, like NamSav$, which you can then clean up. Also, your PRINT USING displays SizeTot with a "$" sign, but that should be pretty easy to fix.

Regards,
Michael



    
This message has been edited by MCalkins on Jul 3, 2011 3:32 PM
This message has been edited by MCalkins on Jul 3, 2011 10:22 AM
This message has been edited by MCalkins on Jul 3, 2011 10:21 AM

Posted on Jul 3, 2011, 10:19 AM

Respond to this message   

Return to Index


*Justin, have you gotten it working yet?

by (Login MCalkins)
Moderator

Posted on Jul 7, 2011, 8:21 PM

Respond to this message   

Return to Index


Sorry, Thanks

by Justin (no login)

Thanks Michael for the info and tips on the program I was able to figure it out and get it to run.

Been away since I e-mailed you last. My mom has been hospitalized and have been in an out of the hospital this past week.


I do have a question regarding the program, and that is on the Read Data portion of it. I'm looking at it and the question I have is this the command that reads all the numerical values and adds them?

'****************************************************************************
'* CALCULATE TOTALS *
'****************************************************************************

CalculateTotals:
LET Numtot = Numtot + Num
LET RevenueTot = RevenueTot + Revenue
RETURN

Posted on Jul 9, 2011, 11:30 AM

Respond to this message   

Return to Index


It adds the value to itself.

by Solitaire (Login Solitaire1)
S

If you did:

total = revenue

then the total would start out at 0 and not account for the previous values that were included in the total.

 

total = total + revenue

adds the new revenue on to the previous total.  This is done inside a loop, or in your case, by repeatedly calling the subroutine.

 

I hope this clarifies your inquiry.  Hope you mom is feeling better.

 



    
This message has been edited by Solitaire1 on Jul 9, 2011 4:58 PM

Posted on Jul 9, 2011, 11:46 AM

Respond to this message   

Return to Index


Re: Sorry, Thanks

by (Login MCalkins)
Moderator

You're welcome, and I'm not aware of any need for you to apologize.

>I was able to figure it out and get it to run.

That's good.

>Been away since I e-mailed you last. My mom has been hospitalized and have been in an out of the hospital this past week.

I also hope your mom is feeling better.

>I do have a question regarding the program, and that is on the Read Data portion of it. I'm looking at it and the question I have is this the command that reads all the numerical values and adds them?

Solitaire already answered, but I will add a little bit:

The CalculateTotals subroutine is not part of the ReadData subroutine. ReadData only does one thing, it loads the next set of data. CalculateTotals keeps track of the total number of students and the total revenue, but not all the numeric variables, just those. Unless I'm missing something, the specification doesn't actually ask you to total the values. I figured you were just doing it as an extra feature.

The expression is NumTot + Num. The expression is evaluated, and the result is assigned to the variable, NumTot. For example, if NumTot is 0, and Num is 5, as it should be on the first call to CalculateTotals, then the expression's value is 5, and that is what is assigned to NumTot. On the next execution of CalculateTotals, NumTot is 5, and Num is 7, so the expression's value of 12 gets assigned to NumTot.

The same principle applies with RevenueTot and Revenue.

Note that QBASIC has excellent debugging capabilities. These allow you to examine how your program operates.

Shift+F1 gives you help.
F1 gives you context sensitive help.
F4 shows you the program's output.
Shift+F5 starts your program from the beginning.
F5 starts or resumes your program.
F6 switches windows.
F8 steps through the program one instruction at a time.
F9 sets of clears break points.
F10 steps through the program one instruction or subroutine/function/procedure at a time.
Ctrl+C interrupts your program from an INPUT or LINE INPUT.
Ctrl+Break interrupts your program.

There is an option in the Debug menu to set the current position of execution, but there is no shortcut key for it.

The STOP keyword can be used like a break point.

The Immediate Window allows you to execute individual instructions just by pressing Enter on them.

For example, you can step through your program one line at a time with the F8 key. If you want to see the output screen, you can press F4, which will show you the output screen until you press any key. If, at a certain point, you want to check the value of a variable, you can press F6 to switch to the Immediate Window. There you can type a question mark, which is the same as the PRINT statement, followed by the variable name, and then press Enter. This will display the value of the variable on the output screen. Then you can press any key to get out of the output screen, and then you can press F8 again to continue stepping through your program.

Try doing this to see the values of Num, NumTot, Revenue, and RevenueTot at the start of CalculateTotals, and the values of NumTot and RevenueTot at the end of CalculateTotals.

Also, try stepping through the whole program with F8. Doing so will show you the flow of the program.

You can use these debugging feature, obviously, to find and fix bugs, but also to help yourself to have a thorough understanding of the operation of the program. I use these features extensively.


I had said that I had modified your program to use a different programming style. I held off posting it then, but since you now have your own working version, I will post this as an example of a somewhat different programming style. It lacks some features of your program, specifically the formatted output.


DIM Rate AS INTEGER
DIM Size AS INTEGER
DIM AmountOwed AS INTEGER
DIM SizeTot AS INTEGER
DIM AmountTot AS INTEGER
DIM Nam AS STRING

SizeTot = 0 'not necessary, but good practice
AmountTot = 0

CLS
READ Nam, Size
DO UNTIL Nam = "END"
 SELECT CASE Size
 CASE IS < 1: Rate = 0
 CASE 1 TO 4: Rate = 100
 CASE 5 TO 10: Rate = 80
 CASE IS >= 11: Rate = 60
 END SELECT
 AmountOwed = Rate * Size
 SizeTot = SizeTot + Size
 AmountTot = AmountTot + AmountOwed
 PRINT Nam; TAB(32); Size, "$"; LTRIM$(STR$(AmountOwed))
 READ Nam, Size
LOOP
PRINT SizeTot, AmountTot
SYSTEM
     
DATA "ABC Company", 5
DATA "NBC Corporation",7
DATA "XLR Company",8
DATA "LUCENT Corp",12
DATA "RAMBO MART",0
DATA "END",0


First, I declare the variables with the DIM statement, making them all INTEGERs, except Nam, which is a STRING. Note that I preferred Size to Num, in this case, because Nam and Num look similar, and that could result in confusion.

Since, in the loop, the two total variables, SizeTot and AmountTot are assigned values depending on their existing values, I assign them zeros at the start of the program. This isn't necessary in this case, because QBASIC will initialize them to 0 anyway. However, it is good practice, especially in case you put the whole thing in another loop... Also, while QBASIC initializes variables to 0 or null, other languages don't necessarily. I don't bother doing it with the others, because the values they are assigned in the loop don't depend on their existing values.

The operation of the program is basically the same as yours, but without subroutines. As ReadData only had 1 executable line (aside from RETURN), CalculateRevenue had 1, and CalculateTotals had 2, it seemed logical to move them inline.

I replaced the IF block with a SELECT CASE block. Note that the colon is a separator, allowing me to put multiple statements on the same line. For example:

 CASE IS < 1: Rate = 0

is the same as:

 CASE IS < 1
  Rate = 0

However, colons can't always be used to put any two statements on the same line. For example, I wouldn't use them to put two IF ... ELSE statements on the same line. :-P

As the DATA statements are not executable, but just provide data that is used sequentially by the READ statement, they are at the end of the program, after the SYSTEM statement.

Anyway, it's just another style... Obviously, you should probably do what your teacher wants for the purpose of passing the class. But, when you are programming on your own, use whatever style works for you... These aren't the only 2 styles. There are numerous programming styles and variations of styles.

Regards,
Michael



    
This message has been edited by MCalkins on Jul 9, 2011 10:29 PM
This message has been edited by MCalkins on Jul 9, 2011 10:26 PM
This message has been edited by MCalkins on Jul 9, 2011 10:23 PM
This message has been edited by MCalkins on Jul 9, 2011 9:39 PM
This message has been edited by MCalkins on Jul 9, 2011 9:34 PM
This message has been edited by MCalkins on Jul 9, 2011 9:33 PM
This message has been edited by MCalkins on Jul 9, 2011 9:22 PM

Posted on Jul 9, 2011, 9:20 PM

Respond to this message   

Return to Index


Music Program with configurable tuning

by qbguy (no login)

This program plays Bach's C major prelude from Well Tempered Clavier (Book 1). Instead of using PLAY, it uses SOUND. The program allows you to set different temperaments (tunings) and hear how the piece changes.

Furthermore, you can perform tranpositions by altering the reference pitch. For example, changing the line "reference = 256" to "reference = 277" transposes the piece into C-sharp major.

DECLARE SUB PLAYIT (s$)
DIM SHARED s(0 TO 11)
DIM SHARED reference
CONST C = 0
CONST CSHARP = 1, DFLAT = 1
CONST D = 2
CONST DSHARP = 3, EFLAT = 3
CONST E = 4
CONST ESHARP = 5, F = 5
CONST FSHARP = 6, GFLAT = 6
CONST G = 7
CONST GSHARP = 8, AFLAT = 8
CONST A = 9
CONST ASHARP = 10, BFLAT = 10
CONST B = 11

' just intonation scale, c major
s(A) = 5 / 3
s(E) = 5 / 4
s(B) = 15 / 8
s(FSHARP) = 45 / 32
s(F) = 4 / 3
s(C) = 1
s(G) = 3 / 2
s(D) = 9 / 8
s(DFLAT) = 16 / 15
s(AFLAT) = 8 / 5
s(EFLAT) = 6 / 5
s(BFLAT) = 9 / 5

reference = 264
foo:
READ x$
IF x$ = "END" THEN GOTO fin
CALL PLAYIT (x$ + x$)
GOTO foo
fin:
CALL PLAYIT ("<<C> C F A > C F C < A > C < A F A F D F D")
CALL PLAYIT ("<<C B>> G B > D F D < B G B D F E D")
CALL PLAYIT ("<<C> C> E G > C")

' BWV 846
DATA "C E G > C E < G > C E <"
DATA "C D A > D F < A > D F <"
DATA "< B > D G > D F < G > D F <"
DATA "C E G > C E < G > C E <"
DATA "C E A > E A < A > E A <"
DATA "C D F+ A >D< F+ A >D< "
DATA "< B > D G > D G < G > D G <"
DATA "< B > C E G >C< E G >C<"
DATA "< A > C E G > C < E G > C <"
DATA "< D A > D F+ > C < D F+ > C <"
DATA "< G B > D G B D G B"
DATA "< G B-> E G > C+ < E G > C+ <"
DATA "<F A> D A >D< D A >D<"
DATA "<F A-> D F B D F B"
DATA "<E G> C G >C< C G >C<"
DATA "<E F A> C F <A> C F"
DATA "<D F A> C F <A> C F"
DATA "<<G> D G B >F< G B >F"
DATA "<C E G> C E <G> C E"
DATA "<C G B-> C E <B-> C E"
DATA "<<F> F A> C E <A> C E"
DATA "<<F+> C A > C E- <A> C E-"
DATA "<<G> F G B > D < G B > D"
DATA "<<G> E G > C E <G> C E"
DATA "<<G> D G> C F <G> C F"
DATA "<<G> D G B> F <G B> F"
DATA "<<G> E- A> C F+ <A> C F+"
DATA "<<G> E G> C G <G> C G"
DATA "<<G> D G> C F <G> C F"
DATA "<<G> D G B> F <G B> F"
DATA "<<C> C G B-> E <G B-> E"
DATA "END"

SUB PLAYIT (s$)
FOR INDEX = 1 TO LEN(s$)
SELECT CASE MID$(s$, INDEX, 1)
CASE "C"
z = C
CASE "D"
z = D
CASE "E"
z = E
CASE "F"
z = F
CASE "G"
z = G
CASE "A"
z = A
CASE "B"
z = B
CASE "<"
reference = reference / 2
GOTO 1
CASE ">"
reference = reference * 2
GOTO 1
CASE ELSE
GOTO 1
END SELECT
IF INDEX < LEN(s$) THEN
IF MID$(s$, INDEX + 1, 1) = "-" THEN z = z - 1: INDEX = INDEX + 1
IF MID$(s$, INDEX + 1, 1) = "+" THEN z = z + 1: INDEX = INDEX + 1
END IF
SOUND s(z) * reference, 3
1 NEXT
END SUB

Posted on Jun 28, 2011, 1:09 PM

Respond to this message   

Return to Index


Examples of altering tuning

by qbguy (no login)

replacing these lines:
' just intonation scale, c major
s(A) = 5 / 3
s(E) = 5 / 4
s(B) = 15 / 8
s(FSHARP) = 45 / 32
s(F) = 4 / 3
s(C) = 1
s(G) = 3 / 2
s(D) = 9 / 8
s(DFLAT) = 16 / 15
s(AFLAT) = 8 / 5
s(EFLAT) = 6 / 5
s(BFLAT) = 9 / 5

with

FOR index = 0 TO 11
s(i) = 2^(index/12)
NEXT

makes the program use equal temperament, which allows you to play untransposed music in any key (if you have the patience type in the music).

whereas using the code

s(A) = 27/16
s(E) = 81/64
s(B) = 243/128
s(FSHARP) = 729/512
s(F) = 4 / 3
s(C) = 1
s(G) = 3 / 2
s(D) = 9 / 8
s(DFLAT) = 256/243
s(AFLAT) = 128/81
s(EFLAT) = 32/27
s(BFLAT) = 16/9

yields a Pythagorean tuning

Posted on Jun 28, 2011, 1:23 PM

Respond to this message   

Return to Index


* That sounds pretty good! Especially in QB64. I can't hardly hear the onboard speaker...

by (Login burger2227)
R

Posted on Jun 28, 2011, 2:08 PM

Respond to this message   

Return to Index


*Really great stuff, qbguy -- and all with one SOUND statement. Talk about elegance!

by (Login qb432l)
R

*

Posted on Jun 28, 2011, 6:24 PM

Respond to this message   

Return to Index


johan sebastien COCK

by goerge (no login)

Posted on Mar 18, 2014, 5:25 AM

Respond to this message   

Return to Index


MS-DOS _SHELL commands help

by Zack (no login)

I went to the wiki and it wasn't very informative on the different commands available in _SHELL. I also went to a website that someone recomended me and either the syntax wasnt compatable with QB64 or I was doing something wrong. If someone could explain how to do a few simple procedures that I need for my program, that would be fatastic. Below are the _SHELL commands that I need to know.

-Find the location of the program

-Delay a little bit and then
-Delete an entire directory

-Copy something and delete it from the original location or
-Move or Cut somethig to a new location

~Zack

P.S the person who is in charge of this forum should change it to allow multiple spaced to be put in from of text. It would make it much easier to read code. There isn't a button to make a code box like on the QB64.net forums.
Unless '[code]' and '[/code]' are valid html commands here.

Posted on Jun 18, 2011, 7:29 PM

Respond to this message   

Return to Index


SHELL is not a QB64 keyword

by (Login burger2227)
R

-Find the location of the program: SHELL _HIDE "CD > tempfile.INF"

-Delay a little bit: _DELAY 1
-Delete an entire directory: you can use RMDIR if the folder is empty

-Copy something and delete it from the original location or
-Move or Cut somethig to a new location:

SHELL using DEL, COPY or MOVE

or use KILL or NAME to delete or rename a file

http://www.computerhope.com/msdos.htm



Posted on Jun 18, 2011, 7:46 PM

Respond to this message   

Return to Index


Almost got it

by Zack (no login)

I got the directory command, that works fine.

I want it to delay MS DOS not the program. I want it to allow time for the program to close before deleting the folder the program is in, the program, all the dlls, source files, and media files. I am trying to make an uninstall option in my program.

I got the MOVE command to work, but how do I use the directory from the "CD > loc.txt" + "blah.txt" as the starting location for the command?
This gives me a "Expected Operator in equation:

iconloc$ = icon$ + "\icon.ico" 'icon$ obtained from directory command
SHELL MOVE /Y iconloc$ "C:/WINDOWS"

~Zack

Posted on Jun 19, 2011, 6:33 AM

Respond to this message   

Return to Index


After the SHELL, read the file to get the current path

by (Login burger2227)
R

OPEN "loc.tmp" FOR INPUT AS #1

LINE INPUT #1, path$

CLOSE #1

KILL "loc.tmp"

Posted on Jun 19, 2011, 11:07 AM

Respond to this message   

Return to Index


Yes, but

by Zack (no login)

Yeah, I know how to get the location as an input, but how do I use it in the command. This is what I have:

OPEN "source/program/fileloc.txt" FOR INPUT AS #1
INPUT #1, fileloc$
CLOSE #1
fileloc$ = fileloc$ + "\tmcicon.ico"
PRINT DOSCommand$
SHELL _HIDE ("MOVE /Y " + CHR$(34) + fileloc$ + CHR$(34) + " " + CHR$(34) + "C\WINDOWS" + CHR$(34))

I got almost the same thing to work in Command Prompt, but for some reason this isn't working. I don't know if it syntax or if I am just doing something wrong. Please help.

~Zack

Posted on Jun 19, 2011, 7:24 PM

Respond to this message   

Return to Index


* "C\WINDOWS" should be "C:\WINDOWS"

by (Login rpgfan3233)

Posted on Jun 19, 2011, 8:07 PM

Respond to this message   

Return to Index


Thanks, one last thing

by Zack (no login)

Thanks, it is easy to overlook something like that. I am glad you caught it.
Also, is there a delay command for ms dos that you know of? I am trying to have an option to uninstall. Well, it never really was installed, but I want to delete the folder where the program, dlls, source, and media files for the program are located.
If there is not a delay command then do you think there would be enogh time after I send the dos command and before the program closes. I dont want to get a "Disk write protect is on or file is in use" message.
And if not then do you have any other ideas on how I could "uninstall" a program?
Oh, and also, would I be able to delete the entire directory at once, or would I have to delete each file individually.

Thank all of you for your continued help, I truly appreciate it, and I would never have gotten this far without you guys.
~Zack

Posted on Jun 19, 2011, 8:58 PM

Respond to this message   

Return to Index


The DOS batch file Pause command

by Solitaire (no login)

Format: PAUSE message.
message is optional, and the only way to see the message is to keep ECHO ON.

The message is displayed before the PAUSE command's default message:

Strike a key when ready...

Shift keys and option keys will have no effect with the PAUSE command. The spacebar is usually used.

-----------------------------------------
The above information was obtained from the 3rd edition of "Advanced Batch File Programming" by Dan Gookin (1991) covering DOS 3, 4, and 5.

Posted on Jun 19, 2011, 10:03 PM

Respond to this message   

Return to Index


* In QB, the SLEEP command will pause until user presses any key.

by Solitaire (no login)

Posted on Jun 19, 2011, 10:08 PM

Respond to this message   

Return to Index


* The CHOICE batch command has a time delay

by (Login burger2227)
R

Posted on Jun 20, 2011, 12:31 PM

Respond to this message   

Return to Index


Any other ideas?

by Zack (no login)

I looked into the CHOICE command and it is only for certain versions of windows. I need a solution that will work with pretty much any windows.

What I am trying to do is. Have the program run a batch file and then close immediately. Then the batch file will wait a few seconds to allow the program to close. Then thr batch will delete the directory that the program was in and everything else there. (dll, source, pictures, etc.)

Do you have any other ideas of how to make the bat file delay for a few seconds?

~Zack

Posted on Jun 20, 2011, 8:54 PM

Respond to this message   

Return to Index


Try this

by (Login burger2227)
R

You can ping a number of times(3 seconds) for 1000 milliseconds(1 second). The file is used to suppress the screen output and is deleted later.

@echo off

ping 1.1.1.1 -n 3 -w 1000 >> png3rr0r.txt
del png3rr0r.txt

Most of this stuff is READILY available on the web with a Google search, so save yourself a lot of time and try that first...

Ted



    
This message has been edited by burger2227 on Jun 20, 2011 11:17 PM

Posted on Jun 20, 2011, 10:01 PM

Respond to this message   

Return to Index


*ping 127.0.0.1 in case there is no internet connection.

by (Login MCalkins)
Moderator

Posted on Jun 20, 2011, 10:04 PM

Respond to this message   

Return to Index


*"\" is the path separator in DOS and Windows, not "/".

by (Login MCalkins)
Moderator

Posted on Jun 19, 2011, 3:27 PM

Respond to this message   

Return to Index


SHELL

by (Login MCalkins)
Moderator

For the most part, SHELL is a way of accessing the command line shell program. In the case of QBASIC, DOS's COMMAND.COM. In the case of QB64, I would guess Windows's CMD.EXE.

COMMAND.COM and CMD.EXE have very similar commands, but they are not identical. Learn to use the command line, and then you will know how to use shell.

The command line shells implement "internal commands" like copy, cd, rd, md, rename, etc... There are also "external commands", which are really just external programs, like attrib and DOS's deltree.

Be advised that concepts like cut and paste are dependent on a clipboard. File management from the command line doesn't use a clipboard. Instead, you specify a source and destination.

In most cases, you can use the "/?" switch with a command to find out what it does. For example, typing "copy /?" will tell you the syntax for the copy command. Typing "help" can give you a list of some of the commands in Windows. For the DOS commands, you can get the "Help" program from:

ftp://ftp.microsoft.com/Products/Windows/Windows95/CDRomExtras/OtherUtilities/olddos.exe

which contains QBASIC, Help, and other DOS utilities.

Keep in mind that the Windows command prompt supports long file names, and spaces in the file names. It will often be necessary to use quotation marks around filenames and URLs.

The "<", ">", and ">>" are redirection commands. They redirect stdin or stdout. "|" is used to pipe the stdout of one program into the stdin of another. For example, "ipconfig /all|more" pipes the output of ipconfig to the input of more, which breaks it up into screen fulls.

Regards,
Michael

Posted on Jun 19, 2011, 1:30 AM

Respond to this message   

Return to Index


Multiple spaces

by Solitaire (no login)

The forum admin has no control over the formatting of spaces. This is a function of Network54.

To get multiple spaces, I use the Alt-255 combo for a hard space. To copy program code, I place it into a WORD document as a text file. Then replace all spaces with a hard space: Click on Edit/Replace. Enter a space on the upper textbox and ^s in the lower textbox. Then click on Replace All.

Posted on Jun 19, 2011, 8:56 AM

Respond to this message   

Return to Index


*Awesome, Thanks!

by Zack (no login)

Posted on Jun 19, 2011, 9:54 AM

Respond to this message   

Return to Index


* Note: You can alternate between Alt-255 and a regular space.

by Solitaire (no login)

Posted on Jun 19, 2011, 5:34 PM

Respond to this message   

Return to Index


No-Break Space

by (Login MCalkins)
Moderator

unicode: 0x00a0 (decimal 160)
windows-1252: 0xa0 (decimal 160)
cp437: 0xff (decimal 255)

This can be entered with Alt+255 or Alt+0160.

See:

http://en.wikipedia.org/wiki/Alt_code

for info on how to enable hex unicode entry.

Note that you can use a Qbasic program to automatically change spaces to cp437 0xa0, "á", and, since Notepad uses Windows-1252, they will be No-Break Spaces when you open it in Notepad.

Regards,
Michael

DIM i AS LONG
DIM b AS STRING * 1
OPEN "linear.bas" FOR BINARY AS 1
OPEN "---tmp.txt" FOR OUTPUT AS 2
CLOSE 2
OPEN "---tmp.txt" FOR BINARY AS 2
FOR i = 1 TO LOF(1)
GET 1, , b
IF ASC(b) = &H20 THEN b = CHR$(&HA0)
PUT 2, , b
NEXT i
CLOSE
SHELL "notepad ---tmp.txt"
SYSTEM



    
This message has been edited by MCalkins on Jun 19, 2011 3:22 PM

Posted on Jun 19, 2011, 3:21 PM

Respond to this message   

Return to Index


Help with little cursor ball thing

by Zack (no login)

Hey, I was messing around with DRAW and CIRCLE commands (just learned these) and thought it would be cool if I could get a little circle to follow your cursor around when your mouse is on the program screen. Of course, it didn't work the first time, and I am not sure what to do.

I tried this:

DO
IF _MOUSEINPUT THEN
CIRCLE (_MOUSEX, _MOUSEY), 5, 15
END IF
LOOP

but this left circles everywhere every time I moved the mouse

Then I tried this:
DO
IF _MOUSEINPUT THEN
currentx = _MOUSEX
currenty = _MOUSEY
IF oldx <> currentx AND oldy <> currenty THEN
CIRCLE (oldx, oldy), 5, 0
CIRCLE (currentx, currenty), 5, 15
END IF
oldx = currentx
oldy = currenty
END IF
LOOP

This worked a little better. It only left a few circles around. However, it only worked on a black screen; when I passed over text it left a black circle.

Is there a way to clear the old circle before it draws the new circle?

~Zack

Posted on Jun 16, 2011, 4:57 PM

Respond to this message   

Return to Index


It sounds like...

by AlGoreIthm (no login)


you need to use GET and PUT

good luck ...

Posted on Jun 16, 2011, 5:04 PM

Respond to this message   

Return to Index


does qb64 let you change the mouse cursor?

by (Login MCalkins)
Moderator

if so, maybe make the mouse cursor the circle? :-)

otherwise, what AlGoreIthm said is probably the way to go.

Regards,
Michael

Posted on Jun 16, 2011, 5:12 PM

Respond to this message   

Return to Index


Use _MOUSEHIDE

by Unseen Machine (no login)

Then you have no mouse pointer, you can put anything you want there!

SCREEN 12

_MOUSEHIDE
DO
CLS
DO: LOOP WHILE _MOUSEINPUT
CIRCLE (_MOUSEX, _MOUSEY), 15, 15
_DISPLAY
LOOP

Unseen

Posted on Jun 20, 2011, 4:55 AM

Respond to this message   

Return to Index


*I have a pair of mousehide shoes

by Sylvester (no login)

Posted on Jun 20, 2011, 8:31 AM

Respond to this message   

Return to Index


*Don't they squeak when you walk?

by (Login qb432l)
R

*

Posted on Jun 20, 2011, 10:23 AM

Respond to this message   

Return to Index


*Yeah they're pretty cheesy

by Sylvester (no login)

Posted on Jun 20, 2011, 11:37 AM

Respond to this message   

Return to Index


I meant actually use a custom cursor.

by (Login MCalkins)
Moderator

The DOS mouse driver would let you load a custom mouse cursor with Int 0x33, function 0x9.

It is also possible in the Windows API:

http://msdn.microsoft.com/en-us/library/ms648379%28v=VS.85%29.aspx

This puts the burden on the OS or mouse driver, which has been optimized for the purpose. It takes the burden off of your application.

Regards,
Michael

Posted on Jun 20, 2011, 3:26 PM

Respond to this message   

Return to Index


Use SDL

by Unseen (no login)

As QB64 is absed on it, and it also allows for swapping the pointer, i am sure with a small wrapper this function could be added. Also, if windows can do it, there's a good chance you can get QB64 to access the function in the API.

Posted on Jun 21, 2011, 4:16 AM

Respond to this message   

Return to Index


* "absed"? Abused? ..........based? ....... :-P

by (Login burger2227)
R

Posted on Jun 21, 2011, 2:48 PM

Respond to this message   

Return to Index


Yes, you have to save the old position to an array using graphical GET...

by (Login qb432l)
R

First, dimension an array:

DIM BGArray(5000) AS INTEGER 'probably bigger than you need...

Then before you draw your circle, use:

GET (currentx - 5, currenty - 5)-(currentx + 5, currenty + 5), BGArray

Now the background with whatever was there, including printing, is stored in the array. Then instead of erasing the white circle with a black circle, you merely PUT the background back to erase it:

IF oldx THEN PUT (oldx - 5, oldy - 5), BGArray, PSET

Don't forget the PSET, otherwise the background will just combine with the circle.

Good luck!
-Bob



    
This message has been edited by qb432l on Jun 16, 2011 5:29 PM

Posted on Jun 16, 2011, 5:14 PM

Respond to this message   

Return to Index


This still leaves marks around

by Zack (no login)

This still leaves marks if you move it slowly. Also when I move it towards the CloseX I got an Unhandled Error.

SCREEN 12
DIM BGArray(5000) AS INTEGER
DO
IF _MOUSEINPUT THEN
currentx = _MOUSEX
currenty = _MOUSEY
GET (currentx - 5, currenty - 5)-(currentx + 5, currenty + 5), BGArray()
IF oldx <> currentx OR oldy <> currenty THEN
IF oldx THEN
PUT (oldx - 5, oldy - 5), BGArray(), PSET
END IF
CIRCLE (currentx, currenty), 5, 15
END IF
oldx = currentx
oldy = currenty
END IF
LOOP

Posted on Jun 16, 2011, 5:42 PM

Respond to this message   

Return to Index


Yeah, you've got the GET in the wrong place...

by (Login qb432l)
R

You are getting the background after the circle has been drawn. Notice that in my version (below), I GET the BG immediately before drawing the circle. In any case, this is just the basic concept. In a finished program, you would begin by GETting the BG even before the loop, having first established the mouse's x/y. It would also be necessary to test for location before PUTting the BG, since you cannot PUT an image "offscreen". Anyway, I think you've got the hang of it in general. If you have any more questions, feel free to ask.

-Bob

'Copy code from here -----------------------------------------------

SCREEN 12
DIM BGArray(5000) AS INTEGER

_FULLSCREEN
_MOUSESHOW

LINE (5, 5)-(634, 474), 7, B
LOCATE 15, 32
COLOR 12
PRINT "BACKGOUND DETAIL"
LOCATE 17, 25
COLOR 10
PRINT "PRESS LEFT MOUSE BUTTON TO QUIT"

DO
IF _MOUSEINPUT THEN
currentx = _MOUSEX
currenty = _MOUSEY
lb = _MOUSEBUTTON(1)
IF oldx <> currentx OR oldy <> currenty THEN
IF oldx THEN PUT (oldx - 5, oldy - 5), BGArray(), PSET
GET (currentx - 5, currenty - 5)-(currentx + 5, currenty + 5), BGArray()
CIRCLE (currentx, currenty), 5, 15
END IF
oldx = currentx
oldy = currenty
END IF
LOOP UNTIL lb



    
This message has been edited by qb432l on Jun 16, 2011 7:25 PM
This message has been edited by qb432l on Jun 16, 2011 7:19 PM

Posted on Jun 16, 2011, 7:18 PM

Respond to this message   

Return to Index


Ok, thanks

by Zack (no login)

Awesome, Thanks! I have never used PUT and GET statements before, so I didn't know. But I guess that way does make more sense. You have to PUT it there before you can GET it. Anyway, thanks.

Posted on Jun 16, 2011, 7:28 PM

Respond to this message   

Return to Index


*change AND to OR

by (Login MCalkins)
Moderator

Posted on Jun 16, 2011, 5:16 PM

Respond to this message   

Return to Index


Need help with BAT file to run a QB program:

by (Login burger2227)
R

I was using a Qbasic program that I THINK only had the following in it:

SHELL "batfile.bat Qbasics.BAS"

Add _HIDE in QB64. It don't work either and will call M$!

It worked, but when I changed it to try to pass a numerical value it also worked

SHELL "batfile.bat 2"

NOW, I changed it back and NOTHING works! Did I forget something? Here's the BAT file:

Code:
@ECHO OFF
Title Q-Basic Library

echo %1

CD C:\Docume~1\Ted\Basic\

cmd /c start QB.EXE /RUN %~nx1 /L

Says file not found.

Change the path if you need to. It is supposed to run the other BAS program with QB.EXE

Ted

Posted on Jun 16, 2011, 3:17 PM

Respond to this message   

Return to Index


%~nx1

by (Login MCalkins)
Moderator

I'm not familiar with that usage, and it seems COMMAND.COM isn't either. It is probably CMD.EXE specific...

Either change %~nx1 to %1, or add "cmd.exe /c " to the SHELL line. It is not necessary to put "cmd /c " in the batch file.

You can observe what I mean by putting

echo %1
echo %~nx1
pause

in the bat file.

Another experiment:

Open a cmd window, and type "ver".

Result: "Microsoft Windows XP [Version 5.1.2600]"

Type "command", then type "ver".

Result: "Microsoft Windows XP [Version 5.1.2600]"

type "exit", type "qb", run:

SHELL

type "ver".

Result: "Microsoft Windows XP [Version 5.1.2600]"

type "exit", run:

SHELL "ver"

Result: "MS-DOS Version 5.00.500"

Another experiment:

Open a cmd window. Type "command", type "ver"

Result: "Microsoft Windows XP [Version 5.1.2600]"

type "exit", type "command /c ver"

Result: "MS-DOS Version 5.00.500"

Conclusion, when COMMAND.COM is called with no parameters, it acts like CMD.EXE (perhaps forwarding the stuff to CMD, perhaps CMD runs instead, or perhaps COMMAND implements it all itself?). If COMMAND.COM is called with parameters, it goes into old fashioned mode, and doesn't know what to do with "%~nx1".

Note that although you had "cmd /c " on the line inside the bat file, it is still "command.com" processing the bat file. "cmd /c " needs to be in the SHELL line, for cmd to process the bat file.

Regards,
Michael



    
This message has been edited by MCalkins on Jun 16, 2011 5:06 PM
This message has been edited by MCalkins on Jun 16, 2011 5:04 PM

Posted on Jun 16, 2011, 4:56 PM

Respond to this message   

Return to Index


CMD /C works, but

by (Login burger2227)
R

I didn't have that in the original command line before I changed it! It ran! QB64 supposedly doesn't need CMD /C in its command line either, but it fails too! All I did was change the file name to 2 and change it back and now it dosn't work.

I can drop BAS files directly into the batch file and it works. I can run the command line in another batch file and it works.

Here's the dope on the NEW command parameters for XP up:

Modifier Description
%~1 Expands %1 to path and filename. QB call shows filename only.
%~f1 Expands %1 to the fully qualified path with file name.
%~d1 Expands %1 to a drive letter without a \ slash. C:
%~p1 Expands %1 to a path with \ at both ends (NO Drive letter).
%~n1 Expands %1 to a file first name only.(No extension or dot)
%~x1 Expands %1 to the file extension only with the dot.
%~s1 Expands %1 to path with short DOS folder and file names only.
%~a1 Expands %1 to file attributes. --a------
%~t1 Expands %1 to date and time of file. 01/03/2011 01:23 PM
%~z1 Expands %1 to size of file. 1002
%~$PATH:1 Searches the directories listed in the PATH environment variable and
expands %1 to the fully qualified name of the first one found. If the
environment variable name is not defined or the file is not found, this
modifier expands to the empty string.

The following table lists possible combinations of modifiers and qualifiers that you can
use to get compound results.

Modifier Description
%~dp1 Expands %1 to a drive letter and path.
%~nx1 Expands %1 to a file name and extension.
%~snx1 Expands to short filename and extension.
%~dp$PATH:1 Searches the directories listed in the PATH environment variable for %1
and expands to the drive letter and path of the first one found.


IF "%PATH%" == "" GOTO NOPATH

:YESPATH
@ECHO The PATH environment variable was detected.
PATH=C:\DOS;%PATH%
GOTO END

:NOPATH
@ECHO The PATH environment variable was NOT detected.
PATH=C:\DOS;
GOTO END
:END

Note:In the previous examples, you can replace %1 and PATH with other
batch parameter values. The %* modifier is a unique modifier that
represents all arguments passed in a batch file.

Posted on Jun 16, 2011, 6:23 PM

Respond to this message   

Return to Index


*thanks for the info. that might be handy someday.

by (Login MCalkins)
Moderator

Posted on Jun 16, 2011, 8:19 PM

Respond to this message   

Return to Index


Prog Ramming Quick Basic

by zzzcat (no login)

Suppose You Have Two Associative And Commutative Binary Operations: A
And B. How Many Distinct Expressions Can Be Created If N x's Are
Combined Using These Operations.

Examples:
N=1: A(x) ; 1 Expressions
N=2: A(x,x), B(x,x) ; 2 Expressions
N=3: A(A(x,x),x) B(B(x,x),x) B(A(x,x),x) A(B(x,x),x) ; 4 Expressions
N=4: 10 Expressions

(Equivalently, How Many Circuts Can Be Created From N Identical Light
Bulbs If The Circut Components Can Be Combined Either In Series And In
Parallel And Each Circut Component Has 2 Terminals. In The Examples
Above, Suppose That A Represents Combining In Series And That B
Represents Combining In Parallel).

Write A Prog Ram In Quick Basic To Determine The Number Of Expressions
Given A User Input Of N.

Posted on Jun 12, 2011, 4:06 PM

Respond to this message   

Return to Index


That definately looks like a homework question....Ben? :-)

by (Login burger2227)
R

A teacher HAD to come up with that kind of assignment!

Why would ANYBODY ELSE care?... tongue.gif



    
This message has been edited by burger2227 on Jun 12, 2011 5:52 PM
This message has been edited by burger2227 on Jun 12, 2011 5:51 PM
This message has been edited by burger2227 on Jun 12, 2011 5:50 PM
This message has been edited by burger2227 on Jun 12, 2011 5:50 PM

Posted on Jun 12, 2011, 5:49 PM

Respond to this message   

Return to Index


Well I've actually solved it

by qbguy (no login)

DECLARE FUNCTION binom& (n&, k&)
DECLARE SUB seriesmul (a&(), b&(), n&)
DEFLNG A-Z
CLS
WIDTH 80, 43
CONST z = 25
DIM a(z), b(z)
FOR i = 0 TO z
a(i) = 1
NEXT
FOR k = 2 TO z
FOR i = 0 TO z: b(i) = 0: NEXT
FOR i = 0 TO z \ k - 1
b(i * k) = binom(a(k) + i - 1, i)
NEXT
CALL seriesmul(a(), b(), z)
NEXT
FOR i = 1 TO z
PRINT i, a(i)
NEXT

FUNCTION binom (n, k)
r = 1
IF k > n THEN binom = 0: EXIT FUNCTION
nn = n
FOR d = 1 TO k
r = r * nn
r = r / d
nn = nn - 1
NEXT
binom = r
END FUNCTION

SUB seriesmul (a(), b(), n)
DIM c(n)
FOR i = 0 TO n
FOR k = 0 TO i
c(i) = c(i) + a(k) * b(i - k)
NEXT
NEXT
FOR i = 0 TO n
a(i) = c(i)
NEXT
END SUB

Posted on Jun 13, 2011, 8:22 PM

Respond to this message   

Return to Index


* It is not very easy to see why this program solves the problem without comments

by qbguy (no login)

Posted on Jun 13, 2011, 8:25 PM

Respond to this message   

Return to Index


* Probably Mr. Obfuscation :-P

by (Login burger2227)
R

:-P

Posted on Jun 13, 2011, 10:31 PM

Respond to this message   

Return to Index


Well I guess I'll post the explanation now

by qbguy (no login)

DECLARE FUNCTION binom& (n&, k&)
DECLARE SUB seriesmul (a&(), b&(), n&)
DEFLNG A-Z
CLS

CONST z = 20
DIM a(0 TO z), b(0 TO z)

' Initializes a(0) and a(1) with correct values
' a(2) contains half of its final value of 2
' begins accumulating the correct coefficient in other array entries
FOR i = 0 TO z
a(i) = 1
NEXT

FOR k = 2 TO z
' At the beginning of the loop, a(k) is always equal to half of its final value
' The number of circuts is always even because you can change each parallel connection
' to a series connection and each series conection to a parallel connection


' binom(a(k) + i - 1, i) represents the number of ways to put i identical balls
' into a(k) boxes. The boxes correspond to possible circut components with k light bulbs
' and each ball is put in a box means that the circut component is used that many times

' If c(n) represents half of the final value of a(n) and n is represented in the form
' 1 * A + 2 * B + 3 * C + 4 * D + ... + n * N
' where A,B,C, etc. are all positive integers
' then there are binom(c(1)+A-1,A)*binom(c(2)+B-1,B)*binom(c(3)+C-1,C)*...*binom(c(n)+N-1,N)
' circuts consisting of a combination of subcircuts in series (each of which is
' itself a parallel combination of subcircuts) which have A components with 1 light bulb
' B components with 2 light bulbs, etc.

' The sum over all partitions of n is equal to a(n)

' We can calculate this sum by multiplying the series
' (1 + binom(c(1)+1-1,1)x + binom(c(1)+2-1,2)x^2 + ...) *
' (1 + binom(c(2)+1-1,1) x^2 + binom(c(2)+2-1,2) x^4 + ...) *
' (1 + binom(c(3)+1-1,2) x^3 + binom(c(3)+2-1,3) x^6) * ... etc.

'initialize coefficients
FOR i = 0 TO z: b(i) = 0: NEXT
FOR i = 0 TO z \ k
b(i * k) = binom(a(k) + i - 1, i)
NEXT

'multiply
CALL seriesmul(a(), b(), z)
NEXT

FOR i = 1 TO z
PRINT i, a(i)
NEXT

' This function calculates coefficient of x^k in (1+x)^n
' (or the number of ways to choose k different flavors of ice cream out of n possible flavors)
FUNCTION binom (n, k)
r = 1
IF k > n THEN binom = 0: EXIT FUNCTION
nn = n
FOR d = 1 TO k
r = r * nn
r = r / d
nn = nn - 1
NEXT
binom = r
END FUNCTION


' This function multiplies a() by b() and stores the result in a()
' a() and b() store the coefficients of power series; for example,
' a(0) is the constant term, a(1) is the coefficient of x, etc.
SUB seriesmul (a(), b(), n)
DIM c(0 TO n)
FOR i = 0 TO n
FOR k = 0 TO i
c(i) = c(i) + a(k) * b(i - k)
NEXT
NEXT
FOR i = 0 TO n
a(i) = c(i)
NEXT
END SUB

Posted on Jun 15, 2011, 5:16 PM

Respond to this message   

Return to Index


Music help? urgent, I'm 11.

by Luan (no login)

How do you set the volume on PLAY?
It's way too loud when I do it.
Please help me.

Posted on Jun 11, 2011, 4:24 AM

Respond to this message   

Return to Index


Depends on what version of QBASIC you are using

by qbguy (no login)

If you are using Quickbasic or QBASIC, change the volume setting for "System Beep" in the system's volume control.

If you are using QB64, use the _SNDVOL command: http://www.qb64.net/wiki/index.php?title=SNDVOL

Posted on Jun 11, 2011, 8:52 AM

Respond to this message   

Return to Index


System beep?

by (Login MCalkins)
Moderator

I don't recall seeing a setting for that. Which version of Windows does that work on?

On my XP computer, the PLAY music goes through the internal speaker, and is unaffected by the Windows volume control. I have seen some old computers that have a physical control for adjusting internal speaker volume.

The BEEP statement, on the other hand, plays a Windows sound, and is affected by Windows volume.

Unless the computer's hardware supports controlling the volume, I don't think there is any easy way of doing it. Perhaps by finely controlling the timing of the speaker, you can prevent it from fully extending the diaphragm.

Regards,
Michael

Posted on Jun 11, 2011, 11:33 AM

Respond to this message   

Return to Index


Are you using QB64?

by (Login burger2227)
R

Qbasic uses the built in PC speaker which may not exist in some computers.

QB64 uses V0 to V100 to control the volume from the sound card. Default is V50 or half loud.

Posted on Jun 11, 2011, 8:59 AM

Respond to this message   

Return to Index


No answer?

by Luan (no login)

I'm using a dell laptop, xp
The speaker volume has no effct, because qbasic uses the internal speker.
I us QBASIC.
I really need help.

Posted on Jun 11, 2011, 2:09 PM

Respond to this message   

Return to Index


You can't change the volume of the internal PC speaker.

by (Login rpgfan3233)

As you said, the speaker volume has no effect because QBasic uses the internal PC speaker. You can turn it on or off. Of course if you turn it off, you won't hear anything at all.

You can't change the volume of the internal PC speaker; you can only turn it on or off. Sorry. sad.gif

I recommend switching to QB64 since it lets you control the volume. You can download it at qb64.net, and you can find help with QB64 in the QB64 wiki as well as at these forums and at the QB64 forums.

Posted on Jun 11, 2011, 2:21 PM

Respond to this message   

Return to Index


Kk.

by Luan (no login)

Is QB64 the same as qbasic? As in, I won't have to learn a new programming language?

Posted on Jun 11, 2011, 3:54 PM

Respond to this message   

Return to Index


*Qb64 uses the same old keywords and has new features you don't have to use.

by (Login burger2227)
R

Posted on Jun 11, 2011, 3:56 PM

Respond to this message   

Return to Index


Hi Luan! Try using PLAY "v50cde" in QB64, "v50" means 50% volume

by Galleon (no login)

The whole purpose of QB64 is to be 100% compatible with QBASIC. It's more like 99.9% compatible really atm, but we are always working on closing that gap. You'll find the new commands added to QB64 really useful too.

Posted on Jun 12, 2011, 1:46 AM

Respond to this message   

Return to Index


Laptops can use the sound card but you can't change the volume.

by (Login burger2227)
R

My XP laptop uses the sound card to play the internal speaker sounds. You can't adjust the volume though.


wink.gif



    
This message has been edited by burger2227 on Jun 12, 2011 6:19 PM
This message has been edited by burger2227 on Jun 12, 2011 6:10 PM
This message has been edited by burger2227 on Jun 12, 2011 6:09 PM

Posted on Jun 12, 2011, 6:00 PM

Respond to this message   

Return to Index


*in that case, plug speakers into the headphone jack, and use the control on the speakers.

by (Login MCalkins)
Moderator

Posted on Jun 12, 2011, 6:15 PM

Respond to this message   

Return to Index


RGB on HTML

by (Login MarineDon)
R

Dear ALL

I have a question about RGB.

Back in January, I wrote a program called RGB.BAS.
It combined Red, Green and Blue to make a
mixed, combined RGB hue color. The three values
went from 0-63. My question is, how may I convert
these to HTML RGB so that I may use a it on a
web page.

Example of a green color on web page: bgcolor=rgb(0, 0, 255).

QB64 code:
http://www.smithselfgen.com/QuickBasic/RGB.BAS

DOWNLOAD RGB SETUP TO INSTALL ON COMPUTER WITH ICON:
http://www.smithselfgen.com/QuickBasic/RGBsetup.Exe


Regards, Don Smith


SCREEN SHOT:
[linked image]



    
This message has been edited by MarineDon on Jun 9, 2011 3:30 PM

Posted on Jun 9, 2011, 3:29 PM

Respond to this message   

Return to Index


Convert to hex and put a octothrope at the front

by qbguy (no login)

Example: #AABBCC = &HAA red, &HBB green, &HCC blue


In CSS you can use rgb(a,b,c):

e.g. <span style="color: rgb(255,0,0)">IF YOU PUT THIS IN A HTML FILE YOU SHOULD GET RED</span>

Posted on Jun 9, 2011, 3:55 PM

Respond to this message   

Return to Index


*Yes, Don, and don't forget to multiply your QB RGB values * 4 (0 - 255).

by (Login qb432l)
R

*

Posted on Jun 9, 2011, 4:11 PM

Respond to this message   

Return to Index


QB64 WIKI

by (Login burger2227)
R

Posted on Jun 9, 2011, 5:07 PM

Respond to this message   

Return to Index


Thanks

by (Login MarineDon)
R

Dear All:

The people on this forum are fabulous! I mean
the very best! They are conversant with all
manner of coding problems and are willing to
share their experience. Appreciate all your
help. I understand now.

Regards, Don Smith

Posted on Jun 9, 2011, 8:10 PM

Respond to this message   

Return to Index


using qb64 to make .cpp files from .bas files

by (no login)

I have a bunch of quick basic programs I want to convert to C++. I am no programmer, but some of the stuff I wrote in QB would be useful to others at work if it was in C++.

I got the sense that qb64 did just that, but all I seem to get with qb64 -c myprog.BAS is a .exe file. (Which successfully compiles and works very nicely, by the way. )

But, what I really want are the .cpp files I presume qb64 creates. is there an option to leave the .cpp file? If so, how do I do it? Couldn't seem to find much in FAQ or searchs. If this is a stupid question, I appologize. It just means I'm totally clueless and would love a point in the right direction. So, please don't flame me too bad, ok?

Posted on Jun 5, 2011, 11:10 PM

Respond to this message   

Return to Index


Re: using qb64 to make .cpp files from .bas files

by (Login MCalkins)
Moderator

You don't usually have to worry about being flamed on this forum. This forum is generally quite tame. There is a talking paper clip who occasionally uses uppercase and exclamation points, but don't take it personally. :-)

I'd say that if you've written anything useful in QB, you are a programmer.

I'm not involved in the QB64 project, but I think that the C++ code it generates is meant to be only an intermediate stage. My guess is that it would be clunky from the perspective of anyone actually wanting to modify it. Keep in mind that QB64 programs depend on SDL.

If the programs are small, it might be better to convert them by hand. I would say that a decent C++ programmer, even without much prior experience with QBASIC, should be able to figure out the operation of the program, and translate it manually. QBASIC code is somewhat self explanatory, more so than C/C++, because it uses pseudo English like "END IF" instead of punctuation like "}".

There are a few guys here who know both QBASIC and C++. I don't want to speak for them, but they *might* be interested in helping you convert the programs, if they are small. I'm very inexperienced with C++, but I *might* take a stab at it with a small enough program, although I would rather translate to C instead of C++.

Regards,
Michael

Posted on Jun 6, 2011, 8:33 AM

Respond to this message   

Return to Index


C programmers should already know how to convert them

by (Login burger2227)
R

Since you are NOT a programmer, let them worry about it. QB64 was not meant to be a Qbasic to C++ converter, but somebody who IS familiar with C could probably find what they need as it is saved somewhere.

Here is the code to check for compiler errors. Tell them to find the path:

http://qb64.net/wiki/index.php?title=QB64_FAQ#Q:_How_can_I_find_what_caused_a_Compiler_error.3F

Posted on Jun 6, 2011, 8:53 AM

Respond to this message   

Return to Index


Fully tabbed file manager for DOS

by Ben (no login)

This program lets you manage your DOS files in a fully tabbed graphical environment.

download:
http://qbasic.orgfree.com/dgui4.zip

screenshots:
http://qbasic.orgfree.com/gui_001.png
http://qbasic.orgfree.com/gui_002.png

Posted on Jun 5, 2011, 10:59 PM

Respond to this message   

Return to Index


Took me three hours

by Ben (no login)

It was a long programming session. One thing to note, at one point I was looking at the code for a few minutes, and then I decided to change a greater than symbol to a less than symbol. And as soon as I did that, for a few seconds the entire QB IDE & monitor flipped upside down and I couldn't read anything. I was a bit scared after this happened, anyone else get this?

Posted on Jun 5, 2011, 11:24 PM

Respond to this message   

Return to Index


Graphics card utility...

by (Login MCalkins)
Moderator

I don't know what hardware and utilities you have, but I have "Intel Graphics Media Accelerator Driver for mobile" on mine. In the "Graphics Properties", under "Hot Keys", there is a check box to "Enable Hot Keys", which I disabled on mine. If it's enabled, the Ctrl+Alt+arrowKeys change the rotation of the display. It was interfering when I was playing Heretic.

Regards,
Michael

Posted on Jun 6, 2011, 8:01 AM

Respond to this message   

Return to Index


it looks like a good start

by (Login MCalkins)
Moderator

are you going to add the ability to copy or move groups of files and folders?

I didn't notice any tabbed capability. how do you switch tabs?

It didn't seem to allow scrolling when viewing files.

When you click ".." it adds ".." to the path, which takes you up a level, but the path string just keeps getting longer and longer...

Regards,
Michael

Posted on Jun 6, 2011, 9:18 AM

Respond to this message   

Return to Index


it's fully tabbed

by Ben (no login)

To open a folder in a new tab, hold down the CTRL key, then click on it. TXT & BAS files automatically open in a new tab. Press 'Q' on your keyboard to close a tab. You switch tabs by clicking on the boxes at the top. The active one is highlighted in yellow. Every tab will save your scroll position.

The ".." will be fixed with some string parsing when I decide to do so. Things such as copy, move, delete can be easily implemented and intertabbed as all the necessary information is stored in memory.

Text files will eventually be given the ability to be edited, scrolled, etc.

Posted on Jun 6, 2011, 10:47 AM

Respond to this message   

Return to Index


*cool.

by (Login MCalkins)
Moderator

Posted on Jun 6, 2011, 11:04 AM

Respond to this message   

Return to Index


*I've partially implemented such file selection

by Ben (no login)



    
This message has been edited by MCalkins on Jun 11, 2011 11:24 AM
This message has been edited by MCalkins on Jun 11, 2011 11:23 AM

Posted on Jun 11, 2011, 10:50 AM

Respond to this message   

Return to Index


Problem with Global IP address in QB64 fixed!

by (Login burger2227)
R

It appears that the IP verification site that QB64 uses changed their link so if you get incorrect readings use the fix at following link:

http://www.qb64.net/forum/index.php?topic=3614.msg35387#new

This affects the _CONNECTIONADDRESS IP string returned.

Ted



    
This message has been edited by burger2227 on May 31, 2011 3:03 PM

Posted on May 31, 2011, 2:16 PM

Respond to this message   

Return to Index


Help with Prog Ramming

by mrpotatoehead (no login)

Write a program to find the nth fibonacci number.

note: the "zeroth" fibonacci number is 0, the first fibonacci number is 1, the second fibonacci number is 2, and the every fibonacci number is the sum of the previous two fibonacci numbers.

Posted on May 31, 2011, 1:21 PM

Respond to this message   

Return to Index


* O sorry the 2nd fibonacci # is 1 not 2

by mrpotatoehead (no login)

Posted on May 31, 2011, 1:28 PM

Respond to this message   

Return to Index


* SOOOOOOOOO. DO IT! You got it all figured out

by (Login burger2227)
R

Posted on May 31, 2011, 1:53 PM

Respond to this message   

Return to Index


I couldn't resist.

by (Login MCalkins)
Moderator

However, I am rather tired, so please excuse any goofiness in the code.

If you want actual help, read the homework policy link, try to do it yourself, and then let us know what specifically you need help with.

Regards,
Michael

----------

;public domain, may 2011, michael calkins
;assemble with:
; nasm -o homew2.com homew2.asm

cpu 386
org 0x100

_homework:

;display message and get input:
mov dx,_msg
mov ah,0x9
int 0x21
mov dx,_inbuf
mov ah,0xa
int 0x21
mov dx,_outbuf
mov ah,0x9
int 0x21

;read decimal string
xor ax,ax
xor dx,dx
mov si,_inbuf+0x2
xor ch,ch
mov cl,[_inbuf+0x1]
test cx,cx
jz .sk0
mov bx,0xa
.lp0:
mov dl,[si]
sub dl,0x30
add ax,dx
sub cl,0x1
jz .sk0
mul bx
inc si
jmp .lp0
.sk0:

;fibonacci calculation
mov cx,ax
mov edx,0x1
xor eax,eax
test cx,cx
jz .sk1
.lp1:
mov ebx,eax
add ebx,edx
mov edx,eax
mov eax,ebx
loop .lp1
.sk1:

;display decimal number
mov di,_outbuf
mov ebx,0xa
.lp2:
dec di
xor edx,edx
div ebx
add dl,0x30
mov [di],dl
test eax,eax
jnz .lp2
mov dx,di
mov ah,0x9
int 0x21
int 0x20

_inbuf:
db 0x3
dd 0x0
_msg:
db "(Note: input is not checked for correctness.)",0xd,0xa
db "Enter a decimal unsigned integer below or equal to 47: $"
_outbuf:
db 0xd,0xa,"$"

Posted on May 31, 2011, 4:36 PM

Respond to this message   

Return to Index


There is a better (worse) way...

by qbguy (no login)

The number of n-bit numbers (where leading zero bits are allowed) with no consecutive 1 bits is equal to the n+2 nd fibonacci number.

Proof:
Clearly, there is only 1 zero-bit number, and all 2 1-bit numbers clearly have no consecutive 1-bits. The number of 2-bit numbers with no consecutive 1-bits is 3. If f(n) is the number of n-bit numbers with no consecutive numbers with no consecutive 1-bits, then the f(n) numbers consist of f(n-2) numbers with low bit 1 and f(n-1) with low bit 0, i.e. f(n) = f(n-1) + f(n-2)

So you can calculate the nth fibonacci number by testing (X XOR 2*X) XOR (X + 2*X) in a loop (no consecutive bits means no carries, meaning that the expression's value is zero).

This method is espescially useful when it is programmed in ASM because you can say "This program should be fast since it's written in ASM".

Posted on May 31, 2011, 6:35 PM

Respond to this message   

Return to Index


okay, qbguy...

by (Login MCalkins)
Moderator

It is clear that I am not a mathematician... :-P

Even using assembly, this is slow. It could probably be optimized a little, but I am not an optimization expert.

By the way, coding this is fairly straight forward in QBASIC, partly because of the way QBASIC handles (2 ^ (n - 2)) - 1. It is calculated as floating point, and then CINT is implicitly applied, so that -.75 becomes -1, and -.5 becomes 0. I haven't learned assembly floating point (x87 FPU) yet, but I intend to in the future. So far, all of my assembly programs just use integers.

The program below prepares a number to be used as an upper limit. This is basically 2 ^ (n - 2), but with special handling for n=0 and n=1. I use bitwise shift left instead of exponentiation. I say "upper limit" for lack of a better phrase. It is actually excluded; the numbers tested in the loop start at 0, and go up to, but don't include, that number.

Regards,
Michael

----------

;public domain, june 2011, michael calkins
;assemble with:
; nasm -o homew3.com homew3.asm

cpu 386
org 0x100

_homework:

;display message and get input:
mov dx,_msg
mov ah,0x9
int 0x21
mov dx,_inbuf
mov ah,0xa
int 0x21
mov dx,_outbuf
mov ah,0x9
int 0x21

;read decimal string
xor ax,ax
xor dx,dx
mov si,_inbuf+0x2
xor ch,ch
mov cl,[_inbuf+0x1]
test cx,cx
jz .sk0
mov bx,0xa
.lp0:
mov dl,[si]
sub dl,0x30
add ax,dx
sub cl,0x1
jz .sk0
mul bx
inc si
jmp .lp0
.sk0:

;prepare limit for fibonacci calculation loop
mov cl,al
xor eax,eax
sub cl,0x2
jns .sk1
add cl,0x1
jns .sk1
dec al
.sk1:
inc al
shl eax,cl

;fibonacci calculation
xor esi,esi
xor ecx,ecx
.lp1:
cmp esi,eax
jnb .sk2
mov ebx,esi
mov edx,esi
shl ebx,0x1
xor edx,ebx
add ebx,esi
inc esi
xor edx,ebx
jnz .lp1
inc ecx
jmp .lp1
.sk2:

;display decimal number
mov eax,ecx
mov di,_outbuf
mov ebx,0xa
.lp2:
dec di
xor edx,edx
div ebx
add dl,0x30
mov [di],dl
test eax,eax
jnz .lp2
mov dx,di
mov ah,0x9
int 0x21
int 0x20

_inbuf:
db 0x3
dd 0x0
_msg:
db "(Note: input is not checked for correctness.)",0xd,0xa
db "Enter a decimal unsigned integer below or equal to 33: $"
_outbuf:
db 0xd,0xa,"$"



    
This message has been edited by MCalkins on Jun 1, 2011 1:42 PM

Posted on Jun 1, 2011, 1:37 PM

Respond to this message   

Return to Index


Binet's Formula

by lawgin (no login)

Put into words:

The nth Fibonacci number is equal to one half of one plus the square root of five to the nth power minus one half of one minus the square root of five to the nth power all divided by the square root of five.

Translate this into qbasic and you have your solution.

Posted on Jun 1, 2011, 10:57 AM

Respond to this message   

Return to Index


*LOL! I love it!

by Solitaire (Login Solitaire1)
S

Posted on Jun 1, 2011, 9:50 PM

Respond to this message   

Return to Index


nth...

by (Login MCalkins)
Moderator

I would argue that, in a sequence, there is no such thing as "zeroth", but there is such a thing as position 0. So, for example, position 0 is the first position, position 1 is the second position, position 2 is the third position, and so on...

So that where f(n) is the fibonacci number in position n:

position n, relative, f(n)
0, 1st, 0
1, 2nd, 1
2, 3rd, 1,
3, 4th, 2
4, 5th, 3
5, 6th, 5
6, 7th, 8
7, 8th, 13
8, 9th, 21

etc...

Anyway, have you looked at the Wikipedia article for fibonacci numbers?

http://en.wikipedia.org/wiki/Fibonacci_number

It has a lot of information, most of which is way over my head. However, you'll find the formula Lawgin mentioned there.

One easy way of calculating fibonacci numbers is just to add them up. Just calculating them can be done with 3 variables. You would need 1 more variable to track the current position.

Basically, imagine 4 variables. You could call them "L" for left, "M" for middle, "R" for right, and "C" for count (I would make them lowercase, but they are uppercase here for readability). Basically, you will be working inside a loop, where R is the number you are trying to calculate, M is the number you just calculated, and L is the number you calculated before that. The initial value of L would be 0, and the initial value of M would be 1. Obviously, R will be L + M. Now, before you loop, you need to shift your position. So, L needs to be assigned the value of M, and M needs to be assigned the value of R. Then you would loop. At the beginning of the loop, you can check the count, C, against your target number, and break out of the loop if necessary, at which point L holds the correct result.

Doing it that way will allow you to get results up to and including f(45) within the limits of qbasic's LONG data type (signed long integer). If you change it so that the initial value of L is 1, and the initial value of M is 0, and you consider M to be the result when you break out of the loop, then you can get results up to and including f(46) within the limits of qbasic's LONG data type. The assembly program I posted in the "I couldn't resist" post used this method with an unsigned long integer data type to get results up to and including f(47). You could use qbasic's DOUBLE data type (double precision floating point) to get even bigger results, but at some point you will run into precision issues. (I believe when the numbers exceed 2^52).

Regards,
Michael



    
This message has been edited by MCalkins on Jun 1, 2011 2:51 PM
This message has been edited by MCalkins on Jun 1, 2011 2:50 PM

Posted on Jun 1, 2011, 2:46 PM

Respond to this message   

Return to Index


In .NET everything is zero-based, so the first position is the zeroth index.

by Solitaire (Login Solitaire1)
S

This makes for a lot of confusion, with numerous opportunities for "off-by-one" errors.

 

Posted on Jun 1, 2011, 9:55 PM

Respond to this message   

Return to Index


Re: In .NET everything is zero-based, so the first position is the zeroth index.

by (Login MCalkins)
Moderator

I think most languages start with 0, and this is natural, as the hardware also starts with 0. To start addressing at anything other than 0 would be difficult and unnatural. Assembly is basically a representation of machine instructions, so naturally, addressing in assembly programs starts at 0. C and C++ also start at 0. Array addressing in QBASIC starts at 0 by default, although it can optionally be made to start at 1.

Just looking through a few definitions of "first" on the internet, I've seen some that I like, and some that I don't like or understand. Anything dealing with the mathematical concepts of ordinal and cardinal numbers, I don't understand. I would prefer to speak in terms of positions in a sequence.

I would define "first" as the initial item in the sequence, the one that precedes any other. That is what I mean and think of when I say or hear "first".

Using that definition, the "first" item will be the initial one, no matter what its value.

So, just as an example, if you had a sequence of odd numbers starting at 5:

5, first
7, second
9, third
11, fourth
13, fifth
15, sixth
17, seventh
etc...

So, if you had a sequence of byte memory addresses (or offsets) starting at 0:

0, first
1, second
2, third
3, fourth
4, fifth
5, sixth
6, seventh
etc...

0 is "first" because it is the initial item in the sequence. No item precedes it. By that definition, there is no room in the sequence for "zeroth". To me, "zeroth" would imply perhaps something that isn't in the sequence.

So, if you had an array (a sequence), of odd numbers starting with 5, you would address the array starting with the "first" element (item) having an index of 0.

value, "nth" position, index:
5, first, 0
7, second, 1
9, third, 2
11, fourth, 3
13, fifth, 4
15, sixth, 5
17, seventh, 6

On the Wikipedia article:

http://en.wikipedia.org/wiki/Zero-based_numbering

It says:

"Under zero-based numbering, the initial element is often termed the "zeroth" element, rather than the first element; "zeroth" is a coined ordinal number corresponding to the number zero. In some cases, an object or value that does not (originally) belong to a given sequence, but which could be naturally placed before its initial element, may be termed the zeroth element. The correctness of using zero as an ordinal is not universally agreed upon as it creates ambiguity for all subsequent elements of the sequence when lacking context."

Later, it says:

"In this context using "zeroth" as an ordinal is not strictly correct, but professional shorthand."

In reference to "In some cases, an object or value that does not (originally) belong to a given sequence, but which could be naturally placed before its initial element, may be termed the zeroth element.", that is what I would take "zeroth" to mean. That is what I took it to mean in the original post, until I realized that 0 actually is part of the fibonacci sequence, and therefore should be considered "first".

In reference to "Under zero-based numbering, the initial element is often termed the "zeroth" element, rather than the first element; "zeroth" is a coined ordinal number corresponding to the number zero." and "In this context using "zeroth" as an ordinal is not strictly correct, but professional shorthand.", I argue that such usage is incorrect.

Regards,
Michael



    
This message has been edited by MCalkins on Jun 2, 2011 11:43 AM

Posted on Jun 2, 2011, 5:59 AM

Respond to this message   

Return to Index


* Why 0? Because the first register bit is Binary 1 = 2 ^ 0

by (Login burger2227)
R

Posted on Jun 2, 2011, 9:33 AM

Respond to this message   

Return to Index


Well, that's one reason.

by (Login MCalkins)
Moderator

And decimal is the same way. The first place in the decimal system is the ones place, 10^0. (Also, hexadecimal: 16^0).

It is the way modern number systems work. 0 is the lowest value possible for any particular place in the common number systems (decimal, binary, hexadecimal, even octal). It is not the case in the Roman number system (I, II, III, etc.), which doesn't use place values.

If, for example, you wanted to select a range of numbers based on place, you would use a mask (a bit mask, in binary). Doing so makes sense because the numbers start at zero.

Last year, when I was still in the volunteer fire department, I was in charge of numbering tickets for a fund raiser dinner, and distributing them to other members, who in turn would sell them to the public. In previous years, the tickets were numbered starting at 1, and distributed in groups of 10: 001-010, 011-020, 021-030, 031-040, ..., 091-100, 101-110, 111-120, etc... (where "-" means "to") Does that even make sense? That is how the years are numbered, but that causes confusion, doesn't it, with people calling the year 2000 the start of the millennium. (2000 was the end of the 2nd millennium; 2001 was the start of the 3rd millennium.) The year that I had a say about it, the tickets were numbered starting at 0: 000-009, 010-019, 020-029, ..., 090-099, 100-109, 110-119, etc... I'd say that is a much more natural way of doing it, but oddly enough, the other members tended not to see it that way, even arguing that, for example, 311-320 seemed more natural than 310-319. Go figure...

I think I've read somewhere that computer programmers have been known to, for example, push the "3" button on an elevator when they mean to go to the fourth floor... It would be more consistent, wouldn't it, if more things in life started at 0?

Considering the way computers store integers, would it be reasonable to start the number system at 1? Would you say that binary "00000000" ought to be given a value of 1? That would be like saying that decimal "000" should be given a value of 1. Then what would binary "00000001" be? Would it be 2? So, 0 is the reasonable place to start. That is how computers work. Binary "00000000" to "01111111" is 0 to 127. x86 computers use "two's compliment" to store negative numbers, so "10000000" to "11111111" could be 128 to 255, or, -128 to -1, depending on whether the byte is unsigned or signed. This scheme works very well.

Since integers stored in computers start with 0, it is natural that memory addresses, which are stored as integers, also start at 0.

A good reason to start arrays at index 0 is that if you want to access an element of a two dimensional array, the offset address of that element is easy to calculate:
row major: sizeofelement * (x + (y * numberofxelements))
column major: sizeofelement * (y + (x * numberofyelements))

The formula would be more complicated if you were to start your indexing at 1:
row major: sizeofelement * ((x - 1) + ((y - 1) * numberofxelements))
column major: sizeofelement * ((y - 1) + ((x - 1) * numberofyelements))

Starting your array indexing at anything other than 0 means one otherwise unnecessary addition or subtraction for each dimension of the array.

Regards,
Michael

Posted on Jun 2, 2011, 11:42 AM

Respond to this message   

Return to Index


Also...

by (Login MCalkins)
Moderator

2011 is in the 21st century, not the 20th century, because 11 was in the 1st, not the "zeroth", century. Even though the years started with 1, the centuries effectively started with 0.

2011 is the 2011th year; it is in the 21st century; it is in the 3rd millennium. Had the years started with 0, then 2011 would be the 2012th year (and 2000 would have been the start of the third millennium, instead of 2001).

Thank goodness for modern positional number systems instead of archaic Roman number systems! :-D

Regards,
Michael



    
This message has been edited by MCalkins on Jun 2, 2011 1:05 PM
This message has been edited by MCalkins on Jun 2, 2011 12:03 PM
This message has been edited by MCalkins on Jun 2, 2011 12:03 PM
This message has been edited by MCalkins on Jun 2, 2011 12:03 PM
This message has been edited by MCalkins on Jun 2, 2011 12:02 PM
This message has been edited by MCalkins on Jun 2, 2011 11:59 AM

Posted on Jun 2, 2011, 11:52 AM

Respond to this message   

Return to Index


Yeah, lots of confusion there...

by (Login qb432l)
R

I've heard people say, "since there was no zero year, the 3rd millennium began in the year 2001". But of COURSE there is no zero year, since calendars don't count/add time, they designate periods of time. For example, the first day of the week, the first year of the 21st century, etc..

For purposes of counting, the first year IS the zero year, as in: a baby turns zero years and three months of age in his first year. The clock says three months, the calendar says first year. Of course, the calendar then notes that the fourth month of the baby's life has begun, but the clock says three months and one day, three months and two days, etc..

My two,
-Bob

P.S. Solitaire, I loved the word "zeroth"!

Posted on Jun 2, 2011, 12:16 PM

Respond to this message   

Return to Index


* I think that the Japanese start with 1 year old when they are born...

by (Login burger2227)
R

Posted on Jun 2, 2011, 12:33 PM

Respond to this message   

Return to Index


I believe that Chinese babies are age 1 at birth.

by Solitaire (Login Solitaire1)
S

I guess it means they are starting their first year.

Posted on Jun 2, 2011, 5:38 PM

Respond to this message   

Return to Index


*I've been in favor of January becoming month #0.

by (Login MCalkins)
Moderator

Posted on Jun 2, 2011, 1:12 PM

Respond to this message   

Return to Index


* OPTION CALENDAR BASE 0 :-P

by (Login burger2227)
R

Posted on Jun 2, 2011, 1:32 PM

Respond to this message   

Return to Index


*You'd swear this was a programmer's forum!

by (Login qb432l)
R

*

Posted on Jun 3, 2011, 4:17 AM

Respond to this message   

Return to Index


* Yeah, a lot of lonely programmers...

by (Login burger2227)
R

Posted on Jun 3, 2011, 11:17 AM

Respond to this message   

Return to Index


"first" can be relative...

by (Login MCalkins)
Moderator

as in "first from the left" or "first from the right" when describing people in a photo.

Likewise, "first century AD" or "first century BC" are relative to the agreed upon start point.

If you were to number the floors of a building like so:

-2: sub basement
-1: basement
0: ground floor
1: floor above ground floor
2: floor above that
3: floor above #2
etc...

Which one is the first floor? Is it the ground floor, #0? According to what I said in the other post, the first floor would be -2, the sub basement. However, you could use the word "first" in a relative sense: "first floor from the ground" (#0), "first floor above the ground" (#1), "second floor up from the ground" (#1), "first floor below ground" (-1), "second floor up from #2: " (#3), "second floor above #2: " (#4), etc... But unless so qualified as being relative, I would say that "first" should default to its absolute meaning of the first in the sequence (#-2). Also, using it in a relative way would leave quite a bit of room for confusion unless it is made very clear what it is counted from.

I guess I've gotten a little off topic. This stuff might have been better in distractions, but it started as a response to the original post... :-P

Regards,
Michael



    
This message has been edited by MCalkins on Jun 2, 2011 12:33 PM

Posted on Jun 2, 2011, 12:31 PM

Respond to this message   

Return to Index


* What's a Prog?

by (Login burger2227)
R

Posted on Jun 4, 2011, 12:02 AM

Respond to this message   

Return to Index


I don't know but I think it is a small animal

by qbguy (no login)

Like a frog or a rabbit. Maybe even a cross between a frog and a rabbit. Something like that.

Posted on Jun 4, 2011, 9:43 AM

Respond to this message   

Return to Index


Re: I don't know but I think it is a small animal

by (Login burger2227)
R

[linked image]

Posted on Jun 5, 2011, 10:20 AM

Respond to this message   

Return to Index


Attention Mods: Get that jackass off the forum!

by (Login The-Universe)
Admin


And while you guys are at it, someome remove the picture of the donkey, too. happy.gif

Pete

[linked image]

Posted on Jun 5, 2011, 10:01 PM

Respond to this message   

Return to Index


Don't you mean tea potty?

by (Login burger2227)
R

happy.gif
BEFORE:
[linked image]

AFTER
[linked image]



    
This message has been edited by burger2227 on Jun 6, 2011 4:34 PM

Posted on Jun 5, 2011, 10:32 PM

Respond to this message   

Return to Index


I assume you're joking.

by (Login MCalkins)
Moderator

especially since you could have deleted it yourself, and didn't.
Regards,
Michael

Posted on Jun 6, 2011, 8:46 AM

Respond to this message   

Return to Index


* Did you see the potty "praying"? :-P

by (Login burger2227)
R

Posted on Jun 6, 2011, 9:43 AM

Respond to this message   

Return to Index


I saw it. I'm not sure what to make of it... (url)

by (Login MCalkins)
Moderator

(some content removed 2013 03 13 - mc)

P.S.

Pete: you might want to delete this post after both clippy and you have seen it. It's up to you.



    
This message has been edited by MCalkins on Mar 12, 2013 11:04 PM
This message has been edited by MCalkins on Jun 6, 2011 11:25 AM
This message has been edited by MCalkins on Jun 6, 2011 11:09 AM
This message has been edited by MCalkins on Jun 6, 2011 10:27 AM
This message has been edited by MCalkins on Jun 6, 2011 10:25 AM

Posted on Jun 6, 2011, 10:23 AM

Respond to this message   

Return to Index


Go Sarah!

by (Login The-Universe)
Admin

And isn't that the same can Obama used in his '08 slogan?

Hey, she wishes her calves were that skinny. My bet is someone photoshopped her head on Calista Flockhart.

Anyway, lucky for us "comodians," these things, distasteful to some as they may be, are well protected under the law of Free Speech.

Just don't anyone post any pics or links of Congress-half-a-man Weiner. I'll be happy to delete him; although the House is about to do that for me.

Pete



Posted on Jun 6, 2011, 4:20 PM

Respond to this message   

Return to Index


* You can tell that her hair isn't quite right... :-)

by (Login burger2227)
R

Posted on Jun 6, 2011, 4:36 PM

Respond to this message   

Return to Index


* And now back to our regularly scheduled QB discussion topics.

by (Login The-Universe)
Admin

Posted on Jun 6, 2011, 10:20 PM

Respond to this message   

Return to Index


like most things we've done it already

by david (no login)

http://www.network54.com/Forum/202193/message/1209728350/Direct+calculation

I often wonder why the homework cheats do not search the archive.

Posted on Jun 12, 2011, 9:01 AM

Respond to this message   

Return to Index


* Because they are THAT LAZY! :-)

by (Login burger2227)
R

Posted on Jun 12, 2011, 10:26 AM

Respond to this message   

Return to Index


Attention All Personnel... Good posts lately

by Radar (Login The-Universe)
Admin


That, and since the forum has a low spam count, I don't have to use protection when visiting.

QB64.net had a high spam count for awhile, and because of that, we got saddled with an off-spring. We call him Clippy. happy.gif

Anyway, kidding aside, that's to the moderators for keeping the place in great shape. Thanks to the regulars who keep the place going, and thanks to the new comers and those who pass by to ask questions about QB or QB64.

I would also like to thank Rob (AKA Galleon) for QB64, which lets our beloved QB program live on in Windows 7, Linux, and Mac operating systems. I told Mac once in chat that I had a weird feeling about this guy, that he could actually pull it off, and he did.

June is forum renewal month and for those who may be wondering, I will be keeping the forum ad free for another renewal period.

Pete

Posted on May 27, 2011, 7:58 PM

Respond to this message   

Return to Index


* You are welcome! And Thanks to you too! :-)

by (Login burger2227)
R

Posted on May 27, 2011, 8:32 PM

Respond to this message   

Return to Index


*Great news! Thanks, Pete!

by (Login qb432l)
R

*

Posted on May 27, 2011, 9:24 PM

Respond to this message   

Return to Index


*Thank you Pete. Great job.

by Solitaire (no login)

Posted on May 28, 2011, 2:44 AM

Respond to this message   

Return to Index


I've got a funny feeling about me too...

by Galleon (no login)

I think I ate too much pizza today, but I always byte off[set] more than I can chew. Thanks to your support and community support QB64 has become a success, and it just keeps getting better.

Posted on May 28, 2011, 4:20 AM

Respond to this message   

Return to Index

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement