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



About pixel coordinates in programming languages

by (no login)

Is there anyway to change the pixel coordinates on the screen to look more like a standard Cartesian graph? instead of (0,0) being at the top left, is there a way to put it in the center? or is there some formula which translates a Cartesian coordinate to a pixel coordinate? Also, is there any reason that pixel coordinates are not the same as Cartesian coordinates?

Posted on May 15, 2012, 1:48 PM

Respond to this message   

Return to Index


* WINDOW can be used for Cartesian y coordinates

by (Login burger2227)
R

Posted on May 15, 2012, 4:32 PM

Respond to this message   

Return to Index


the simplest way (besides using WINDOW)

by stosb (no login)

is to add/subtract some horizontal & vertical offset from your coordinates. For example:

'''''''''''''''''

SCREEN 12
DIM SHARED CENTERX, CENTERY
CENTERX = 320
CENTERY = 240

DRAWAXES 7
CIRCLEX 0, 0, 100, 15
R = 100 * COS(45 * 3.14159 / 180)
FOR X = 0 TO R
PSETX X, X, 7
NEXT X
LINEX R, R, R, 0, 4

SUB PSETX (X, Y, C)

PSET (CENTERX + X, CENTERY - Y), C

END SUB

SUB DRAWAXES (C)

LINE (CENTERX, 0)-(CENTERX, CENTERY * 2), C
LINE (0, CENTERY)-(CENTERX * 2, CENTERY), C

END SUB

SUB CIRCLEX (X, Y, R, C)

CIRCLE (CENTERX + X, CENTERY - Y), R, C

END SUB

SUB LINEX (X1, Y1, X2, Y2, C)

LINE (CENTERX + X1, CENTERY - Y1)-(CENTERX + X2, CENTERY - Y2), C

END SUB

Posted on May 15, 2012, 6:44 PM

Respond to this message   

Return to Index


Re: the simplest way (besides using WINDOW)

by (no login)

Oh..so basically you would create a center coordinate (origin) then add your x value and subtract your y? I think i get it now...Thanks.

Posted on May 15, 2012, 7:04 PM

Respond to this message   

Return to Index


*yep, that's all there is to it!

by stosb (no login)

Posted on May 15, 2012, 7:06 PM

Respond to this message   

Return to Index


a further note

by stosb (no login)

One may wonder why the top left part of the screen was chosen as (0,0). Well it's simple really. Back in the days of CRT monitors, the electron beam would scan from left to right, and top to bottom, 1 row at a time. So the upper left corner of the screen was the first part scanned, and the lower right corner was the last part. The VGA video memory is located at segment &hA000 (that's A000 in hexadecimal), and it was easiest to load the memory in order, so that the first byte was the first pixel drawn on the screen. So byte [A000:0000] became coordinate (0,0) at the top left, byte [A000:0001] was the second pixel (assuming 1 byte per pixel, like in mode 13h), etc. Basically it was done to make things fast & easy with older technology.

Posted on May 15, 2012, 7:11 PM

Respond to this message   

Return to Index


* Only problem with your theory is that they STILL do it that way!

by (Login burger2227)
R

Posted on May 16, 2012, 2:08 AM

Respond to this message   

Return to Index


*i never said they stopped... lol... programmers are sentimental, right? :)

by stosb (no login)

Posted on May 16, 2012, 5:15 PM

Respond to this message   

Return to Index


*actually it's to make software backward-compatible

by stosb (no login)

Posted on May 16, 2012, 5:23 PM

Respond to this message   

Return to Index


Updated Assignment

by Matt (no login)

Michael,
Thanks again, Just wanted to share the final product. I'm sure it isn't perfect and could use MASSIVE improvements but it will be good enough for this situation. (you can delete this thread after reading if you would like)

DECLARE SUB ENTERSTATES ()
DECLARE SUB PRINTSTATES ()
DECLARE SUB DELETESTATES ()
CONST MAX = 50
DIM STATES(0 TO MAX - 1) AS STRING
DIM MENU AS STRING

CLS
' ** MENU **
DO
CLS
COLOR 15
PRINT "MAIN MENU"
PRINT
COLOR 7

PRINT "1) Input State(s)"
PRINT "2) Delete State(s)"
PRINT "3) Display State(s)"
PRINT "4) Exit"
PRINT
PRINT "Make a selection: ";
DO
MENU = INKEY$
SELECT CASE MENU
CASE "1" TO "4": EXIT DO
END SELECT
LOOP

SELECT CASE MENU
CASE "1": ENTERSTATES 'sub
CASE "2": DELETESTATES 'sub
CASE "3": PRINTSTATES 'sub
CASE "4": EXIT DO
END SELECT

LOOP
END


' ** INPUT ARRAY **
SUB ENTERSTATES
SHARED STATES() AS STRING
DIM STATE AS STRING
DIM X AS INTEGER
DIM Y AS INTEGER
DIM FOUND AS INTEGER

CLS
COLOR 15
PRINT "INPUT STATES"
PRINT
COLOR 7

X = -1
DO
DO
X = X + 1
IF X = MAX THEN PRINT "!! The array is full !!": EXIT SUB
LOOP WHILE LEN(STATES(X)) <> 0
DO
INPUT "Enter State: (blank to exit) ", STATE
IF LEN(STATE) = 0 THEN EXIT SUB 'exits if blank
FOUND = 0
FOR Y = 0 TO MAX - 1
IF UCASE$(STATE) = UCASE$(STATES(Y)) THEN 'check for duplicate states
FOUND = 1
PRINT "!! This state has already been entered !!"
EXIT FOR
END IF
NEXT
LOOP WHILE FOUND <> 0
STATES(X) = STATE
LOOP
END SUB

SUB DELETESTATES
SHARED STATES() AS STRING
DIM STATE AS STRING
DIM X AS INTEGER
DIM FOUND AS INTEGER

CLS
COLOR 15
PRINT "DELETE STATES"
COLOR 7

DO
PRINT
INPUT "Enter State: (blank to exit) ", STATE
IF LEN(STATE) = 0 THEN EXIT SUB
FOUND = 0
FOR X = 0 TO MAX - 1
IF UCASE$(STATE) = UCASE$(STATES(X)) THEN 'search for state
FOUND = 1
STATES(X) = ""
PRINT
PRINT STATE; " was found and deleted.": EXIT FOR
PRINT
END IF
NEXT X
IF FOUND = 0 THEN
PRINT
PRINT STATE; " was not found in the array."
PRINT
END IF
LOOP
END SUB

' ** PRINT ARRAY **
SUB PRINTSTATES ()
SHARED STATES() AS STRING
DIM X AS INTEGER
DIM Y AS INTEGER
DIM Z AS INTEGER
DIM MENU AS STRING

CLS
COLOR 15
PRINT "PRINT STATES"
COLOR 7

DO
FOR X = 0 TO MAX - 1
FOR Y = X + 1 TO MAX - 1
IF STATES(X) > STATES(Y) THEN 'search states for order
SWAP STATES(X), STATES(Y)
END IF
NEXT Y
NEXT X
FOR Z = 0 TO MAX - 1
PRINT STATES(Z),
NEXT Z
PRINT
PRINT
INPUT "Press ENTER to return to menu: ", MENU
IF LEN(MENU) = 0 THEN EXIT SUB
LOOP
END SUB

Posted on May 13, 2012, 8:43 AM

Respond to this message   

Return to Index


Re: Updated Assignment

by (Login MCalkins)
Moderator

You're quite welcome. I enjoy helping on this kind of program.

It looks good, and it seems to work correctly. I looked over it, and tested it very quickly, so I can't guarantee that it is correct, but I didn't see anything wrong.

-----

There are two places where the code looks pretty similar to mine:

DO
X = X + 1
IF X = MAX THEN PRINT "!! The array is full !!": EXIT SUB
LOOP WHILE LEN(STATES(X)) <> 0

But then, that is pretty straightforward code that does the job, so I would assume that's probably okay.

This concerns me slightly more:

DO
MENU = INKEY$
SELECT CASE MENU
CASE "1" TO "4": EXIT DO
END SELECT
LOOP

SELECT CASE MENU
CASE "1": ENTERSTATES 'sub
CASE "2": DELETESTATES 'sub
CASE "3": PRINTSTATES 'sub
CASE "4": EXIT DO
END SELECT

That one I would suggest you might change. The reason I even had it that way was so that it would PRINT the keystroke if and only if the keystroke was a valid option. Since you took the PRINT out, then the main reason for having two SELECT CASE blocks goes away. The second SELECT CASE is probably okay, but you might simplify the DO...LOOP so that it exits anytime MENU is not empty. If it's a valid keystroke, the SELECT CASE will handle it. If not, the outer loop will repeat.

DO
MENU = INKEY$
LOOP UNTIL LEN(MENU)

You might still PRINT the keystroke between the LOOP and the SELECT CASE. If it's invalid, the CLS at the top of the main loop will hide it. But then again, options 1 to 3 have CLSes also, so it might be moot.

-----

I like that your PrintStates sub alphabetizes the array. Well done. :-)

I'm slightly curious about this:

INPUT "Press ENTER to return to menu: ", MENU
IF LEN(MENU) = 0 THEN EXIT SUB
LOOP

That exits if the user enters a blank string, but loops the whole thing if the user enters a non-empty string. I'm a little curious about the purpose.

-----

I hope your teacher won't mind that you've gotten assistance online. I don't think there is any problem with it, but I hope your teacher is okay with it. You'll probably be turning in a more refined program than your classmates, which could be unfair if they thought they shouldn't get assistance, and therefore didn't. Otherwise, I don't see a problem, as you are learning, and that's the purpose of the class in the first place.

Regards,
Michael

Posted on May 13, 2012, 2:15 PM

Respond to this message   

Return to Index


My QB site is back up.

by (Login ComputerGhost)
R

My QBasic site, originally created in 2002, moved in 2005, and taken down around last year, is back online! It has all the content it originally had in addition to a few more downloads. It also has sections for algorithms, data structures, C, C++, rantings, et cetera. It's basically a personal site, but I figure the QBasic command list and tutorials on which I was complimented years ago merit posting it.

Sadly, I only currently have FTP access to the site and so can't finish the database stuff (this is the reason for the errors on the home page (news section)) or register a domain name. If I find where I wrote my password down, I can do that stuff. However, the URLs I will list below will work both before and after a domain name is registered, so they can be used (contact me if you want to link to it, though, because I want to use the domain name I'm registering).

QBasic section:
http://nathanbelue.com/index.php?page=prog&subPage=qb

QBasic FAQ:
http://nathanbelue.com/index.php?page=prog&subPage=qb&subSubPage=faq

QBasic Reference:
http://nathanbelue.com/index.php?page=prog&subPage=qb&subSubPage=ref

QBasic Tutorials:
http://nathanbelue.com/index.php?page=prog&subPage=qb&subSubPage=tut

QBasic / MSDOS Downloads:
http://nathanbelue.com/index.php?page=downloads&subPage=dos



    
This message has been edited by ComputerGhost on May 13, 2012 4:10 PM
This message has been edited by ComputerGhost on May 12, 2012 9:44 PM

Posted on May 12, 2012, 9:43 PM

Respond to this message   

Return to Index


why is your site hosted on a lawyer's server?

by stosb (no login)

Your site is hosted on beluelaw.com, which hosts the server of the Law Office of James T. Belue (just look at beluelaw.com). Why? What does that have to do with programming? Are you a lawyer or of some similar profession?

Posted on May 12, 2012, 10:27 PM

Respond to this message   

Return to Index


It's a family account on GoDaddy.

by (Login ComputerGhost)
R

The beluelaw account was created first, so it is in the root directory. Other sites are also hosted there. After I register a domain name, I will point it to the folder where my site is hosted (I'm thinking nathanbelue.com or computerghost.com (if I can buy the later)). I put it on that account because it was created to host the websites of family. It's cheaper than getting my own account. happy.gif

--EDIT: addendum--

It's only temporary that it's on the beluelaw.com domain. In a couple of days, it will have its own domain name. The old url (beluelaw.com/moi) will still work, but the new URL will be what I'll use for linking and stuff.



    
This message has been edited by ComputerGhost on May 13, 2012 1:21 AM

Posted on May 13, 2012, 1:12 AM

Respond to this message   

Return to Index


lol ok

by stosb (no login)

We were talking about you last night (MC & I), but I'm a little fuzzy on the details (was a bit smashed lol). Hope I didn't get out of line in chat or anything. Don't remember. :-P

Posted on May 13, 2012, 9:34 AM

Respond to this message   

Return to Index


* I changed it. After the DNS records update, it's nathanbelue.com

by (Login ComputerGhost)
R

Posted on May 13, 2012, 4:11 PM

Respond to this message   

Return to Index


CASE

by MATT (no login)

Wasnt sure if I should start a new topic or not..

I know that this is incorrect.. It works but, when STATE <> STATES() it also prints "Deleting: ''" before reprinting "(Blank to exit) which state?"

SELECT CASE Y
CASE IS < 0, IS >= 50: PRINT "Out of range"
CASE STATE <> STATES(): PRINT STATE; " was not found!"
CASE ELSE
PRINT "Deleting: '" + STATES(Y) + "'"
STATES(Y) = ""
END SELECT

Posted on May 12, 2012, 5:35 PM

Respond to this message   

Return to Index


scratch that

by Matt (no login)

Nevermind, doesnt work at all.. back to the drawing board

Posted on May 12, 2012, 5:40 PM

Respond to this message   

Return to Index


Re: CASE (added some more info) (fixed a few typos in the pseudo code)

by (Login MCalkins)
Moderator

Are you wanting the user to type the name of the state to delete?

In that case, loop through the states() array until you find the match.

Here's how you might do it:

have an outer DO loop to prompt (and reprompt) the user for the state to delete.
 if the user entered a blank string, exit the loop
 have an inner FOR loop to loop through the states() array looking for a case insensitive match.
  when you find a match, clear that element of the array, then exit both loops.
 NEXT
 print a message that no match was found.
LOOP

alternatively, you might exit just the inner FOR loop, instead of exiting both loops, if you want to give the user the chance to delete another state. However, then you would need an IF statement for the error message, instead of just printing it unconditionally. In such a case, it is not necessary to introduce another variable to track whether a match was found or not. You can tell from the FOR's counter alone. If the FOR loop is 1 to 50, the counter will be 51 after finishing the loop without a match, but would be less than 51 if the EXIT FOR were executed...

---

Are you wanting the user to type the array index? (This is how my other modification worked, but might not be ideal.) Then check that the index is within bounds, then delete it.

---

I think you are going for the first method, but the code looks like you are trying to mix the two methods.

---

A better method would be to have the user be able to select which one to delete from the display. That is, scroll through the list and let the user select which. However, that is more complicated to code.

Regards,
Michael



    
This message has been edited by MCalkins on May 12, 2012 6:25 PM
This message has been edited by MCalkins on May 12, 2012 6:23 PM
This message has been edited by MCalkins on May 12, 2012 6:23 PM
This message has been edited by MCalkins on May 12, 2012 6:21 PM

Posted on May 12, 2012, 6:09 PM

Respond to this message   

Return to Index


RE

by MATT (no login)

Yes, your assumption is correct. And Yes, I am (although not previously realized) mixing both.
Basically at this point im not sure what I am doing...
Ill figure it out though. Just getting a bit frustrated which is causing me to over-think the situation.


Posted on May 12, 2012, 6:17 PM

Respond to this message   

Return to Index


* I edited my previous post...

by (Login MCalkins)
Moderator

Posted on May 12, 2012, 6:21 PM

Respond to this message   

Return to Index


Thanks

by Matt (no login)

I really appreciate your help and patience!

Posted on May 12, 2012, 6:24 PM

Respond to this message   

Return to Index


* yw.

by (Login MCalkins)
Moderator

Posted on May 12, 2012, 6:26 PM

Respond to this message   

Return to Index


re: case updated

by MATT (no login)

Ok,
I'm not quite sure why i am having so much trouble getting this. It is my first time creating a program this complicated but it doesn't seem like it should be so difficult...

Here is what I have so far.
It seems to work fine the first loop around but then every other entry gives "was not found" and "IF LEN(STATE) = 0 THEN EXIT DO" seems to not work either. Any ideas? I'm sure it is something simple that I am missing here..

SUB DeleteStates
SHARED states() AS STRING
DIM STATE AS STRING
DIM x AS INTEGER
DIM found AS INTEGER
DO
DO
INPUT "Enter State: (blank to exit) "; STATE
IF LEN(STATE) = 0 THEN EXIT DO
found = 0
FOR x = 0 TO maxstates - 1
IF UCASE$(STATE) = UCASE$(states(x)) THEN
found = 1
states(x) = ""
PRINT STATE; " was found and deleted.": EXIT DO

ELSEIF found = 0 THEN
PRINT
PRINT STATE; " was not found in the array.": EXIT DO
END IF
NEXT x
LOOP
LOOP
END SUB

Posted on May 12, 2012, 8:54 PM

Respond to this message   

Return to Index


I see 2 main problems

by (Login MCalkins)
Moderator

The first is that you have two DO...LOOP blocks, one right inside the other. So, your EXIT DOs are exiting the middle loop, but are not exiting the outer loop.

The next problem is related to the ELSEIF. Inside your inner loop, the FOR loop, you have:


IF UCASE$(STATE) = UCASE$(states(x)) THEN
found = 1
states(x) = ""
PRINT STATE; " was found and deleted.": EXIT DO

ELSEIF found = 0 THEN
PRINT
PRINT STATE; " was not found in the array.": EXIT DO
END IF


Which is okay, I think, until the ELSEIF. Consider:

Let's say "Texas" is in states(5), but I want to delete it. The first time it gets to:

IF UCASE$(STATE) = UCASE$(states(x)) THEN

Well, that's false, because states(0) is something else. So then the

ELSEIF found = 0 THEN

is processed. found is 0, so it executes:

PRINT STATE; " was not found in the array.": EXIT DO

But we haven't finished searching the array yet, only the first element. That whole bit related to the ELSEIF needs to be moved so that it is after the inner loop, that is, the FOR loop.

Also, since the extra DO...LOOP has been removed, the 3rd EXIT DO needs to be removed also (the one for "was not found").

This code is mostly fixed and should work, but could use some improvement:

SUB DeleteStates
 SHARED states() AS STRING
 DIM STATE AS STRING
 DIM x AS INTEGER
 DIM found AS INTEGER
 DO
  INPUT "Enter State: (blank to exit) "; STATE
  IF LEN(STATE) = 0 THEN EXIT DO
  found = 0
  FOR x = 0 TO maxstates - 1
   IF UCASE$(STATE) = UCASE$(states(x)) THEN
    found = 1
    states(x) = ""
    PRINT STATE; " was found and deleted.": EXIT DO
   END IF
  NEXT x
  IF found = 0 THEN
   PRINT
   PRINT STATE; " was not found in the array."
  END IF
 LOOP
END SUB


Actually, those EXIT DOs could probably become EXIT SUBs in this case.

If you want to keep looping, letting the user delete multiple states until entering a blank, then change the 2nd EXIT DO to an EXIT FOR.

Otherwise, you actually don't even need the found variable at all, because EXIT DO or EXIT SUB would completely exit the loop if it were found, so if it gets to that point, you know it wasn't found.

I suspect you'll prefer the former (multiple deletions).

One other thing: are you going to use 0 to 49 or 1 to 50? My preference would be 0 to 49, but your teacher might anticipate 1 to 50. Whichever you choose, make sure it is consistent throughout the program.

I'll post this, and double check the code examples afters I've posted. I'll edit as necessary.

=====

From here on contains code that should work. If you want to come up with it yourself, you might hold off on reading the rest of the post.

Regards,
Michael


---------------- To allow multiple deletions:


SUB DeleteStates
 SHARED states() AS STRING
 DIM STATE AS STRING
 DIM x AS INTEGER
 DIM found AS INTEGER
 DO
  INPUT "Enter State: (blank to exit) "; STATE
  IF LEN(STATE) = 0 THEN EXIT SUB
  found = 0
  FOR x = 0 TO maxstates - 1
   IF UCASE$(STATE) = UCASE$(states(x)) THEN
    found = 1
    states(x) = ""
    PRINT STATE; " was found and deleted.": EXIT FOR
   END IF
  NEXT x
  IF found = 0 THEN
   PRINT
   PRINT STATE; " was not found in the array."
  END IF
 LOOP
END SUB


---------------- Multiple deletions without the found variable. Only use if you understand it well enough to explain it to your teacher.


SUB DeleteStates
 SHARED states() AS STRING
 DIM STATE AS STRING
 DIM x AS INTEGER
 DO
  INPUT "Enter State: (blank to exit) "; STATE
  IF LEN(STATE) = 0 THEN EXIT SUB
  FOR x = 0 TO maxstates - 1
   IF UCASE$(STATE) = UCASE$(states(x)) THEN
    states(x) = ""
    PRINT STATE; " was found and deleted.": EXIT FOR
   END IF
  NEXT x
  IF x = maxstates THEN
   PRINT
   PRINT STATE; " was not found in the array."
  END IF
 LOOP
END SUB


---------------- To allow only one deletion per call of the SUB:


SUB DeleteStates
 SHARED states() AS STRING
 DIM STATE AS STRING
 DIM x AS INTEGER
 DO
  INPUT "Enter State: (blank to exit) "; STATE
  IF LEN(STATE) = 0 THEN EXIT SUB
  FOR x = 0 TO maxstates - 1
   IF UCASE$(STATE) = UCASE$(states(x)) THEN
    states(x) = ""
    PRINT STATE; " was found and deleted.": EXIT SUB
   END IF
  NEXT x
  PRINT
  PRINT STATE; " was not found in the array."
 LOOP
END SUB



    
This message has been edited by MCalkins on May 12, 2012 10:43 PM
This message has been edited by MCalkins on May 12, 2012 10:40 PM

Posted on May 12, 2012, 10:27 PM

Respond to this message   

Return to Index


RE: two main problems

by Matt (no login)

Funny, I figured it out shortly after i posted. Then i forgot to save :-P.
In any case, THANK YOU!
You have been above and beyond helpful!

Posted on May 13, 2012, 7:25 AM

Respond to this message   

Return to Index


I see some other potential problems in your program.

by (Login emoneo)

Matt,

You enter the state names as such. How about the spelling of these, e.g.,
How many "s" and "t" in Massachusetts?
How many "s" and "p" in Mississippi?
How many "n" in Connecticut?

If the names of the states are not spelled correctly, then you will not be able to determine duplicates, and you will not be able to delete a state (unless you know the original spelling.) Given this type of error, you could end up with 50 state names which don't match the real 50 names of the states, and actually have less than 50 state names in your array.

One possible solution is to use the official USPS abbreviations for the states. But, this gets tricky because states beginning with "M" or "N" do not necessary have intuitive abbreviations.

I'll let you think about this. You might ask your teacher about it.

Regards..... Moneo


Posted on May 24, 2012, 6:02 PM

Respond to this message   

Return to Index


Example using a boolean variable with a loop

by Solitaire (Login Solitaire1)
S

DIM states(1 TO 50) AS STRING
DIM x AS INTEGER, ok AS INTEGER, found AS INTEGER, state AS STRING
ok = 0    'Boolean variable:  0 is False, 1 is True
CLS
FOR x = 1 TO 50         'dummy data entered into array
      states$(x) = CHR$(x  +  65)
NEXT x
INPUT "Enter state:   ", state$
FOR x = 1 TO 50
      IF UCASE$(states$(x)) = UCASE$(state$) THEN
              ok = 1
              found = x
              EXIT FOR
      END IF
NEXT x
IF ok = 1 THEN
      PRINT state$; " was found at index "; x
ELSE
      PRINT state$; " was not found"
END IF
END

Posted on May 12, 2012, 7:27 PM

Respond to this message   

Return to Index


Re: Example using a boolean variable with a loop

by (Login MCalkins)
Moderator

Aye, that would work, but as I mentioned in the other post, something like this:


FOR x = 1 TO 50
            IF UCASE$(states$(x)) = UCASE$(state$) THEN
                            ok = 1
                            found = x
                            EXIT FOR
            END IF
NEXT x
IF ok = 1 THEN
            PRINT state$; " was found at index "; x
ELSE
            PRINT state$; " was not found"
END IF


could be also be written as something like this:


FOR x = 1 TO 50
            IF UCASE$(states$(x)) = UCASE$(state$) THEN
                            PRINT state$; " was found at index "; x
                            EXIT FOR
            END IF
NEXT x
IF x = 51 THEN
            PRINT state$; " was not found"
END IF


because x will be 51 if and only if EXIT FOR was not executed. The NEXT x increments x, then checks to see if x <= 50. When x is 50, NEXT x turns it to 51, then exits the loop. However, if a match had been found, EXIT FOR would exit the loop before x becomes 51.

Regards,
Michael

Posted on May 12, 2012, 7:55 PM

Respond to this message   

Return to Index


Good shortcut. Another example using duplicate data:

by Solitaire (Login Solitaire1)
S

If you don't use EXIT FOR, you can also test for repeated instances of a match (for arrays with random data) and identify them with a counter and a concatenated string with the converted array indexes. This can be useful for eliminating duplicates. Example:

======================================================================
DIM states(1 TO 50) AS STRING
DIM x AS INTEGER, ok AS INTEGER, found AS INTEGER, randnum AS INTEGER
DIM state AS STRING, finder AS STRING
ok = 0  'used as counter
CLS
RANDOMIZE TIMER
FOR x = 1 TO 50     'dummy data entered into array (random letters A-Z)
    randnum = INT(RND * 27) + 65
    states$(x) = CHR$(randnum)
NEXT x
INPUT "Enter state:  ", state$
FOR x = 1 TO 50
    IF UCASE$(states$(x)) = UCASE$(state$) THEN
        ok = ok + 1
        found = x
        finder$ = finder$ + ", " + STR$(x)
    END IF
NEXT x
IF ok > 0 THEN
    PRINT state$; " was found at index:  "; finder
ELSE
    PRINT state$; " was not found"
END IF
END
======================================================================

Special Note: In VB.NET, you can use block-level variables, where the value of the For Next counter is removed from memory after the block ends. In that case, the code I posted above using a Boolean variable would work best. Example:
For x As Integer = 1 to 50
'more code goes here
Next x
'x is no longer available



    
This message has been edited by Solitaire1 on May 13, 2012 11:54 AM

Posted on May 13, 2012, 11:50 AM

Respond to this message   

Return to Index


going a bit off topic...

by (Login MCalkins)
Moderator

>Special Note: In VB.NET, you can use block-level variables, where the value of the For Next counter is removed from memory after the block ends.

By "can", you mean it's optional, right? I know basically nothing about VB.NET, but C++ also has block level variables. It would matter where you define the variable:

--------

#include <stdio.h>
int main(){
 int x;                         // x is defined here, at the function level.
 for (x=1; x<=50; ++x) {
 }
 printf("%i\n", x);             // will print 51
}

--------

#include <stdio.h>
int main(){
 for (int x=1; x<=50; ++x) {    // x is defined within the scope of the for
 }
 printf("%i\n", x);             // error: name lookup of 'x' changed for ISO 'for' scoping
}

--------

So, in VB.NET, I guess it would matter where the variable is DIMmed?

Regards,
Michael

Posted on May 13, 2012, 12:46 PM

Respond to this message   

Return to Index


Yes, in VB.NET:

by Solitaire (Login Solitaire1)
S

If you Dim the variable in the procedure, it is local to that procedure and cannot also be used as a block-level variable. If you try, it will be flagged as an error.

If you use only the local procedure-level variable, it will behave the same as in QB, so the code you posted in response to my first post in this thread, would be valid.

Posted on May 13, 2012, 4:32 PM

Respond to this message   

Return to Index


just downloaded qb64

by stosb (no login)

Is there a way to remove that god-awful auto-syntax-checking at the bottom of the screen? It highlights every line as I go along, then it's like "oh, nvm your code is right". :-S

Posted on May 12, 2012, 2:00 PM

Respond to this message   

Return to Index


Re: just downloaded qb64

by (Login MCalkins)
Moderator

Not that I know of.

If really can't stand it, you can always code in Notepad, and then compile the program with qb64.exe -x filename. Also, there is at least one alternative IDE. I think Dav wrote one.

The auto-indenting can take some time to get used to also, but it can be disabled through the options menu. I used to somewhat rely on the indentation of the code below where I'm working to remind myself of the program structure, but in QB64 with auto-indenting, you can't rely on the indentation below where you are working. However, I feel the tradeoff is worth not having to manually indent everything.

Regards,
Michael

Posted on May 12, 2012, 2:20 PM

Respond to this message   

Return to Index


that's too bad

by stosb (no login)

I was hoping there was a way to make it exactly like qb's ide. It really is annoying to have that status window constantly updating.

Posted on May 12, 2012, 2:33 PM

Respond to this message   

Return to Index


Re: that's too bad

by Docfxit (Login Docfxit)
R

I prefer coding in Ultra Edit. It doesn't auto indent. But it does give you line numbers. It's much easier with a large program.

Docfxit

Posted on May 13, 2012, 7:07 AM

Respond to this message   

Return to Index


I've not heard of it

by stosb (no login)

The problem isn't auto-indent, but the immediate syntax checking every time you type a line.

Posted on May 13, 2012, 4:19 PM

Respond to this message   

Return to Index


while wend

by matt (no login)

quick question
Ive been looking around online but still have not gotten a good grasp here.

WHILE LEN(INKEY$): WEND

I understand the use of WHILE/WEND, LEN, and INKEY$. But i am having trouble understanding exactly why this works.

It would seem like there would need to be another variable there.
example.

WHILE LEN(INKEY$)= X: WEND

Posted on May 12, 2012, 1:36 PM

Respond to this message   

Return to Index


type conversion

by stosb (no login)

If you have a number in an IF statement (including for a loop) it is converted to TRUE/FALSE based on if it's nonzero or zero, respectively. So if you say

WHILE LEN(INKEY$)

It's the exact same as saying

WHILE LEN(INKEY$) <> 0

because the numeric value of the LEN function is converted to TRUE if it's not zero, or FALSE if it is zero.

Posted on May 12, 2012, 1:59 PM

Respond to this message   

Return to Index


RE

by MATT (no login)

Ok, so
WHILE LEN(INKEY$): WEND
Is the same as
WHILE LEN(INKEY$) <> 0: WEND
correct?

One more question.
What exactly would this do since there is not a statement or loop between WHILE/WEND?

example;
WHILE [condition, IE: LEN(INKEY$)]
[statement]
WEND

Posted on May 12, 2012, 2:26 PM

Respond to this message   

Return to Index


yes

by stosb (no login)

If you say

WHILE LEN(INKEY$)
PRINT "hello"
WEND

What will happen when you execute is this:

1) The program will evaluate the condition ( LEN(INKEY$) )
2) If it evaluates to TRUE (nonzero), go to step 3. Otherwise, if it's FALSE (0) go to step 5
3) Execute PRINT command
4) WEND here jumps back to the beginning of the WHILE loop
5) Exit the loop

Try it!

Posted on May 12, 2012, 2:33 PM

Respond to this message   

Return to Index


RE

by MATT (no login)

THANKS!

Posted on May 12, 2012, 2:39 PM

Respond to this message   

Return to Index


Re: RE

by (Login MCalkins)
Moderator

The purpose of:

WHILE LEN(INKEY$): WEND

is to clear the keyboard buffer. INKEY$ strips a keystroke off of the buffer every time it is called. When it returns an empty string, that is, a string with a length of 0, then the keyboard buffer is empty.

So, I am discarding any existing keystrokes, because I want an empty buffer for the next SLEEP or INKEY$ loop.

Regards,
Michael

Posted on May 12, 2012, 2:42 PM

Respond to this message   

Return to Index


RE:RE

by MATT (no login)

Ah!

Thank you, that makes quite a bit more sense!
I was having difficulty understanding its purpose here.
Guess i was asking the wrong questions

Posted on May 12, 2012, 2:45 PM

Respond to this message   

Return to Index


Re: RE:RE

by (Login MCalkins)
Moderator

You're welcome. This demonstrates it. _DELAY requires QB64, otherwise you could use a TIMER loop.

Regards,
Michael

DIM k AS STRING

PRINT "Type something in the next 5 seconds."
_DELAY 5

' uncomment the next line to clear the buffer.
' WHILE LEN(INKEY$): WEND

PRINT "Press ESC to exit."
DO
 k = INKEY$
 IF LEN(k) THEN PRINT k;
LOOP UNTIL k = CHR$(&H1B) ' esc key
END



    
This message has been edited by MCalkins on May 12, 2012 2:59 PM

Posted on May 12, 2012, 2:59 PM

Respond to this message   

Return to Index


to expand on what stosb said...

by (Login MCalkins)
Moderator

Conditions in QBASIC are always numeric. Things like IF, WHILE, and UNTIL all take conditions.

examples:

WHILE condition
...
WEND

IF condition THEN
...
END IF

DO
...
LOOP UNTIL condition

In each case 'condition' is a numeric expression. If its value is 0, the condition is false. If its value is non-zero, the condition is true. I wouldn't call that type conversion, I'd call it a built in check for equality/inequality with zero.

If you have something like:

WHILE LEN(INKEY$) = X
WEND

it's still a numeric expression.

LEN(INKEY$) = X

is a numeric expression, as the equality test operator, =, returns 0 for false or -1 for true.

Likewise:

IF t$ = "abc" THEN

t$ = "abc" is actually a numeric expression. Although both t$ and "abc" are strings, and in this case, the equality operator is testing for equality between two strings, it still returns a number, 0 for false, -1 for true. Run this code to see what I mean:

PRINT "abc" = "def"
PRINT "abc" = "abc"

The first will print 0, the next will print -1.

Likewise, you can assign the result to a numeric variable:

DIM i AS INTEGER
i = "abc" = "def"
PRINT i

the first = is an assignment, the second = is an equality operator.

Why is -1 the ideal true? Because -1 is all bits on in either an INTEGER or a LONG. Therefore NOT -1 is 0, and any non-zero number AND -1 is a non-zero number. Neither is true of any number other than -1. Examples:

PRINT NOT -1 ' should print 0
PRINT NOT 1 ' should print -2
PRINT 4 AND -1 ' should print 4
PRINT 4 AND 1 ' should print 0

-----

Digressing a little:

PRINT 5 = 5
compares two integers; the result is an integer -1

print 5.5 = 5.5
compares two floats; the result is a -1. (I assume an integer -1, but I'm not sure.)

PRINT "5" = "5"
compares two strings; the result is an integer -1

The + operator can also be used with both numbers and strings:

PRINT 5 + 5
Adds two integers; the result is an integer 10.

PRINT 5.5 + 5.5
Adds two floats; the result is a float 11.

PRINT "5" + "5"
Concatenates two strings; the result is a string "55".

Regards,
Michael



    
This message has been edited by MCalkins on May 12, 2012 2:46 PM

Posted on May 12, 2012, 2:39 PM

Respond to this message   

Return to Index


thanks

by matt (no login)

You sound like you really know your stuff.
Thanks, i understood most of that ;)

I have quite a bit to learn yet.

Thanks for the help gentlemen!

Posted on May 12, 2012, 2:52 PM

Respond to this message   

Return to Index


Re: thanks

by (Login MCalkins)
Moderator

Good. Which parts didn't you understand? If you want to tackle them now, I can try to help. If you want to put them on the 'to-learn' list for later, that's fine also.

Regards,
Michael

Posted on May 12, 2012, 3:02 PM

Respond to this message   

Return to Index


It should be noted that comparing against -1 for truth is a bad idea.

by John Q. Boolean (no login)

Instead, one should compare to ensure something is not true (i.e. false):

'Open a file and keep reading lines until we exit.
f = FREEFILE
OPEN "filename.txt" FOR INPUT AS #f
WHILE NOT EOF(#f)
LINE INPUT #f, x$
PRINT x$
WEND
CLOSE #f
END

Also, for things like the LEN function that return a non-Boolean value, it makes more sense to test whether something is/isn't a certain length. For example, doing something like WHILE NOT LEN(INKEY$): WEND makes little sense semantically whereas WHILE LEN(INKEY$) = 0: WEND makes more sense. After all, you're testing whether the number of characters in INKEY$ is 0, not whether it is true or false because it doesn't return a true/false value. Of course, you're free to do what you wish as always.

Posted on May 12, 2012, 3:00 PM

Respond to this message   

Return to Index


...

by matt (no login)

Yes, i will place those things on a "to learn" list. I have loads of homework to tackle yet.

As for the comment from John.
WHILE LEN(INKEY$) = 0: WEND
Doesn't seem to work for my application. I get a blank screen upon program start-up.

However,
WHILE LEN(INKEY$): WEND
AND
WHILE LEN(INKEY$) <> 0; WEND

Both seem to work fine. But thanks for the input. Ill look into it a bit more later.

Posted on May 12, 2012, 3:10 PM

Respond to this message   

Return to Index


Re: It should be noted that comparing against -1 for truth is a bad idea.

by (Login MCalkins)
Moderator

I agree that testing if something = -1 to determine general truth is not ideal.

IF integerExpression THEN statement

is perfectly valid if you want statement to execute on a true (non-zero) integerExpression.

IF 0 = (integerExpression) THEN statement

is perfectly valid if you want statement to execute on a false (zero) integerExpression.

IF integerExpression THEN
statementA
ELSE
statementB
END IF

is perfectly valid for combining both into a single IF statement.

0 = (integerExpression) is the same as !(integerExpression) in C/C++, where ! is a logical NOT. BASIC doesn't have a logical NOT. Bitwise NOT is unsuitable here, because, for example: 5 is true, but NOT 5 is -6 which is still true. However 0=(integerExpression) performs a logical NOT.

Wherever possible, you may exploit QBASIC's built in zero equality/inequality testing. Doing so is not bad coding practice, but is normal exploitation of known aspects of the language. For example:

DO WHILE 0 = (something)
...
LOOP

is the same as:

DO UNTIL something
...
LOOP

If you know for a certainty that:

DO WHILE 0 <> (something)
...
LOOP

is functionally identical, in all cases, to:

DO WHILE something
...
LOOP

then I am aware of no reason not to go with the latter. WHILE already has a built in test for <> 0, so:
0 <> (something)
is redundant. Maybe the compiler optimizes it away, maybe not. Either way, it is unnecessary and redundant. I believe the source code is just as clear, probably more clear, without it.

In the case of LEN(someString), I know that LEN() will return zero if the string is empty and non-zero if the string is not empty. My desire is to execute the loop as long as the string is not empty. So, in this case, I don't care whether the LEN is 5 or 10, I just care whether it is 0 or non-zero, which fits very nicely with what I confidently know about IF/WHILE/UNTIL.

However, as you say, people may code as they wish.

Regards,
Michael



    
This message has been edited by MCalkins on May 12, 2012 3:27 PM

Posted on May 12, 2012, 3:26 PM

Respond to this message   

Return to Index


Getting error 62 reading a com port

by Docfxit (Login Docfxit)
R

I'm getting an error 62 On the second line (IF LOC(wsFileNum))which says:
Check for the end of file with EOF when reading from a file.

DO WHILE NOT EOF(wsFileNum) 'receive
IF LOF(wsFileNum) <= 32767 THEN junk$ = INPUT$(LOF(wsFileNum), # wsFileNum)
LOOP


Does anyone have any ideas how I can stop getting error 62?

Thanks,

Docfxit



    
This message has been edited by Docfxit on May 11, 2012 5:20 PM
This message has been edited by Docfxit on May 11, 2012 4:55 PM
This message has been edited by Docfxit on May 11, 2012 4:54 PM
This message has been edited by Docfxit on May 11, 2012 4:53 PM
This message has been edited by Docfxit on May 11, 2012 4:39 PM
This message has been edited by Docfxit on May 11, 2012 1:20 PM

Posted on May 11, 2012, 1:19 PM

Respond to this message   

Return to Index


well i don't know but

by stosb (no login)

Since error 62 is input past EOF you could try something slower:

WHILE NOT EOF(wsFileNum)
byte$ = INPUT$(1, wsFileNum)
WEND

Posted on May 12, 2012, 12:16 AM

Respond to this message   

Return to Index


another thing would be

by stosb (no login)

this line:

IF LOF(wsFileNum) <= 32767 THEN

That will execute even if LOF = 0, which will cause error 62. Try saying instead

IF LOF(wsFileNum) > 0 THEN

Posted on May 12, 2012, 12:48 AM

Respond to this message   

Return to Index


* This did get rid of error 62. But nothing is input

by Docfxit (Login Docfxit)
R

Posted on May 13, 2012, 6:32 AM

Respond to this message   

Return to Index


*lol well maybe nothing is being sent?

by stosb (no login)

Posted on May 13, 2012, 9:42 AM

Respond to this message   

Return to Index


* I get the same error 62. Check for EOF

by Docfxit (Login Docfxit)
R



    
This message has been edited by Docfxit on May 13, 2012 6:28 AM

Posted on May 13, 2012, 6:27 AM

Respond to this message   

Return to Index


Yeah, get rid of the loop

by (Login burger2227)
R

Use the IF statement ONCE to load the contents of the file into the variable.

The loop makes it try to load more data and is past the EOF.

Posted on May 12, 2012, 5:38 AM

Respond to this message   

Return to Index


Re: Yeah, get rid of the loop

by Docfxit (Login Docfxit)
R

Why does this go past the EOF?
Why doesn't this input anything? junk$ is blank every time.
I'm stopping the program after 40 loops.

WHILE NOT EOF(wsFileNum)
IF LOF(wsFileNum) >0 THEN junk$ = INPUT$(LOF(wsFileNum), # wsFileNum)
WEND

Thanks,

Docfxit

**Please Note: Since no one has posted any ideas I am posting this on QB64.net

This code is what I am using for testing the above statements:

DIM SHARED debugflag$
DIM SHARED var1$
DIM SHARED var2$
DECLARE SUB openWsPort (portNum)
CONST theComPort = 1
CONST comMode$ = ":9600,N,8,1,CS6000,DS6000" ' change baud here if you change s12 setting
ON ERROR GOTO ErrorHandler
debugflag$ = "Onn3" 'For debugging either Onn or off
Ix = 5
openWsPort theComPort
END

ErrorHandler:
Ix = Ix + 1
SELECT CASE ERR
CASE 155: LastErrorLine = _ERRORLINE
CASE ELSE: PRINT "Error code "; ErrorCode; " on line "; _ERRORLINE
END
END
END SELECT
IF ERR = 155 THEN 'Debug
'** Print line and variable to screen
IF var2$ "999" THEN
COLOR 11, 0: LOCATE Ix, 1: PRINT "On Line "; LastErrorLine; var1$; var2$ ' for debugging only
ELSE
COLOR 11, 0: LOCATE Ix, 1: PRINT "On Line "; LastErrorLine; var1$ ' for debugging only
END IF
END IF
IF Ix > 40 THEN ' 47 tops
Ix = Ix + 1
COLOR 13, 0: LOCATE Ix, 1: PRINT "Too many debugs Program Ended "
END
END IF
RESUME NEXT
SUB openWsPort (portNum)
'** Open the specified serial port. Use global constant comMode for baud
IF debugflag$ = "Onn3" THEN
var1$ = "OpenWsPort start " 'For Debuging Only
var2$ = "999" 'For Debuging Only
ERROR 155 'For Debuging Only
var1$ = "FreeFile = " 'For Debuging Only
var2$ = STR$(FREEFILE) 'For Debuging Only
ERROR 155 'For Debuging Only
var1$ = "wsFileNum = " 'For Debuging Only
var2$ = STR$(wsFileNum) 'For Debuging Only
ERROR 155 'For Debuging Only
var1$ = "portNum = " 'For Debuging Only
var2$ = STR$(portNum) 'For Debuging Only
ERROR 155 'For Debuging Only
var1$ = "Fid = " 'For Debuging Only
var2$ = STR$(Fid) 'For Debuging Only
ERROR 155 'For Debuging Only
END IF
DO
IF wsFileNum = 0 THEN ' don't open if already open
wsFileNum = FREEFILE ' get an unused file number

'now open the serial port
ComPortOpen$ = "Yes"

IF debugflag$ = "Onn3" THEN
var1$ = "Open Com Port " 'For Debuging Only
var2$ = "999" 'For Debuging Only
ERROR 155 'For Debuging Only
var1$ = "wsFileNum = " 'For Debuging Only
var2$ = STR$(wsFileNum) 'For Debuging Only
ERROR 155 'For Debuging Only
var1$ = "portNum = " 'For Debuging Only
var2$ = STR$(portNum) 'For Debuging Only
ERROR 155 'For Debuging Only
var1$ = "comMode$ 2= " 'For Debuging Only
var2$ = comMode$ 'For Debuging Only
ERROR 155 'For Debuging Only
END IF
OPEN "COM" + STR$(portNum) + comMode$ FOR RANDOM AS #wsFileNum
IF errnum = 0 THEN
var1$ = "COM exists! " 'For Debuging Only
var2$ = "999" 'For Debuging Only
ERROR 155 'For Debuging Only
END IF
WHILE NOT EOF(wsFileNum)
IF debugflag$ = "Onn3" THEN
var1$ = " LOF(wsFileNum)2 = " 'For Debuging Only
var2$ = STR$(LOF(wsFileNum)) 'For Debuging Only
ERROR 155 'For Debuging Only
END IF
IF LOF(wsFileNum) > 0 THEN junk$ = INPUT$(LOF(wsFileNum), # wsFileNum)
IF debugflag$ = "Onn3" THEN
var1$ = " junk$ = " 'For Debuging Only
var2$ = junk$ 'For Debuging Only
ERROR 155 'For Debuging Only
END IF
WEND
END IF
LOOP
END SUB




    
This message has been edited by Docfxit on May 14, 2012 1:40 PM
This message has been edited by Docfxit on May 14, 2012 1:05 PM

Posted on May 13, 2012, 6:39 AM

Respond to this message   

Return to Index


Problems passing ARRAY from SUB to SUB (continued)

by Matt (no login)

Hello, I am still having trouble passing an ARRAY from one SUB to another. I have tried several different methods for passing variables and none have been successful... Here is what I have so far. I understand that my variables are incorrect so please keep that in mind. And the program is incomplete as of right now. I basically need to transfer the array from the first sub to the second and eventually a third. Could someone please give me an idea of what to change to get this thing to work?

DIM MENU AS INTEGER
DECLARE SUB ENTERSTATES
DECLARE SUB PRINTSTATES

CLS

' ** MENU **
DO
PRINT
PRINT "1) INPUT A STATE INTO THE ARRAY"
PRINT "2) DELETE A STATE FROM THE ARRAY"
PRINT "3) DISPLAY THE STATES STORED IN THE ARRAY"
PRINT "4) QUIT"
PRINT
INPUT "MAKE A SELECTION FROM THE ABOVE LIST (1, 2, 3, OR 4):", MENU
PRINT

IF MENU = 1 THEN
ENTERSTATES
ELSEIF MENU = 2 THEN PRINT "MENU 2 SELECTED"
ELSEIF MENU = 3 THEN
PRINTSTATES
ELSEIF MENU > 4 THEN
PRINT "!! YOU HAVE ENTERED AN INVALID SELECTION !!"
PRINT
END IF
LOOP UNTIL MENU = 4

' ** INPUT ARRAY **
SUB ENTERSTATES
SHARED STATES
DIM STATE AS STRING
DIM STATES(50) AS STRING
DIM x AS INTEGER
DIM y AS INTEGER
DIM Found AS INTEGER
CLS

FOR x = 1 TO 50

DO
INPUT "Enter Name: ", STATE
Found = 0

IF STATE = "EXIT" OR STATE = "Exit" OR STATE = "exit" THEN
EXIT SUB
END IF

FOR y = 1 TO 50
IF UCASE$(STATE) = UCASE$(STATES(y)) THEN
Found = 1
END IF

NEXT y

IF Found = 1 THEN
PRINT
PRINT "!! STATE ALREADY IN ARRAY !!"
PRINT
END IF
LOOP UNTIL Found = 0

STATES(x) = STATE
NEXT x

PRINT

END SUB

' ** PRINT ARRAY **
SUB PRINTSTATES
SHARED STATES
DO UNTIL EXIT$ = "EXIT" OR EXIT$ = "Exit" OR EXIT$ = "exit"
PRINT STATES
INPUT "TYPE EXIT TO RETERN TO MENU: ", EXIT$
LOOP
END SUB


Posted on May 10, 2012, 6:13 PM

Respond to this message   

Return to Index


I made some changes...

by (Login MCalkins)
Moderator

DECLARE SUB EnterStates ()
DECLARE SUB PrintStates ()
DECLARE SUB DeleteStates ()
CONST maxstates = 50
DIM states(0 TO maxstates - 1) AS STRING
DIM k AS STRING

CLS
WHILE LEN(INKEY$): WEND
DO
 PRINT
 PRINT "1) Input a state into the array"
 PRINT "2) Delete a state from the array"
 PRINT "3) Display the states stored in the array"
 PRINT "4) Quit"
 PRINT
 PRINT "Please make a selection: ";
 DO
  SLEEP
  k = INKEY$
  SELECT CASE k
  CASE "1" TO "4": EXIT DO
  END SELECT
 LOOP
 PRINT k
 SELECT CASE k
 CASE "1": EnterStates
 CASE "2": DeleteStates
 CASE "3": PrintStates
 CASE "4": EXIT DO
 END SELECT
LOOP
END

SUB DeleteStates
 SHARED states() AS STRING
 DIM k AS STRING
 DIM i AS INTEGER
 DO
  LINE INPUT "(Blank to exit) which state? "; k
  IF 0 = LEN(k) THEN EXIT DO
  i = VAL(k)
  SELECT CASE i
  CASE IS < 0, IS >= maxstates: PRINT "Out of range"
  CASE ELSE
   PRINT "Deleting: '" + states(i) + "'"
   states(i) = ""
  END SELECT
 LOOP
END SUB

' ** INPUT ARRAY **
SUB EnterStates
 SHARED states() AS STRING
 DIM state AS STRING
 DIM x AS INTEGER
 DIM y AS INTEGER
 DIM found AS INTEGER
 PRINT
 x = -1
 DO
  DO
   x = x + 1
   IF x = maxstates THEN PRINT "Full.": EXIT SUB
  LOOP WHILE LEN(states(x))
  DO
   LINE INPUT "Enter name: ", state
   IF 0 = LEN(state) THEN EXIT SUB
   found = 0
   FOR y = 0 TO maxstates - 1
    IF UCASE$(state) = UCASE$(states(y)) THEN
     found = 1
     PRINT "State already in array."
     EXIT FOR
    END IF
   NEXT
  LOOP WHILE found
  states(x) = state
 LOOP
END SUB

' ** PRINT ARRAY **
SUB PrintStates
 SHARED states() AS STRING
 DIM i AS INTEGER
 WHILE LEN(INKEY$): WEND
 DO WHILE i < maxstates
  IF LEN(states(i)) THEN PRINT i, states(i): SLEEP
  IF INKEY$ = CHR$(&H1B) THEN EXIT DO
  i = i + 1
 LOOP
END SUB

--------------------------------

Using the SHARED keyword like that in the SUB is for giving the SUB access to a module level variable, as the QBASIC Help says. For that to work, you have to define the variable at the module level.

I made some other changes too, which are improvements in my opinion, but it could still use some more improvements. For example, a possible improvement would be combining all three operations, so that you can scroll through the list of states, select one to delete, or just start typing to add a new one...

Regards,
Michael



    
This message has been edited by MCalkins on May 11, 2012 12:40 AM

Posted on May 11, 2012, 12:39 AM

Respond to this message   

Return to Index


Good but..

by Matt (no login)

Thank you. It looks vary nice compared to my version. There is only one problem with it. This is a homework assignment and the teacher is expecting a certain level of... "simplicity" since i am a beginner. I will however try to use some of your suggestions to get the original working.

Thanks again,
Matt

Posted on May 11, 2012, 5:50 AM

Respond to this message   

Return to Index


Oi...

by (Login MCalkins)
Moderator

You had said on the other post, about sharing arrays, that it wasn't homework, and since this was obviously related, I guess I applied it to this also. Well, thanks for being honest about it.

Here's your version, with just a few modifications, and some comments added throughout. (The comments are for you, not for the program you turn in.)

By the way, you could use DIM SHARED STATES(50) AS STRING at the module level, and share it with all SUBs. What the program below does is to shared it only with the SUBS that have SHARED STATES() AS STRING in them. I'm assuming that's what you want.

Best wishes regarding your assignment, and your endeavor to learn programming.

Regards,
Michael

--------------------------------

DECLARE SUB ENTERSTATES ()
DECLARE SUB PRINTSTATES ()

'Note that this array will have 51 elements, numbered 0 to 50.

DIM STATES(50) AS STRING
DIM MENU AS INTEGER

CLS

' ** MENU **
DO
PRINT
PRINT "1) INPUT A STATE INTO THE ARRAY"
PRINT "2) DELETE A STATE FROM THE ARRAY"
PRINT "3) DISPLAY THE STATES STORED IN THE ARRAY"
PRINT "4) QUIT"
PRINT
INPUT "MAKE A SELECTION FROM THE ABOVE LIST (1, 2, 3, OR 4):", MENU
PRINT

'if your teacher has taught you SELECT CASE, consider changing the next IF
'block to SELECT CASE.
'hypothetically, the user could enter a negative number, but you only check
'for >4.

IF MENU = 1 THEN
ENTERSTATES
ELSEIF MENU = 2 THEN PRINT "MENU 2 SELECTED"
ELSEIF MENU = 3 THEN
PRINTSTATES
ELSEIF MENU > 4 THEN
PRINT "!! YOU HAVE ENTERED AN INVALID SELECTION !!"
PRINT
END IF
LOOP UNTIL MENU = 4

' ** INPUT ARRAY **
SUB ENTERSTATES
SHARED STATES() AS STRING
DIM STATE AS STRING
DIM x AS INTEGER
DIM y AS INTEGER
DIM Found AS INTEGER
CLS

FOR x = 1 TO 50

'one problem is that, if you have already entered states, you are overwriting
'them without checking. My other revision looped until it found an "" one to
'fill.

DO
INPUT "Enter Name: ", STATE
Found = 0

'a little oddity will be that the user will be able to enter one and only one
'empty, that is: "", string. My other revision got around that by using ""
'instead of "exit" to exit the loop.

IF UCASE$(STATE) = "EXIT" THEN 'changed to UCASE$() for simplicity.
EXIT SUB
END IF

FOR y = 1 TO 50
IF UCASE$(STATE) = UCASE$(STATES(y)) THEN
Found = 1
END IF

NEXT y

IF Found = 1 THEN
PRINT
PRINT "!! STATE ALREADY IN ARRAY !!"
PRINT
END IF
LOOP UNTIL Found = 0

STATES(x) = STATE
NEXT x

PRINT

END SUB

' ** PRINT ARRAY **
SUB PRINTSTATES
SHARED STATES() AS STRING
DO UNTIL EXIT$ = "EXIT" OR EXIT$ = "Exit" OR EXIT$ = "exit"
' I guess you would want to loop through the STATES() array, printing it's
' contents. As there are 50 states, and 25 lines on the screen, you'll have
' to use multiple columns, or have some kind of delay, or something.
' PRINT STATES(x)

INPUT "TYPE EXIT TO RETERN TO MENU: ", EXIT$
LOOP
END SUB

Posted on May 11, 2012, 12:51 PM

Respond to this message   

Return to Index


RE

by Matt (no login)

Thank you.
I will give that a try.
Not that it matters but i am working on both homework and personal "for fun" stuff. Both require the use of shared arrays in subs and functions. I specified "not for homework" because i have seen several posts where there was little to no help because it was immediately assumed that the question was homework related.
Yes, this is for homework but I am trying to write some programs for personal use also which require the use of similar techniques. In other words, i will probably be posting questions regarding both homework and personal projects. Mainly it will likely be homework for the next month or so. I will do my best to specify which is which.

Thanks again for the help!

Posted on May 12, 2012, 11:43 AM

Respond to this message   

Return to Index


* No problem. yw.

by (Login MCalkins)
Moderator

Posted on May 12, 2012, 12:11 PM

Respond to this message   

Return to Index


At least that means that you want to learn.

by (Login MCalkins)
Moderator

We sometimes have people coming here to cheat on their homework, with absolutely no desire to learn (some admit it, other you can just tell.). That's one of the reasons why I would not be in favor of mandatory programming classes.

Regards,
Michael

Posted on May 12, 2012, 6:31 PM

Respond to this message   

Return to Index


My usage of SLEEP in the menu loop is incorrect

by (Login MCalkins)
Moderator

and was based on a misunderstanding. I though SLEEP would not delay if the keyboard buffer was not empty, but it does delay if the keyboard buffer isn't empty, but there are no current keystrokes.

So, the SLEEP inside the menu loop should be removed.

Regards,
Michael

Posted on May 12, 2012, 3:40 PM

Respond to this message   

Return to Index


UGH..

by mATT (no login)

Michael,
I have been messing around with the original code that you posted. I realized that in the DeleteStates SUB only the first name entered is deleted. I have been messing with it for about an hour now and cannot seem to figure out why. Any suggestions?

Posted on May 12, 2012, 5:54 PM

Respond to this message   

Return to Index


Re: UGH..

by (Login MCalkins)
Moderator

It was supposed to be the array index number. If you enter text other than a number, VAL() turns it to 0. 0 is the first element...

Regards,
Michael

Posted on May 12, 2012, 6:28 PM

Respond to this message   

Return to Index


I downloaded qb64 but won't run

by Tom Geiter (no login)

I downloaded qb64 but won't run. My computer says its damaged. How can I make it run? I retyped this because the other one was hard to read sorry.

Posted on May 10, 2012, 8:25 AM

Respond to this message   

Return to Index


Re: I downloaded qb64 but won't run

by (Login MCalkins)
Moderator

Did you download it correctly?

qb64v0954-win.7z
size: 30,801,179
md5: 0bebdb85dc713190c2534e8b5e0eadcc
sha1: 32c9224b5512fefc9652cbc297f74d0811bffc19
sha256: 95b4a904bd4ba4527ff1fc31660b202b2d9a8c31467004467e41f33a3e0adcc0

What exact version/edition of Windows are you using?

What folder are you trying to extract it to?

Regards,
Michael

Posted on May 10, 2012, 1:00 PM

Respond to this message   

Return to Index


QBasic under XP - changing from full screen to a window

by (Login slowneutron)

Is there a way of changing the QBasic edit and output screens (eg after a screen 12 statement) from full screen back to the QBasic window without exiting and re-loading a program?

Alt + Enter from the edit screen changes the edit screen from full screen to a window only temporarily. Going to the output screen (eg by a PRINT statement or F4) and then back to the edit screen brings the edit screen back to full screen again.

Alt + Enter from the output screen only minimises the screen. On maximumising, the full screen is displayed again.

Posted on May 10, 2012, 2:09 AM

Respond to this message   

Return to Index


Passing ARRAY "FROM" SUB to SUB

by MATT (no login)

Is there a way to pass an array from one subroutine to another? I cannot seem to get it to work...

Note: this is not homework

Posted on May 9, 2012, 9:17 PM

Respond to this message   

Return to Index


I assume you mean other than DIM SHARED...

by (Login MCalkins)
Moderator

DECLARE SUB a ()
DECLARE SUB b (z() AS INTEGER)
CLS
a

SUB a
 DIM n(0 TO 2) AS INTEGER
 n(0) = 1
 n(1) = 3
 n(2) = 5

 b n()
END SUB

SUB b (z() AS INTEGER)
 DIM i AS INTEGER
 FOR i = 0 TO UBOUND(z)
  PRINT z(i)
 NEXT
END SUB

--------------------------------

That seems to work, but I am inexperienced in passing arrays in BASIC. I'd appreciate anyone pointing out mistakes.

Notice that an array, "n" is created in the "a" sub, and is local to that sub. However, "a" calls "b", passing "n" by reference. "b" gets it as "z", and uses UBOUND() to know how big it is.

As the array is local to the "a" sub, it is destroyed when "a" exits. (It is not SHARED or STATIC.)

Regards,
Michael



    
This message has been edited by MCalkins on May 9, 2012 10:33 PM

Posted on May 9, 2012, 10:32 PM

Respond to this message   

Return to Index


Passing arrays

by Solitaire (Login Solitaire1)
S

I just dug up something I wrote back in 2006 for my class. Not sure if this will help with your question, but here it is:

DECLARE SUB entry (T AS INTEGER, item() AS STRING, trio() AS INTEGER)
DECLARE SUB show (T AS INTEGER, item() AS STRING, trio() AS INTEGER)
DIM sT AS STRING, T AS INTEGER 'local variable
DIM trio(3) AS INTEGER 'local static array
REDIM item(0) AS STRING 'local dynamic array
CLS : PRINT "Enter items in a list."
INPUT "How many items are there"; sT$
T = VAL(sT$)
PRINT
CALL entry(T, item$(), trio())
PRINT
PRINT "Here is a list of all your items:"
PRINT
CALL show(T, item$(), trio())
END

SUB entry (T AS INTEGER, item() AS STRING, trio() AS INTEGER)
DIM x AS INTEGER
REDIM item(T) AS STRING
FOR x = 1 TO T
PRINT "Enter item #"; x;
INPUT ": ", item$(x)
NEXT x
FOR x = 1 TO 3
trio(x) = x * 3
NEXT x
END SUB

SUB show (T AS INTEGER, item() AS STRING, trio() AS INTEGER)
DIM x AS INTEGER
FOR x = 1 TO T
PRINT x; item$(x)
NEXT x
FOR x = 1 TO 3
PRINT , trio(x)
NEXT x
END SUB

Posted on May 10, 2012, 4:18 AM

Respond to this message   

Return to Index


i believe you can also

by stosb (no login)

use ANY as the data type in case you want to pass a custom TYPE

SUB test(A() AS ANY)

It has been some time since I tried

Posted on May 12, 2012, 12:22 AM

Respond to this message   

Return to Index


* That might be PDS or VB or something. QBASIC won't let you.

by (Login MCalkins)
Moderator

Posted on May 12, 2012, 11:42 AM

Respond to this message   

Return to Index


*i thought it was qb4.5

by stosb (no login)

Posted on May 12, 2012, 1:07 PM

Respond to this message   

Return to Index


you're right

by (Login MCalkins)
Moderator

But I get the impression that it is probably meant for external CDECL functions.

To my surprise, QBASIC 1.1 actually allows it in declarations, but it doesn't seem to usable for anything.

Regards,
Michael

Posted on May 14, 2012, 10:07 PM

Respond to this message   

Return to Index


QBX Compiler

by Nestor (no login)

Hi, I'm new here... I need help finding a compiler

I have a code in QBX 7.1 and I need a full compatible 64-bits compiler.

The aplicaton is too big to translate it to other 'QB Like' language, so I'm looking for a compiler to make the exe's files for Win7 64.

I'm using a virtual machine to run the soft in 16 bits, but isn't a good solution.

I already try the QB64, but doesn't work...

Do you know another compiler that I can use?


Thanks

Posted on May 7, 2012, 5:47 PM

Respond to this message   

Return to Index


Re: QBX Compiler

by (Login MCalkins)
Moderator

Welcome to the forums.

I'm thinking that there isn't one.

QB64 is probably the best option, although it doesn't aim for QBX 7.1 compatibility, but rather Qbasic 1.1/QB 4.x. Also, QB64 doesn't actually target Win64 yet; it targets Win32, but it will run on 64 bit Windows.

What part of your program isn't working in QB64?

The other compiler is FreeBASIC, but I don't think it targets Win64 either, and I would expect significantly less compatibility than you would get from QB64.

Proprietary compilers targeting Windows include PowerBASIC and VisualBASIC (up to version 6). I wouldn't expect very good QBX compatibility from either of them. Pete or Clippy would know more.

As far as I can tell, none of those are actually 64 bit compilers. I think they are all 32 bit compilers. But remember, 32 bit code will run on 64 bit Windows just fine.

A google search reveals PureBasic and xbasic. PureBasic is a 64 bit compiler, but it seems that you have to pay for it. I don't know if it's QBX compatible. I can't tell if xbasic is 64 bit, but it's not QBX compatible.

I still think QB64 is probably your best bet, other than actual QBX in DOSBox.

Regards,
Michael

P.S. QB64 is also a 64 bit compiler on it's non-Windows targets (Linux, Mac OS X). I believe it could be made to target Win64 with very little modification. (I think Galleon has designed for it, just hasn't enabled it yet.)



    
This message has been edited by MCalkins on May 7, 2012 8:06 PM

Posted on May 7, 2012, 8:02 PM

Respond to this message   

Return to Index


Re: QBX Compiler

by Nestor (no login)

Hello, thanks for answer.

I try XBase, GB32, and doesn't work. FreeBasic work on a simple code, but not with a more complex one.

Now I'll trying QB64, but is a little slow on big files (~ 3000 lines + several includes) and report only 1 error at time but is promising.

I need to read the documentation first, because I have some errors, maybe on unsupported features.

The current error is Illegal string-number conversion on line:
IMAGEDIR = Trim$(RUTA(GRUPO.UNICO)) + "\IMAGPROD"

and in some place:
DIM RUTA(MAX.GRUPOS.ARCHIVOS) AS STRING * 63
COMMON SHARED RUTA() AS STRING * 63
CONST GRUPO.UNICO = 2
DIM SHARED IMAGEDIR AS STRING
DECLARE FUNCTION Trim$(S AS STRING)

Is a problem for the dot in the variable name?
is the COMMON?

I also have problems with COMMON /name/
and in the call to C functions, but do not have an error in the CDECL line... yet
is CDECL supported?

And another question, how I can make separated object files and then link them?

I have the DECLEAR's, so don't have the "undeclared external" error, but I don't know how to link the files together.

Thank you again for your time.

Posted on May 8, 2012, 5:52 PM

Respond to this message   

Return to Index


I'm not very sure.

by (Login MCalkins)
Moderator

QB64 doesn't support multiple modules yet. I think it is something Galleon will be working on later this year. I'm not sure what kind of linking arrangement he will have, though.

Currently, if you need to call C code, the way to do it is with DECLARE LIBRARY. There are several specific ways of going about it.

Even though the project is large, if you post a link to it (including the C source code), I could take a look to see what would be involved in adapting it. It might be feasible.

Regards,
Michael

Posted on May 9, 2012, 12:13 AM

Respond to this message   

Return to Index


Flick me the code...

by Galleon (no login)

It could work with some simple changes. 32-bit apps run on Windows 64-bit so no dramas there.

Email it to me: galleondragon@gmail.com
If the code is a 'secret' (though I will treat it privately if you instruct me to do so), and given your stance towards making modifications to the source, I'm afraid DOSBOX is your only option.

Posted on May 8, 2012, 12:41 AM

Respond to this message   

Return to Index


Re: Flick me the code...

by Néstor (no login)

Thanks,

Is not 'secret', but I have an application of more than 400 source files, with about 9Mb of source code, and its difficult to make changes... so, if QB64 do not support the code as is, I think have no chance more than use DOSBOX

Posted on May 8, 2012, 5:58 PM

Respond to this message   

Return to Index


What PDS keywords does it use?

by (Login burger2227)
R

If there are not a lot, it could work pretty easily. DIR$, etc? We might have ways to get around them. Memory is not a problem.

Posted on May 8, 2012, 11:17 PM

Respond to this message   

Return to Index


RE: so, if QB64 do not support the code as is, I think have no chance...

by Galleon (no login)

I disagree. Zip it up and send it my way. At the very least I'll get it to compile for you.

Posted on May 9, 2012, 3:54 AM

Respond to this message   

Return to Index


I'm new

by (no login)

so far micheal calkins has taught me how to compose beeps and colors plus some basic hot key type commands. I want to know what are the ultra advanced applications of learning programming? Just curious to know whats has all you guys so interested. I'll browse around the forum to get an idea maybe.

Posted on May 7, 2012, 1:50 PM

Respond to this message   

Return to Index


Welcome aboard, Mr. Jonathan.

by (Login MCalkins)
Moderator

Jonathan Moore is my friend. He lives in my hometown of Floresville, and I met him some years ago when we were coworkers.

I've been trying to talk him into learning programming.

Jon, I take it you've got some free time today? I'm planning on heading to town this afternoon. I'll stop by and see if you are home.

Regards,
Michael



    
This message has been edited by MCalkins on May 7, 2012 2:21 PM

Posted on May 7, 2012, 2:07 PM

Respond to this message   

Return to Index


* Here is a discussion from June 2005 (URL)

by (Login MCalkins)
Moderator

http://www.network54.com/Forum/13959/message/1119576657/Why+did+all+of+you+start+programming-

It's in the old main forum, which is archived (read only) now.

Posted on May 7, 2012, 2:20 PM

Respond to this message   

Return to Index


A better way to code debugs

by Docfxit (Login Docfxit)
R

I have this code to print debugging statements throughout the program.
It looks cumbersome to me. Do you have a better way of printing
1. Text
2. A text variable
3. A numeric variable

The way it's written If I don't want var2 to print I put it equal to 999
Currently If var2 doesn't print var3$ always prints and I don't want it to.

ON ERROR GOTO ErrorHandler

debugflag$ = "Onn3" 'For debugging

ErrorHandler:
ErrorCode = ERR
Ix = Ix + 1

SELECT CASE ERR
CASE 155: LastErrorLine = _ERRORLINE
END SELECT
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
' This If statement works but I'd like some help in making it more efficient
' I'm sure there must be a better way to do it
IF ERR = 155 THEN 'Debug
'** Print line and variable to screen
IF var2 999 THEN
COLOR 11, 0: LOCATE Ix, 1: PRINT "On Line "; LastErrorLine; var1$; var2
ELSE
COLOR 11, 0: LOCATE Ix, 1: PRINT "On Line "; LastErrorLine; var1$; var3$
END IF
END IF
RESUME NEXT

' This If statement goes in the middle of my code when I only want text to print.
IF debugflag$ = "Onn3" THEN
var1$ = "Text Only " 'For Debuging Only
var2 = 999 'For Debuging Only
ERROR 155 'For Debuging Only
END IF

' This If statement goes in the middle of my code when I want one line of text
' and one character variable printed.
IF debugflag$ = "Onn3" THEN
var1$ = "Text and one character variable - wsFileNum = " 'For Debuging Only
var2 = wsFileNum 'For Debuging Only
ERROR 155 'For Debuging Only
END IF

' This If statement goes in the middle of my code when I want one line of text
' and one numeric variable printed.
IF debugflag$ = "Onn3" THEN
var1$ = "Text and one numeric variable - tmp$ = " 'For Debuging Only
var2 = 999 'For Debuging Only
var3$ = tmp$ 'For Debuging Only
ERROR 155 'For Debuging Only
END IF



    
This message has been edited by Docfxit on May 5, 2012 3:34 PM

Posted on May 5, 2012, 3:33 PM

Respond to this message   

Return to Index


Is there a way

by Docfxit (Login Docfxit)
R

Is there a way to put the value of
var3$ into var2 so I don't need the extra field?

Thanks,

Docfxit

Posted on May 8, 2012, 8:11 AM

Respond to this message   

Return to Index


Re: Is there a way

by (Login MCalkins)
Moderator

If Var3$ contains a number, VAL().

If you want to store the value of var2 into var3$, there are a number of functions you could use, STR$() probably being most obvious.

Regards,
Michael

Posted on May 8, 2012, 8:37 AM

Respond to this message   

Return to Index


How could I make this work?

by Docfxit (Login Docfxit)
R

How could I make this work without changing the const line and
without changing var2$

CONST theComPort = 1

var2$ = STR(theComPort) 'For Debuging Only

Thanks,

Docfxit

Posted on May 8, 2012, 8:38 PM

Respond to this message   

Return to Index


* You're missing an $

by (Login MCalkins)
Moderator



    
This message has been edited by MCalkins on May 8, 2012 9:00 PM

Posted on May 8, 2012, 8:43 PM

Respond to this message   

Return to Index


* Thank you. That worked great.

by Docfxit (Login Docfxit)
R

Posted on May 11, 2012, 1:12 PM

Respond to this message   

Return to Index


Compile without QB64

by (no login)

Hi, is there a way to use a bat file to compile a bas to an exe? The bas file would contain in it '$include:'x.bas' and x.bas would only consist of other 'Sinclude:'d txt documents, if that makes a difference. I know that you can use recompile.bat to recompile the last thing that was made but, this is probably a bit different. Thanks for your help.

Posted on May 5, 2012, 9:55 AM

Respond to this message   

Return to Index


QB64.exe -c %1

by (Login burger2227)
R

I made a batch that can be added to the Open With right click BAS menu:



@Echo off
Title QB64 Compiler
color 5F

REM BATCH file MUST be in the QB64 folder!
Set QB64=%~dp0
Echo.QB64 Path: %QB64%

REM Get filename only:
Set FILE=%~nx1
Echo.BAS file: %FILE%

REM Replace BAS with EXE:
SET BASfile=%FILE%
SET EXEfile=%BASfile:.BAS=.EXE%
Echo.EXE file: %EXEfile%
Echo.
REM Get BAS file path:
Set OLDIR=%CD%
Set "OLDPATH=%OLDIR%\%EXEfile%"

REM Change to the QB64 folder path:
CD "%QB64%"

REM Set QB64 folder path:
Set "NEWPATH=%QB64%%EXEfile%"

REM Display Paths:
Echo.QB64 file: %NEWPATH%
Echo.Move file: %OLDPATH%

REM Compile BAS file:
cmd /c start /low QB64.exe -c %1

REM Skip COPY if compiling BAS file in the QB64 folder:
IF "%NEWPATH%" == "%OLDPATH%" GOTO END

ECHO.
ECHO.
ECHO PRESS a Key to MOVE file when Compile has completed!
ECHO.
Pause

ECHO.
MOVE /-Y "%NEWPATH%" "%OLDIR%"
REM COPY "%NEWPATH%" "%OLDPATH%" /-Y
ECHO.
Pause
GOTO END

:END
CLS


Just put it in the QB64 folder and right click a BAS file from anywhere. Afte QB64 compiles, the batch will move the EXE back to the BAS file's folder. It will ask if the EXE already exists there.

Posted on May 5, 2012, 11:38 AM

Respond to this message   

Return to Index


Thanks

by (no login)

Thank you Clippy. How would you get it to wait for a file to exist before continuing? I tried this:

:a
if exist x.exe goto a

but that doesnt seem to work. Alternatively, how would you tell it to include a .o file when it runs the QB64 compiler?

Posted on May 5, 2012, 4:04 PM

Respond to this message   

Return to Index


Try this:

by (Login burger2227)
R

I got this to work. Edit bottom of batch. See if it works for you:


REM Skip COPY if compiling BAS file in the QB64 folder:
IF "%NEWPATH%" == "%OLDPATH%" GOTO END ELSE GOTO Check


:Check
IF EXIST "%NEWPATH%" (GOTO Finish) ELSE (PING 127.0.0.1 -w 1000 -n 3 >NUL)
GOTO Check

:Finish
REM PING 127.0.0.1 -w 1000 -n 10 >NUL
ECHO.
MOVE /-Y "%NEWPATH%" "%OLDIR%"
REM COPY "%NEWPATH%" "%OLDPATH%" /-Y
ECHO.
GOTO END

:END
CLS


Using PING can set a delay for 3 or more seconds as above. Thanks for the idea! I never got around to that LOL.

You may need the second PING if QB64 takes too long. I had that problem on some compiles. If it doesn't move it, it will be in QB64 folder.



    
This message has been edited by burger2227 on May 5, 2012 9:27 PM
This message has been edited by burger2227 on May 5, 2012 8:14 PM
This message has been edited by burger2227 on May 5, 2012 7:40 PM
This message has been edited by burger2227 on May 5, 2012 7:39 PM
This message has been edited by burger2227 on May 5, 2012 7:31 PM
This message has been edited by burger2227 on May 5, 2012 7:13 PM
This message has been edited by burger2227 on May 5, 2012 7:12 PM

Posted on May 5, 2012, 7:11 PM

Respond to this message   

Return to Index


*Thank You

by (no login)

Posted on May 6, 2012, 5:57 AM

Respond to this message   

Return to Index

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