Click here to Skip to main content
15,919,358 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionhaving problems with program to merge sort a given set of input Pin
benkazy101415-Oct-12 0:23
benkazy101415-Oct-12 0:23 
QuestionRe: having problems with program to merge sort a given set of input Pin
Eddy Vluggen15-Oct-12 0:50
professionalEddy Vluggen15-Oct-12 0:50 
AnswerRe: having problems with program to merge sort a given set of input Pin
benkazy101415-Oct-12 1:36
benkazy101415-Oct-12 1:36 
QuestionRe: having problems with program to merge sort a given set of input Pin
Eddy Vluggen15-Oct-12 2:16
professionalEddy Vluggen15-Oct-12 2:16 
AnswerRe: having problems with program to merge sort a given set of input Pin
benkazy101415-Oct-12 2:38
benkazy101415-Oct-12 2:38 
GeneralRe: having problems with program to merge sort a given set of input Pin
Eddy Vluggen15-Oct-12 2:47
professionalEddy Vluggen15-Oct-12 2:47 
AnswerRe: having problems with program to merge sort a given set of input Pin
benkazy101415-Oct-12 1:38
benkazy101415-Oct-12 1:38 
GeneralRe: having problems with program to merge sort a given set of input Pin
Member 132474409-Jun-17 17:20
Member 132474409-Jun-17 17:20 
you'll have to modify this code to suit your needs, but this is how I sort/merge text files.
m& = LBOUND(Master)
s& = LBOUND(Slave)
t& = 0
DO
    IF m& < MasterLines& THEN '* aka not eof(masterfile%)
        IF s& < SlaveLines& THEN '* aka not eof(slavefile%)
            IF Master(m&) > Slave(s&) THEN '* reached end of primary so flush secondary
                printToFile Slave(s&), OChannel%, s&, t&
            ELSE
                printToFile Master(m&), OChannel%, m&, t&
            END IF
        ELSE
            printToFile Master(m&), OChannel%, m&, t&
        END IF
    ELSE
        IF s& < SlaveLines& THEN
            printToFile Slave(s&), OChannel%, s&, t&
        ELSE
            EXIT DO
        END IF
    END IF
LOOP
CLOSE OChannel%
PRINT MasterLines& " lines merged from Master file "; Mast$
PRINT SlaveLines& " lines merged from Slave file "; Slav$
PRINT t& " Records written to "; OutPF$
DO
LOOP UNTIL INKEY$ > ""
SYSTEM

SUB printToFile (x$, channel%, RecsPrinted&, t&)
t& = t& +1 '* increment the appropriate array counter
RecsPrinted& = RecsPrinted& + 1 ' keep track of how many processed so far
PRINT #channel%, x$
END SUB


SUB MergeSort (array() AS STRING, start&, finish&)
IF start& < finish& THEN '* no need to do this for 0-sized sublists
    length& = finish& - start& + 1
    middle& = start& + (finish& - start&) \ 2
    MergeSort array(), start&, middle&
    MergeSort array(), middle& + 1, finish&
    REDIM temp(0 TO length& - 1) AS STRING
    FOR i& = 0 TO length& - 1
        temp(i&) = array(start& + i&)
    NEXT
    mptr& = 0
    sptr& = middle& - start& + 1
    FOR i& = 0 TO length& - 1
        IF sptr& > finish& - start& THEN
            array(i& + start&) = temp(mptr&)
            mptr& = mptr& + 1
        ELSE
            IF mptr& > middle& - start& THEN
                array(i& + start&) = temp(sptr&)
                sptr& = sptr& + 1
            ELSE
                IF temp(mptr&) > temp(sptr&) THEN
                    array(i& + start&) = temp(sptr&)
                    sptr& = sptr& + 1
                ELSE
                    array(i& + start&) = temp(mptr&)
                    mptr& = mptr& + 1
                END IF
            END IF
        END IF
    NEXT
    ERASE temp
END IF
END SUB

Question[SOLVED] How to update Gridview with value textbox = Null Pin
zaimah14-Oct-12 22:25
zaimah14-Oct-12 22:25 
AnswerRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen15-Oct-12 0:48
professionalEddy Vluggen15-Oct-12 0:48 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah15-Oct-12 5:46
zaimah15-Oct-12 5:46 
GeneralRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen15-Oct-12 6:13
professionalEddy Vluggen15-Oct-12 6:13 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah15-Oct-12 13:48
zaimah15-Oct-12 13:48 
GeneralRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen16-Oct-12 0:14
professionalEddy Vluggen16-Oct-12 0:14 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah16-Oct-12 2:35
zaimah16-Oct-12 2:35 
GeneralRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen16-Oct-12 2:42
professionalEddy Vluggen16-Oct-12 2:42 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah16-Oct-12 2:59
zaimah16-Oct-12 2:59 
GeneralRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen16-Oct-12 3:17
professionalEddy Vluggen16-Oct-12 3:17 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah16-Oct-12 3:50
zaimah16-Oct-12 3:50 
GeneralRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen16-Oct-12 4:21
professionalEddy Vluggen16-Oct-12 4:21 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah17-Oct-12 4:13
zaimah17-Oct-12 4:13 
GeneralRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen17-Oct-12 4:51
professionalEddy Vluggen17-Oct-12 4:51 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah17-Oct-12 5:25
zaimah17-Oct-12 5:25 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah17-Oct-12 6:04
zaimah17-Oct-12 6:04 
GeneralRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen17-Oct-12 9:20
professionalEddy Vluggen17-Oct-12 9:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.