Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Basic to VB

Status
Not open for further replies.

gbrigman

IS-IT--Management
Mar 7, 2002
13
US
We have some labels that we print out on an old DOS computer using a .bat to call a .bas file. It prints directly to the printer port (com 1) on the printer. Is there any way to convert these to VB so that I can update the computer to W2K or XP?
 
"most" of the old GWBasic functions work in VB, so you should be able to simply copy the label printing code to a VB module and run it. Some parts of the code may 'run', but not be particularly appropiate to the VB environment, but these can sorted out as a part of the learning process.

While 'off topic', the fact that you even have a machine which is " ... still running DOS ... " and " ... ugrading to win ... " suggest that there is more effort in that arena than in converting GW Basic to VB.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Almost every line in the bas file causes an "invalid outside procedure" error. Below is an example:

START:
Open "COM1:9600,N,8,1,CS50000,DS50000,TB2048,RB2048" For Random As #1

MAIN:
Cls
Color 7, 9

'the first section of this program gets the variables for printing.

INPUT "1. PLEASE ENTER STARTING NUMBER--> ", STRNM%
INPUT "2. PLEASE ENTER ENDING NUMBER--> ", ENDNM%
INPUT "3. PLEASE ENTER TOTAL NUMBER--> ", TOTNM%

 
No offense intended, but if it's at all possible, I think you might want to give this project to someone with a bit more knowledge of Visual Basic. I say this because your last post sounded as if you aren't really very familiar with the language, and there's definitely going to be some work involved in the conversion. It isn't going to be just "recompile and go."
The reason you're getting the "invalid outside procedure" error is that you need to use procedures, not labels, to divide the code. You can't just type VB code into a .bas module and expect it to compile. Everything has to be inside a subroutine. For example, instead of a START label, you would use:
Code:
Sub Start()
    'Note: I have no idea if this will work in VB.
    Open "COM1:9600,N,8,1,CS50000,DS50000,TB2048,RB2048" For Random As #1
End Sub
Also, Visual Basic doesn't have any native console I/O facilities (it can be done, but it's a big pain and probably isn't worth the effort), so nothing you had under MAIN will work. The easiest way to get your information is probably to use a form and some text boxes.
 
Unfortunately AdaHacker is correct. I used to do a lot of work in GWBasic, QBasic, MS PDS, and VB for DOS. As a matter of fact I have spent more years in DOS than Windows. :) VB in windows is a whole other world. Its going to be more than knowing what each line does and converting it. In some ways turning it into a VB app is going to make it easier. For example:
The line:
COM1:9600,N,8,1,CS50000,DS50000,TB2048,RB2048" For Random As #1
can go away all together. You can use the native printing functions in VB and send the output to any printer you like. All you need do is gather the data and format it, and the printer drivers will take care of the codes specific to that printer. In addition it will also take care of the communications with the printer.

THe "Input" statements are history. You will have to create a form in VB adding in a text box (or possibly a combo box if there are certain preset multiple choice answers) for each of your input statements. Then a simple command button to get the ball rolling. Its really pretty easy if you understand BASIC. If you do not know what the code is doing in the original though, you really should find yourself a programmer to convert it for you.
 
That Open "com1 .... will not even work in vb3. I have a no. of programs written in Basica communicating with instruments from serial ports and guess what, now that I've upgraded to VB I have to rewrite all that stuff again. Also I have special characters I have to send to the instrument and it's not supported in Windows. Big headache here cos instrument are too expensive to throw away.
 
also an problem you have with the new basic and the old is with windows you have to have a directroy and when i fixed my dads program i had to start from scratch. the reson for that is because the old gw-basic code is interpreted in vb6 as a module. as we all know you can not start on a module you have to have a form wich rasis a hole million other problems because in gw there were no forms. i hope i have helped
 
>as we all know you can not start on a module

No, we don't all know that. It is quite possible to start on a module (and even have a completely formless VB program as a result)), simply by creating a Sub Main in a module, and then under Project Properties changing the Startup Object to Sub Main
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top