Qbasicnews.com
September 19, 2019, 04:32:40 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: COMMAND$ gives uppercase. Get command with original case.  (Read 6838 times)
Moneo
Na_th_an
*****
Posts: 1971


« on: January 23, 2005, 10:51:39 PM »

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.
*****
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #1 on: January 23, 2005, 11:53:24 PM »

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
Logged
Meg
Ancient QBer
****
Posts: 483


« Reply #2 on: January 24, 2005, 10:07:44 AM »

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.
Logged
Mac
Senior Member
**
Posts: 243


WWW
« Reply #3 on: January 28, 2005, 06:17:42 PM »

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
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #4 on: January 28, 2005, 07:09:13 PM »

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.)
Logged
Mac
Senior Member
**
Posts: 243


WWW
« Reply #5 on: January 28, 2005, 07:24:25 PM »

Hi, Plasma,

T H A N K S

Good info.

Mac
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #6 on: January 28, 2005, 09:51:00 PM »

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.
*****
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #7 on: January 28, 2005, 10:46:44 PM »

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.
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #8 on: January 28, 2005, 11:33:43 PM »

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.
*****
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #9 on: January 29, 2005, 09:52:08 PM »

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 (R) QuickBASIC Compiler Version 4.50
(C) 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.
*****
Logged
Z!re
*/-\*
*****
Posts: 4599


« Reply #10 on: January 29, 2005, 10:20:41 PM »

Load QB with this parameter from a commandline/shortcut/batfile:
QB /L

Too lazy to check the actuall BC/LINK parameter to include a lib.


And you might need to add:
'$include: qb.bi"

To the top of the code.
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #11 on: January 29, 2005, 10:22:55 PM »

The code I posted was only a function, not an entire program. So of course it wasn't "ready to run." Wink Like Zire said, you need to link with QB.LIB and include QB.BI when compiling a program that uses INTERRUPT or INTERRUPTX.
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #12 on: January 30, 2005, 12:21:30 AM »

I'm using QuickBasic 4.5. I don't have QB.LIB nor QB.BI. All I have is BCOM45.LIB, which I never use, and the QuickPak .LIB.

I'm not about to change my linking batchfile and get your required QB.LIB and QB.BI, which probably wouldn't work with QuickBasic, just to test your function. You test it in your QBasic environment, and I'll take your word for it that it works.

Not all of us on the forum use QBasic, some of us use QuickBasic, and I think some use GW-Basic or similar.
*****
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #13 on: January 30, 2005, 12:38:05 AM »

Err...QB.LIB and QB.BI are included with QuickBASIC 4.5. Maybe you deleted them? I don't know where you got the impression that I was using QBasic.

There's not really any reason to read the command-line in QBasic or GWBASIC, because it will always be run in the interpreter...
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #14 on: January 30, 2005, 12:40:49 AM »

QB.QLB and QB.BI are part of the standard QuickBasic 4.5 package. You should have them, unless your package is incomplete. You can head to qbnz to download the full, official QB 4.5 package that the community compiled and completed.

Quote
I'm not about to change my linking batchfile and get your required QB.LIB and QB.BI, which probably wouldn't work with QuickBasic, just to test your function.


QB.LIB and QB.BI do work with QuickBasic. They were coded by Microsoft and put in there just in case people wanted to call MSDOS or BIOS interrupts. The functions in QB.LIB were taken away from the runtime 'cause in 1987 all the space you could save was precious, and not all programs use interrupts.

You don't have to change any batch files, just load the QB ide with the /L option, load the code, and run it. Trust me, trying this routine won't kill you Wink And I find it the most "intelligent" way to do it: call the OS 'cause retrieving the command line is OS stuff.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!