Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


ok some help with a few things

BravoknightBravoknight Member Posts: 35 can i delete files that i have made with the open output ....? can i delete certain sections of an array without deleting the entire thing?
3.lets say i get the array saved, and then open it with open input...and then want to keep adding onto it at the end can i get an array to be listed (let say i want it to be printed on the screen) in alphabetical order, or by certain catagories can i make the user be able to search an array for something, like a certain name


  • alan_pollockalan_pollock Member Posts: 110
    1) to delete files, use the KILL statement
    KILL drive:pathfileNameString

    2 & 3 are related)
    You'll need to manage an array, as Basic does not have the built-in functionality to do the tasks you require. Using the $DYNAMIC metacommand, initially dimension the array using the DIM statement to the value 1. As you add/remove elements to/from the array, you adjust the array's size using the REDIM statement. Keep in mind that REDIM first deallocates the array space, losing it's contents, before reallocating it's new space... meaning you've got to save it's contents first.

    4) to print data to the screen, use the PRINT statement
    PRINT arrayName(element)

    Alphabetizing requires sorting the array, and likewise for grouping. There are several different methods one could use in sorting an array, such as a simple sort, or bubble sort, or merge-sort. You should refer to some reference on sorting methods.

    5) Searching through the array can be accomplished in differnt ways also. How you're intending on structuring the array's content will help define a method.

    Keep in mind that before creating any array, you need to decide the OPTION BASE you'll be using. Refer to QBasic's inline help on the KILL, $DYNAMIC, DIM, REDIM, PRINT, and OPTION BASE statements.

  • BravoknightBravoknight Member Posts: 35
    ok thanks but about number 4, i already knew about PRINT, what i meant is that how can i print them alphabetically if they arent.
    i have names in my array:
    ...but i want it to print
    (alphabetical order, i know i could use locate) but then i add Ashley to the list, then it would be wrong, u get what im saying??????
  • brisraybrisray Member Posts: 60

    here's a qucicksort subroutine that I use for sorting arrays. It's a quicksort algorithm and so is very fast.

    It is called by using

    SortArrays MyArray$(), 1, UBOUND(MyArray$)

    If you don't like using formal subroutines then add the code between SUB and END SUB to the end of your program, change all the references to SortArray$() to the name of your array, add a label to the top, RETURN to the bottom and call it like this

    Low = 1
    High = UBOUND(MyArray$)
    GOSUB SortArrays



    If your array contains more than 32,767 subscripts then DIM all the variables referrenced as integers to LONGs.

    As you can see, as QBasic makes its comparisons bitwise so it's capable of sorting text as well as numbers.


    SUB SortArrays (SortArray$(), Low AS INTEGER, High AS INTEGER)

    '*** This is a QuickSort routine ***

    DIM RandIndex AS INTEGER

    'QuickSort works by picking a random "pivot" element in SortArray, then
    'moving every element that is bigger to one side of the pivot, and every
    'element that is smaller to the other side. QuickSort is then called
    'recursively with the two subdivisions created by the pivot. Once the
    'number of elements in a subdivision reaches two, the recursive calls end
    'and the array is sorted.

    IF Low < High THEN

    ' *** Only two elements in this subdivision ***
    ' *** Swap them if they are out of order, then end recursive calls: ***

    IF High - Low = 1 THEN
    IF SortArray$(Low) > SortArray$(High) THEN
    SWAP SortArray$(Low), SortArray$(High)
    END IF


    '*** Pick a pivot element at random, then move it to the end ***

    RandIndex = INT(RND * (High - Low + 1)) + Low
    SWAP SortArray$(High), SortArray$(RandIndex)
    Partition$ = SortArray$(High)

    '*** Move in from both sides towards the pivot element ***

    Lower = Low
    Higher = High
    DO WHILE (Lower < Higher) AND (SortArray$(Lower) <= Partition$)
    Lower = Lower + 1

    DO WHILE (Higher > Lower) AND (SortArray$(Higher) >= Partition$)
    Higher = Higher - 1

    '*** If pivot element not reached, it means that ***
    '*** two elements on either side are out of order, ***
    '*** so swap them ***

    IF Lower < Higher THEN
    SWAP SortArray$(Lower), SortArray$(Higher)
    END IF

    LOOP WHILE Lower < Higher

    '*** Move the pivot element back to its proper place in the array ***

    SWAP SortArray$(Lower), SortArray$(High)

    '*** Recursively call the SortArray sub ***
    '*** Pass the smaller subdivision first to use less stack space ***

    IF (Lower - Low) < (High - Lower) THEN
    SortArrays SortArray$(), Low, Lower - 1
    SortArrays SortArray$(), Lower + 1, High
    SortArrays SortArray$(), Lower + 1, High
    SortArrays SortArray$(), Low, Lower - 1
    END IF
    END IF
    END IF



    Something else, on the National Institute of Standards and Technology site there is one of the best programmers references on the net I've ever found (apart from this forum). It's called the Dictionary of Algorithms and Data Structures and can be found at

  • alan_pollockalan_pollock Member Posts: 110

    Thanks for posting that site, it's a good one.


  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ________ / / free ebooks and video tutorials about // Python, Visual Basic, MATLAB, C++, C#, Ruby, Go, PL/SQL, Objective-C, C, Perl, Swift, Delphi, Java, PHP, JavaScript, Scratch, Visual Basic .NET, Assembly, R Hack, Fortran, Clojure, Dart, ABAP, Ada, Erlang, Crystal, Awk, Lisp, VBScript, F#, Apex, Scheme, Logo, Prolog, Julia, D, COBOL, Rust, Bash, FoxPro, Kotlin, Lua, Scala, Alice, ML, SAS, Transact-SQL, LabVIEW // __

Sign In or Register to comment.