Qbasicnews.com

Full Version: COMMAND$ gives uppercase. Get command with original case.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
When you use COMMAND$ to get the command-line of a program, it gives it to you in uppercase only.

CHALLENGE: Write a routine to retrieve the command-line with the original case that was keyed.
*****
Code:
DECLARE FUNCTION GetCom$ ()

DEFINT A-Z
FUNCTION GetCom$

  DIM Regs AS RegTypeX

  Regs.ax = &H2F00
  InterruptX &H21, Regs, Regs

  DEF SEG = Regs.es
  Offset = Regs.bx
  Length = PEEK(Offset)

  FOR i = Offset + 2 TO Offset + Length
    Com$ = Com$ + CHR$(PEEK(i))
  NEXT

  GetCom$ = Com$

END FUNCTION
That's the same as this, I believe: http://www.outer-court.com/basic/echo/T1031.HTM

I don't know whether there's another way of doing this, so I can't offer anything original.

*peace*

Meg.
Hi, Plasma and Meg,

Rats! That only works if the user enters the COMMAND$ on the screen. If it comes via a BAT file or a Windows shortcut, no good.

Hi, Moneo,

If it is important to solve that problem, you might use a BAT file that saves the info in a file and read the file from QBasic, rather than COMMAND$

Instead of doing
MyProg "This is stuff"

do
CallMe "This is stuff"

where
BAT FILE CallMe
echo %1 > xxx
MyProg xxx
exit

Where xxx is an address QBasic can cope with.

Mac
I just tested it, and it works fine no matter how you start the program.

(You must read the command line before any file operations, since it is stored in the DTA. That might be your problem.)
Hi, Plasma,

T H A N K S

Good info.

Mac
PLASMA,
I've been tied up at work all week. Give me a chance to test your entry.
I personally never include interrupt or assembly language code in my programs, mostly because I'm unfamiliar with it. My last assembler code for microprocessors was on a Motorola 6502 and an RCA 1802. However, in QuickBasic I do use functions from a library which are often in assembler --- I don't have to debug those (I would expect).

MAC,
I think your approach of using a batchfile is very clever. It has its drawbacks however. If my program is a utility, for example, I would have to tell the user "If your parameter needs to be case sensitive, you must run a batchfile called CALLME with the parameter". Not a big deal, I admit, but a little bit awkward.

However, I just thought of something. Maybe the instructions for running the utility program always say: "Run CALLME with the quoted parameter". To install the utility program you would have to install the .exe of the program as well as the CALLME batchfile (or whatever name you give it). This could work fine!

P.S.: I didn't consider posting my solution because it uses a function from the QuickPak library. If anybody has this library and is interested, I'll post it.
*****
Emm...so if I include the source, you don't trust it, but if it's assembled in a library and you can't see the source, you trust it? That's kind of backwards...

Anyhow, it's just one interrupt, you can look it up if you want.
Sorry, Plasma, that's not what I meant. I will test your solution.

A function in a library undergoes strict testing and scrutiny by the thousands of programmers that purchased the library. Yes, I tend to trust this to a greater degree than some code that a well-meaning friend offers me.

I have stated here in this forum that if you are going to introduce a piece of code that someone else wrote into your program, first understand the code completely, and then test it thoroughly.

In this particular case, I cannot get to understand the code, and yes, there's a certain element of mistrust before perfoming exhaustive testing.

Nothing personal, Plasma, and I do appreciate your contributions.
*****
Ok, Plasma, I put your GETCOM$ function inside a little test program, like so:
Code:
defint a-z
DECLARE FUNCTION GetCom$ ()

PRINT GETCOM$
SYSTEM

END

FUNCTION GetCom$

  DIM Regs AS RegTypeX

  Regs.ax = &H2F00
  InterruptX &H21, Regs, Regs

  DEF SEG = Regs.es
  Offset = Regs.bx
  Length = PEEK(Offset)

  FOR i = Offset + 2 TO Offset + Length
    Com$ = Com$ + CHR$(PEEK(i))
  NEXT

  GetCom$ = Com$

END FUNCTION

I got the following errors when compiling:

C:\moneo\qb45\BC /O GETCOM,,GETCOM;
Microsoft ® QuickBASIC Compiler Version 4.50
© Copyright Microsoft Corporation 1982-1988.
All rights reserved.
Simultaneously published in the U.S. and Canada.
005D 000A DIM Regs AS RegTypeX
^ TYPE not defined
005D 000A InterruptX &H21, Regs, Regs
^ Equal sign missing
^ Syntax error

42845 Bytes Available
42048 Bytes Free

0 Warning Error(s)
3 Severe Error(s)

Your solution, or entry, is not exactly "ready to run". :wink:
I don't use TYPE, so I can't fix that problem.
As far as the "Equal sign missing" and the "Syntax error", I haven't got a clue how to fix them.

Send me a fixed version, and I'll try it again.
*****
Pages: 1 2