Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading in Grahpics mode

Posted on 1998-11-06
5
Medium Priority
?
239 Views
Last Modified: 2010-04-16
Hi

I am using Borland Pascal (DOS) version 7.0.  I wondered if it is possible to read from user while in graphics mode.  I mean just like Read and Readln in CRT mode.  If possible could anybody send example code.

Also anothe problem I have is I want to read a number from user, if I use integer or word and user presses a character the program will crash.  What is the best way to validate and make sure the program does not crash.

If answering please bear in mind that even though I do VB and C++ stuff, my Pascal knowledge is not that brilliant, therefore a little example code will help.

Thank you folks
0
Comment
Question by:gbzhhu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 100 total points
ID: 1215981
program blahblah;

var
  s :string;
  i,
  code :integer;

begin
  asm                        {these lines set graphics mode}
    mov ax,13h
    int 10h;
  end;
  readln(s);                 {this line reads a string}
  val(s,i,code);             {this line converts string s to integer i}
  if code <> 0 then writeln('error')
  else writeln(i);
  readln;
end.


Readln works in any graphics mode.  The question is whether or not it will write to the screen in the readln statement.  I know for sure that mode 13 will write to the screen, you can try it with other graphics modes too.  In any case, readln will always read what the user enters.

To answer your second question:

Always read anything the user types in into a string.  This will allows the user to enter anything without crashing the program.  After the string is read in, manually convert it to an integer using the Val procedure.  Val takes a string, and returns an integer, and another integer called Code.  You can validate whether or not the user's input was numeric by checking the value in code.  If code is not equal to zero, then there was an error.  (The value in code actually points to the position in the string where there was a nonumeric character).

Look at the code above to see how it works.


0
 
LVL 12

Author Comment

by:gbzhhu
ID: 1215982
Hi Scrapdog

The validation part of your answer works brilliant for me, however, the graphics part, I was using InitGraph statement to initialise graphics and I was using OutTextXy to write something on screen, but did not know what to use in order to read something from user while still in graphics mode.  Now readln works, but I would like to move the cursor to the position I want (somewhere in the screen) and then use readln.

Can you please have a look at the problem and see if you can help.  Is there a the equivalent in graphics mode of the following

gotoxy(12,22); readln(something);


Also I did not understand dthe assembly lines which initialise graphics (first time I have ever seen) what happened to InitGraph;  I mean the only help file I have with my Pascal is crap -- do you know a better one?

thanks again
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215983
Let's see your source code.
0
 
LVL 7

Expert Comment

by:Motaz
ID: 1215984
Unfortunately there is no equevelant to ( gotoxy, readln ) in graphic mode, so that you must make your own gotoxy, readln procedures using readkey and OutTextXy and read any thing as string.

Motaz from Sudan.
0
 
LVL 7

Expert Comment

by:Motaz
ID: 1215985
I've fucntion that read string in graphic mode called ReadStr, you can find it in my unit which exist in my homepage :

http://members.wbs.net/homepages/a/z/z/azzoz.html

The unit called MGR.pas, you will find many examples use that unit.

You can call that function as :

St:=ReadStr(200,100,'',30);

st : string;
200 : X-cordinate
100 : Y-cordinate
''     : initial value of string
30  : maximum length of string you want to read.

If you want to set a colour for text and background you can use :

Colour(14,1);  { Yellow in Blue }

Motaz.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question