Results 1 to 8 of 8

Thread: gwBasic

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2016
    Posts
    51

    gwBasic

    I have some small programs I coded in gwBasic that I want to code in vb6. I don't know exactly where to start. It's not numbered lines in vb6 I attached the code from a gwbasic program
    Attached Files Attached Files

  2. #2
    Frenzied Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,155

    Re: gwBasic

    What is attached isn't a Basic source program that can be examined - but a 'binary' version which can't be displayed as Basic source code outside of GWBasic. To get the program as ascii text, open the program in GWbasic and save with the ,a option.

    This is the source for the attached program:

    Code:
    10 DIM NH$(20),VEL1(20),VEL2(20),VEL3(20),MED(20),BL1(20),BL2(20),D$(20),F1(20),F2(20),F3(20)
    20 CLS
    30 LOCATE 15,28: PRINT "LOAD FILE FROM DISK ?  (N)"
    40 L$=INKEY$:IF L$="" THEN 40
    50 IF L$ = "Y" THEN CLS: FILES "*.TXT": GOTO 70
    60 GOTO 90
    70 LOCATE 17,28: INPUT "NAME OF FILE TO LOAD ";RACE$
    80 GOTO 1300
    90 CLS
    100 LOCATE 10,30:INPUT "RACE ======> ",RACE$
    110 LOCATE 12,30:INPUT "COMMENTS ==> ",C$
    120 LOCATE 14,30:INPUT "DIST ======> ",DIST$
    130 CLS
    140 IF N=0 THEN N=1
    150 LOCATE 8,24:PRINT "NAME  #";N;
    160 INPUT "               ",NH$
    170 IF NH$ = "" THEN 660
    180 NH$(N) = NH$
    190 LOCATE 10,24:INPUT "DIST OF PACELINE          ",D$
    200 D$(N)=D$
    210 LOCATE 12,24:INPUT "TIME 1ST CALL             ",T1$
    220 T1 = VAL(T1$)
    230 F=T1-INT(T1)
    240 T1=(F*2)+INT(T1)
    250 IF T1 >= 100 THEN T1 = T1 - 40
    260 LOCATE 13,24:INPUT "TIME 2ND CALL             ",T2$
    270 T2 = VAL(T2$)
    280 F=T2-INT(T2)
    290 T2=(F*2)+INT(T2)
    300 IF T2 >= 100 THEN T2 =T2-40
    310 LOCATE 14,24:INPUT "FINAL TIME                ",T3$
    320 T3=VAL(T3$)
    330 F=T3-INT(T3)
    340 T3=((F*2)+INT(T3))-40
    350 IF T3 > 160 THEN T3=T3-40
    360 IF T3<60 THEN T3=T3+40
    370 LOCATE 16,24:INPUT "BEATEN LENGTHS 1ST CALL    ",B1$
    380 B1 = VAL(B1$)
    390 LOCATE 17,24:INPUT "BEATEN LENGTHS 2ND CALL    ",B2$
    400 B2 = VAL(B2$)
    410 LOCATE 18,24:INPUT "BEATEN LENGTHS FINISH      ",B3$
    420 B3 =VAL(B3$)
    430 LOCATE 22,27:INPUT "DATA O.K. ";OK$
    440 IF OK$ = "N" THEN CLS: GOTO 150
    450 D=VAL(D$)
    460 IF D=1.4 THEN D=8.181
    470 IF D = 1.7 THEN D = 8.318
    480 IF D>=8 THEN D1=4:D2=6:BF=9
    490 IF D<8 THEN D1=2:D2=4
    500 IF D>=10 THEN D1=4:D2=6:BF=11
    510 IF D>=9 THEN BF=10
    520 IF D<=7.5 THEN BF=8
    530 IF D<6 THEN BF=7
    540 D3=D
    550 VEL1(N)=((D1*660)-(BF*B1))/T1
    560 VEL2(N)=(((D2-D1)*660)-((B2-B1)*BF))/(T2-T1)
    570 VEL3(N)=(((D3-D2)*660)-((B3-B2)*BF))/(T3-T2)
    580 MED(N)= ((VEL1(N)+VEL2(N))/(VEL1(N)+VEL2(N)+VEL3(N)))*100
    590 F1(N)=(D1*660)/VEL1(N)
    600 F2(N)=((D2-D1)*660)/VEL2(N)
    610 F3(N)=F1(N)+F2(N)
    620 BL1(N)=B1
    630 BL2(N)=B2
    640 N=N+1
    650 CLS: GOTO 150
    660 N=N-1
    670 CLS
    680 PRINT"                                 E N E R G Y   "
    690 PRINT"                                 * * * * * *   "
    700 PRINT
    710 PRINT SPC(10)"Race: ";RACE$;"        Dist: ";DIST$; " Furlongs";"    Comments: ";C$
    720 PRINT"          ============================================================="
    730 PRINT SPC(12)"   Name         F1       F2       2C       Med%     B1  B2"
    740 PRINT "          -------------------------------------------------------------"
    750 FOR I = 1 TO N
    760 PRINT SPC(12) USING"## ";I;
    770 PRINT USING"\        \";LEFT$(NH$(I),12);
    780 PRINT USING" ###.##  ";F1(I);F2(I);F3(I);
    790 PRINT USING"  ###.##   ";MED(I);
    800 PRINT USING" ## ";BL1(I);BL2(I)
    810 NEXT
    820 LOCATE 24,22:PRINT "(D)elete   (A)dd    (P)rint   (N)ext ";
    830 Y$=INKEY$:IF Y$="" THEN 830
    840 IF Y$ = "D" THEN GOTO 1120
    850 IF Y$ = "A" THEN CLS: GOTO 640
    860 IF Y$ = "P" THEN CLS: GOTO 980
    870 CLS:LOCATE 6
    880 CLS: LOCATE 15
    890 PRINT "                          Save Race to Disk (Y/N)"
    900 Q$=INKEY$:IF Q$="" THEN 900
    910 IF Q$ = "Y" THEN 1230
    920 CLS: LOCATE 15
    930 PRINT "                        (N)ew Race   (R)eview   (Q)uit "
    940 O$=INKEY$:IF O$="" THEN 940
    950 IF O$ = "N" THEN N=0: GOTO 20
    960 IF O$ = "R" THEN 670
    970 CLS:CLOSE:SYSTEM
    980 LPRINT:LPRINT
    990 LPRINT SPC(20)"      E N E R G Y"
    1000 LPRINT SPC(20)"      * * * * * *    "
    1010 LPRINT
    1020 LPRINT SPC(5)"Race: ";RACE$;"   Dist: ";DIST$;" Furlongs";"  Comments: ";C$
    1030 LPRINT SPC(4)"======================================================================="
    1040 LPRINT SPC(10)"Name        F1      F2      F3     Total   Med%"
    1050 LPRINT SPC(4)"-----------------------------------------------------------------------"
    1060 FOR I = 1 TO N
    1070 LPRINT SPC(4)USING"\       \";LEFT$(NH$(I),10);
    1080 LPRINT USING" ###.#  ";F1(I);F2(I);F3(I);TOT(I);
    1090 LPRINT USING" ##.##  ";MED(I)
    1100 NEXT
    1110 GOTO 880
    1120 LOCATE 25,15
    1130 INPUT "                 Scratch # ",S
    1140 IF S=N THEN 1220
    1150 FOR I = S TO N
    1160 NH$(I)=NH$(I+1)
    1170 F1(I)=F1(I+1)
    1180 F2(I)=F2(I+1)
    1190 F3(I)=F3(I+1)
    1200 MED(I)=MED(I+1)
    1210 NEXT I
    1220 N=N-1: GOTO 670
    1230 REM SAVE FILE TO DISK
    1240 OPEN "O",#1,RACE$ + ".TXT"
    1250 FOR I = 1 TO N
    1260 WRITE #1,NH$(I),VEL1(I),VEL2(I),VEL3(I),MED(I),DIST$,D$(I),BL1(I),BL2(I),F1(I),F2(I),F3(I)
    1270 NEXT
    1280 CLOSE #1
    1290 GOTO 920
    1300 OPEN "I",#1,RACE$ + ".TXT"
    1310 I=1
    1320 IF EOF(1) THEN 1350
    1330 INPUT #1,NH$(I),VEL1(I),VEL2(I),VEL3(I),MED(I),DIST$,D$(I),BL1(I),BL2(I),F1(I),F2(I),F3(I)
    1340 I=I+1: GOTO 1320
    1350 CLOSE #1
    1360 I=I-1
    1370 N=I
    1380 GOTO 670
    Last edited by 2kaud; Apr 11th, 2025 at 04:03 AM.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    3,240

    Re: gwBasic

    I suppose you start by defining the form layout, buttons, input boxes &c then attach the relevant bit of BASIC logic to each using your .BAS listing as a guide.

    It is going to be a manual task as VB6 has it's own built-in graphics framework and is event driven whereas GWBASIC is largely linear in operation and has no graphic framework, so the program logic will need to be converted from the linear GWBASIC type to VB6's event driven model.

    You just have to dive into it and start converting.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,547

    Re: gwBasic

    Something like this won't be simple 1->1 conversion of code for a host of reasons. GWBasic is sequential code, VB is event driven.

    Essentially, it would be taking the principles of what the original code is doing and writing new VB6 code. All of the code that displays output would need to be rewritten. All of the code that gets user input would need to be rewritten. At a quick glance, I would say that the bulk of the math code could be reused in its entirety. All of the line number jumps would need to be understood to determine how they should be handled.

    If you don't have a great handle on those things you will struggle.

    Good luck.

  5. #5
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,940

    Re: gwBasic

    Not sure where to start? Well, you could start by writing a description of your program's purpose and how it is intended to be used.

    Also, if you're going to update it, why move to vb6? Why not Python? It's a modern language suited for console-based applications such as your program - on many different platforms.

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,940

    Re: gwBasic

    Code:
    import os
    
    # Horse data storage
    NH = []     # Names
    VEL1 = []
    VEL2 = []
    VEL3 = []
    MED = []
    DIST_STR = []
    D = []
    BL1 = []
    BL2 = []
    F1 = []
    F2 = []
    F3 = []
    
    def clear_screen():
        os.system('cls' if os.name == 'nt' else 'clear')
    
    def input_float(prompt, default=0.0):
        try:
            val = input(prompt)
            return float(val)
        except ValueError:
            return default
    
    def adjust_time(tstr):
        try:
            t = float(tstr)
        except ValueError:
            return 0.0
        frac = t - int(t)
        t = (frac * 2) + int(t)
        if t >= 100:
            t -= 40
        return t
    
    def adjust_final_time(tstr):
        try:
            t = float(tstr)
        except ValueError:
            return 0.0
        frac = t - int(t)
        t = ((frac * 2) + int(t)) - 40
        if t > 160:
            t -= 40
        if t < 60:
            t += 40
        return t
    
    def get_bf_d1_d2(dval):
        if dval == 1.4:
            dval = 8.181
        elif dval == 1.7:
            dval = 8.318
        if dval >= 10:
            d1, d2, bf = 4, 6, 11
        elif dval >= 9:
            d1, d2, bf = 4, 6, 10
        elif dval >= 8:
            d1, d2, bf = 4, 6, 9
        elif dval <= 7.5:
            bf = 8
            d1, d2 = 2, 4
        elif dval < 6:
            bf = 7
            d1, d2 = 2, 4
        else:
            d1, d2, bf = 2, 4, 9
        return dval, d1, d2, bf
    
    def input_horse(n):
        while True:
            name = input(f"NAME #{n+1}: ").strip()
            if not name:
                return False  # End of data entry
            NH.append(name)
    
            dist_str = input("DIST OF PACELINE: ").strip()
            D.append(dist_str)
    
            t1 = adjust_time(input("TIME 1ST CALL: "))
            t2 = adjust_time(input("TIME 2ND CALL: "))
            t3 = adjust_final_time(input("FINAL TIME: "))
    
            b1 = input_float("BEATEN LENGTHS 1ST CALL: ")
            b2 = input_float("BEATEN LENGTHS 2ND CALL: ")
            b3 = input_float("BEATEN LENGTHS FINISH: ")
    
            ok = input("DATA O.K. (Y/N)? ").strip().upper()
            if ok != 'Y':
                NH.pop()
                D.pop()
                continue
    
            try:
                dval = float(dist_str)
            except ValueError:
                dval = 8.0
    
            dval, d1, d2, bf = get_bf_d1_d2(dval)
    
            # Check for division by zero
            if t1 == 0 or (t2 - t1) == 0 or (t3 - t2) == 0:
                print("Invalid time input leading to division by zero. Skipping entry.")
                NH.pop()
                D.pop()
                continue
    
            v1 = ((d1 * 660) - (bf * b1)) / t1
            v2 = (((d2 - d1) * 660) - ((b2 - b1) * bf)) / (t2 - t1)
            v3 = (((dval - d2) * 660) - ((b3 - b2) * bf)) / (t3 - t2)
    
            total_velocity = v1 + v2 + v3
            vel_med = ((v1 + v2) / total_velocity) * 100 if total_velocity != 0 else 0
    
            f1 = (d1 * 660) / v1 if v1 != 0 else 0
            f2 = ((d2 - d1) * 660) / v2 if v2 != 0 else 0
            f3 = f1 + f2
    
            VEL1.append(v1)
            VEL2.append(v2)
            VEL3.append(v3)
            MED.append(vel_med)
            F1.append(f1)
            F2.append(f2)
            F3.append(f3)
            BL1.append(b1)
            BL2.append(b2)
    
            return True
    
    def print_report(race, comments, dist):
        clear_screen()
        print(f"{' ' * 10}Race: {race}        Dist: {dist} Furlongs    Comments: {comments}")
        print("          =============================================================")
        print(f"{' ' * 12}Name         F1       F2       F3     Med%    B1  B2")
        print("          -------------------------------------------------------------")
        for i in range(len(NH)):
            print(f"{' ' * 12}{NH[i][:12]:<12}  {F1[i]:>6.2f}  {F2[i]:>6.2f}  {F3[i]:>6.2f}  {MED[i]:>6.2f}  {BL1[i]:>3} {BL2[i]:>3}")
    
    def save_to_disk(race_name):
        with open(race_name + ".txt", "w") as f:
            for i in range(len(NH)):
                line = f"{NH[i]},{VEL1[i]},{VEL2[i]},{VEL3[i]},{MED[i]},{DIST_STR[i]},{D[i]},{BL1[i]},{BL2[i]},{F1[i]},{F2[i]},{F3[i]}\n"
                f.write(line)
        print(f"Saved to {race_name}.txt")
    
    def load_from_disk(race_name):
        try:
            with open(race_name + ".txt", "r") as f:
                for line in f:
                    parts = line.strip().split(",")
                    NH.append(parts[0])
                    VEL1.append(float(parts[1]))
                    VEL2.append(float(parts[2]))
                    VEL3.append(float(parts[3]))
                    MED.append(float(parts[4]))
                    DIST_STR.append(parts[5])
                    D.append(parts[6])
                    BL1.append(float(parts[7]))
                    BL2.append(float(parts[8]))
                    F1.append(float(parts[9]))
                    F2.append(float(parts[10]))
                    F3.append(float(parts[11]))
            print(f"Loaded {len(NH)} entries from {race_name}.txt")
        except FileNotFoundError:
            print(f"File {race_name}.txt not found.")
    
    def main():
        clear_screen()
        load = input("LOAD FILE FROM DISK? (Y/N): ").strip().upper()
        if load == 'Y':
            files = [f for f in os.listdir() if f.endswith('.txt')]
            print("\nAvailable TXT files:")
            for f in files:
                print(" ", f)
            race_name = input("\nNAME OF FILE TO LOAD: ").strip()
            load_from_disk(race_name)
        else:
            race_name = input("RACE ======> ").strip()
            comments = input("COMMENTS ==> ").strip()
            dist = input("DIST ======> ").strip()
    
        while True:
            if not input_horse(len(NH)):
                break
    
        print_report(race_name, comments, dist)
        save = input("\nSave race to disk? (Y/N): ").strip().upper()
        if save == 'Y':
            save_to_disk(race_name)
    
    if __name__ == "__main__":
        main()
    Disclaimer: This is a quick and dirty concept of proof which has only been minimally tested!

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2016
    Posts
    51

    Re: gwBasic

    Is that python code? This gwbasic code is how I learned to code. I made that program in the 90's and it takes information you enter about a horse race and outputs a report. I only moved on to visual basic after that and I'm not experienced in coding at all

  8. #8
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,940

    Re: gwBasic

    Yes, that is Python code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width