Qbasicnews.com

Full Version: Converting QBasic code to TrueBasic
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
ok well i have some code in qbasic that i need converted to truebasic. i have truebasic in school and i need the code to meet truebasics standards but im having trouble converting it. if somebody can do this for me i will be glad to paypal them 5 bucks. heres the code

DECLARE SUB LoadMonth (yInput AS INTEGER, mInput AS INTEGER)
' First input the data into an array
DATA January,31,February,28,March,31
DATA April,30,May,31,June,30
DATA July,31,August,31,September,30
DATA October,31,November,30,December,31
DIM SHARED MonthName(12) AS STRING
DIM SHARED MonthDays(12) AS INTEGER
FOR i = 1 TO 12
READ MonthName(i), MonthDays(i)
NEXT i

' Now provide for months of 6 lines of 27 characters each
DIM SHARED Calendar(12, 6) AS STRING * 27

' Input the year
DIM Year AS INTEGER
INPUT "Year"; Year

' Compute a calendar
DIM Month AS INTEGER
FOR Month = 1 TO 12
CALL LoadMonth(Year, Month)
NEXT Month

' Print the calendar 3 months at a time
DIM S27 AS STRING * 27
OPEN "z.dat" FOR OUTPUT AS #1
FOR row = 0 TO 3
PRINT #1, ""
FOR col = 1 TO 3
Month = (row * 3) + col
LSET S27 = "": MID$(S27, 7) = STR$(Year) + " " + MonthName(Month)
IF col = 3 THEN
PRINT #1, S27
ELSE
PRINT #1, S27; " | ";
END IF
NEXT col
lset S27="Mon Tue Wed Thu Fri Sat Sun"
print #1, S27; " | ";S27; " | ";S27
FOR Week% = 1 TO 6
FOR col = 1 TO 3
Month = (row * 3) + col
IF col = 3 THEN
PRINT #1, Calendar(Month, Week%)
ELSE
PRINT #1, Calendar(Month, Week%); " | ";
END IF
NEXT col
NEXT Week%
NEXT row
CLOSE
SYSTEM

SUB LoadMonth (yInput AS INTEGER, mInput AS INTEGER)
DIM Year AS INTEGER: Year = yInput
DIM Month AS INTEGER: Month = mInput
IF Month = 2 THEN
IF Year MOD 4000 = 0 THEN
LET numdays = 29
ELSEIF Year MOD 100 = 0 THEN
LET numdays = 28
ELSEIF Year MOD 4 = 0 THEN
LET numdays = 29
ELSE
LET numdays = 28
END IF
ELSE
numdays = MonthDays(Month)
END IF

IF Month < 3 THEN
LET Month = Month + 12
LET Year = Year - 1
END IF
LET w = day + 2 * Month + INT(3 * (Month + 1) / 5) + Year + INT(Year / 4) - INT(Year / 100) + INT(Year / 400) + 2
IF Month > 12 THEN
LET Month = Month - 12
LET Year = Year + 1
END IF

IF w MOD 7 = 0 THEN
LET endd = 6
ELSE
LET endd = (w MOD 7) - 1
END IF

Week$ = ""
FOR blanks = 1 TO endd
Week$ = Week$ + SPACE$(4)
NEXT blanks
FOR Cal = 1 TO numdays
IF Cal < 10 THEN day$ = " " + STR$(Cal) ELSE day$ = STR$(Cal)
Week$ = Week$ + " " + day$
IF LEN(Week$) > 26 THEN
Week% = Week% + 1
LSET Calendar(Month, Week%) = RIGHT$(Week$, 27)
Week$ = ""
END IF
NEXT Cal
IF Week$ <> "" THEN
Week% = Week% + 1
LSET Calendar(Month, Week%) = RIGHT$(Week$, LEN(Week$) - 1)
END IF
IF Week% < 6 THEN LSET Calendar(Month, Week% + 1) = ""
END SUB




here is a list of TRUEBASIC commands http://truebasic.com/downloads/TB_Commands.pdf

here is the demo version of truebasic, fully functional, only lasts 15 minutes though.
http://truebasic.com/demo.asp

click first link


anyone who can do this for me or help me will be compensated. if you can do it for free, it would be even better! this is very important, thank you for any help.
Hi, impact, welcome to the forum.

I don't know Truebasic so I can't help you much. Your program is simple enough and uses standard Basic syntax. I would just take the QBasic code and feed it to the Truebasic compiler and see what errors you get. Then start changing the code lines that give errors. This shouldn't take too long.

I think it would be a good idea to thoroughly debug your QBasic code before trying to convert it. Otherwise, when you get to debugging in Truebasic, you won't know if it's a logic error or a Truebasic error.

By the way, I just happened to notice your leap year logic in the code, with the following errors:

1) The MOD 4000 should be a MOD 400. The MOD 4000 logic has been added to the official algorithm in addition to the MOD 400, but you won't be needing it for a very long time. I'm ignoring this myself.

2) The MOD 100 should be "anded" with the MOD 4. See correct leap year logic below that I've been using for over 10 years in production programs.
Code:
FUNCTION IsLeapYear (Z) STATIC

   ' If the year is evenly divisible by 4 and not divisible
   ' by 100, or if the year is evenly divisible by 400, then
   ' it's a leap year:
   IsLeapYear = (Z MOD 4 = 0 AND Z MOD 100 <> 0) OR (Z MOD 400 = 0)
END FUNCTION
some of the statements are too advance for me. dim? whats that? close? i cant intepret this. 5 bucks to anyone who can do it
DIM stands for dimension, and it declares a variable. Close is used after opening a file to close a file.
Quote:some of the statements are too advance for me. dim? whats that? close? i cant intepret this. 5 bucks to anyone who can do it
Oh, I thought the code that you posted was your own. Ok, then you've got to understand the code and test it before converting it to Truebasic, in my opinion.

DIM is short for dimension.
It is most often used to dimension an array. Example: to dimension an array of strings called SARRAY$ that has 100 entries, from 1 to 100, then the DIM statement would be:
DIM SARRAY$(1 TO 100)

Another frequent usage of DIM is for declaring the type for a variable. Example: You want a double precision floating point number called TOTAL and you don't want to have to refer to it as TOTAL# throughout the program, then you use the DIM as follows:
DIM TOTAL AS DOUBLE

The same can be done to declare variable types of INTEGER, LONG, and SINGLE.

See the QB Online Help at the top of the Qbasicnews screen. Look for statements, functions and commands in the Index.
*****
ive got about 95 percent of it converted. found a converter. few MINOR problems though, about 5 errors. heres the code...hopefully you guys can help me with the TrueBasic demo

10 ! This program converted from BASIC to True BASIC.
11 !
12 ! Converter version 2.0 copyright © 1998 by:
13 ! True BASIC, Inc.
14 ! 12 Commerce Ave.
15 ! West Lebanon, NH 03784
16 !
17 ! True BASIC makes no warranty, expressed or implied, that
18 ! this converted program is a precise and accurate equivalent
19 ! of the original BASIC program. This conversion is provided
20 ! only as an aid to a more complete conversion by the owner of
21 ! the original BASIC program.
22 !
23 OPTION BASE 0
24 !
25 LIBRARY "DefLib.trc"
100 ! First input the data into an array
110 data January, 31, February, 28, March, 31
120 data April, 30, May, 31, June, 30
130 data July, 31, August, 31, September, 30
140 data October, 31, November, 30, December, 31
150 share monthname(12)
160 share monthdays(12)
170 for i = 1 to 12
180 read monthname$(i), monthdays(i)
190 next i
200 ! Now provide for months of 6 lines of 27 characters each
210 share calendar(12, 6) *** 27
220 ! Input the year
230 input prompt "Year": year
240 ! Compute a calendar
250 for month = 1 to 12
260 call loadmonth (year, month)
270 next month
280 ! Print the calendar 3 months at a time
290 ! dim s27 as string * 27
300 open #1: name "z.dat", org text, access output, create newold
310 for row = 0 to 3
320 print #1: ""
330 for col = 1 to 3
340 let month = round((row*3)+col)
350 lset S27 = ""
360 call middol(s27$, 7, maxnum, str$(year) & " " & monthname$(month))
370 if col = 3 then print #1: s27$ else print #1: s27$; " | ";
420 next col
430 lset S27="Mon Tue Wed Thu Fri Sat Sun"
440 print #1: s27$; " | "; s27$; " | "; s27$
450 for week_i = 1 to 6
460 for col = 1 to 3
470 let month = round((row*3)+col)
480 if col = 3 then print #1: calendar$(month, week_i) else print #1: calendar$(month, week_i); " | ";
530 next col
540 next week_i
550 next row
560 close
570 stop
580 sub loadmonth (yinputas
590 ! Error at source line: 55 Expected comma; found: as in
600 ! SUB LoadMonth (yInput AS INTEGER, mInput AS INTEGER)
610 let year = round(yinput)
620 let month = round(minput)
630 if month = 2 then
640 if remainder(year,4000) = 0 then
650 let numdays = 29
660 elseif remainder(year,100) = 0 then
670 let numdays = 28
680 elseif remainder(year,4) = 0 then
690 let numdays = 29
700 else
710 let numdays = 28
720 end if
730 else
740 let numdays = monthdays(month)
750 end if
760 if month < 3 then
770 let month = month+12
780 let year = year-1
790 end if
800 let w = day+2*month+int(3*(month+1)/5)+year+int(year/4)-int(year/100)+int(year/400)+2
810 if month > 12 then
820 let month = month-12
830 let year = year+1
840 end if
850 if remainder(round(w),7) = 0 then let endd = 6 else let endd = (remainder(round(w),7))-1
900 let week$ = ""
910 for blanks = 1 to endd
920 let week$ = week$ & repeat$(" ",(4))
930 next blanks
940 for cal = 1 to numdays
950 if cal < 10 then let day$ = " " & str$(cal) else let day$ = str$(cal)
1000 let week$ = week$ & " " & day$
1010 if len(week$) > 26 then
1020 let week_i = week_i+1
1030 lset Calendar(Month, Week%) = RIGHT$(Week$, 27)
1040 let week$ = ""
1050 end if
1060 next cal
1070 if week$ <> "" then
1080 let week_i = week_i+1
1090 lset Calendar(Month, Week%) = RIGHT$(Week$, LEN(Week$) - 1)
1100 end if
What are the errors! Smile
correct me if i'm wrong but it appears impact just wants to buy some completed homework, and not bother actually learning anything. Personally i wouldn't help them cheat their way through school
Quote:correct me if i'm wrong but it appears impact just wants to buy some completed homework, and not bother actually learning anything. Personally i wouldn't help them cheat their way through school
Hmmm, what do you have to say about this, impact?
One of the rules on this forum is that we don't help people by doing their homework.
*****