GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Feb-2004, 09:41
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough
Unhappy

Having problems displaying a line of variable length using winio.


I have the problem of creating a program to give the option of selecting a shape(line,rectangle,circle,ellipse) then specifying the dimensions in a pop up window. After putting in the values a button will refresh the screen showing the object. Im having problems managing to get the line to be drawn "Run-time Error:The function supplied as arguement 2 is corrupt". Im also pretty sure that i shouldnt have to put a ";" after DLine() but it errors otherwise.
CPP / C++ / C Code:
#pragma windows 500000,500000
#include<stdio.h>
#include <windows.h>
#include <dbos\graphics.h> 

int hand1=1,ctrl; 
int X1=0,X2=0,Y1=0,Y2=0,DLine();
main()
{
winio("%ca[Graphics Tablet]&");
char* shape[]={"Line","Rectangle","Circle","Ellipse",NULL};
int selection=1;
winio("Please Select a Shape:  %`7.4ls&",shape,&selection);

winio("%bt[close]\n");
{
if (selection==1)
        {;
        winio("%`gr&",400,300,hand1);
        winio("%ww%lw",&ctrl); 
        winio("%fn[Arial]%tsStart position x:\t%rd\n&",1.0,&X1); 
        winio("Start Position y:\t%rd\n&",&Y1); 
        winio("End Position x:\t%rd\n&",&X2);
        winio("End Position y:\t%rd\n&",&Y2);
        winio("%bc[grey]%^bt[Display Line]&",DLine);
        winio("%bt[close]\n");
        }
        DLine();
                {
                select_graphics_object(hand1);
                draw_line(X1,Y1,X2,Y2,29);
                return 1;
                }
}        
        
        
if (selection==2)
        {
        winio("%spRectangle",400,400);
        return 0;
        }
if (selection==3)
        {
        winio("%spCircle",400,400);
        return 0;
        }
if (selection==4) 
        {
        winio("%spEllipse",400,400);
        return 0;
        }   
}
  #2  
Old 13-Feb-2004, 10:08
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi Warny.

I am afraid that I am not going to be much help as I have never used the winio functions. Your code is always so easy to read and so well formatted that I always want to help but unfortunately I may not have the background to help. Let me ask you a couple of questions though and maybe we can figure something out.

What is DLine()? You have it defined here as a function that returns an integer:
CPP / C++ / C Code:
int X1=0,X2=0,Y1=0,Y2=0,DLine();

When you call it here, it seems like DLine is a variable, did you mean to call it this way or should it be called as a funcion, ie DLine()
CPP / C++ / C Code:
        winio("%bc[grey]%^bt[Display Line]&",DLine);

I think I may have just figured something out. Isn't DLine() a function that you declare here?
CPP / C++ / C Code:
    winio("%bc[grey]%^bt[Display Line]&",DLine);
        winio("%bt[close]\n");
        }
        DLine();
                {
                select_graphics_object(hand1);
                draw_line(X1,Y1,X2,Y2,29);
                return 1;
                }
}        

Is that why you think it shouldn't have a semicolon. You are right & wrong. You need to define this function outside of your main function. So, above or below your main function, just put it as:
CPP / C++ / C Code:
 
DLine()
              {
                select_graphics_object(hand1);
                draw_line(X1,Y1,X2,Y2,29);
                return 1;
                }

One more quick thing. Have you thought about using a case/switch statement? It is not a huge thing, but using a row of ifs like this causes the program to check for the value, even after it has found the right one.

I hope something here helps....
  #3  
Old 15-Feb-2004, 06:52
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough
Iv used Dline() before, although it can b called anything u want, its just like main() as its just an area in which a process takes places which is y it doesnt need a ";", and i simply use a pointer to let the program know where to find it.

Iv worked on my code while trying to post my reply and while sticking varias parts of programs iv done before i managed to get something that works:
CPP / C++ / C Code:
if (selection==1)
        { 
        winio("\t%fn[Paris]%ts Start position X: \t%rd\n&",1.5,&X1); 
        winio("\tStart Position Y: \t%rd\n&",&Y1); 
        winio("\tEnd Position X: \t%rd\n&",&X2); 
        winio("\tEnd Position Y: \t%rd\n&",&Y2);
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);
        winio("%`gr&",400,300,hand1);
        winio("%ww%lw",&ctrl);
        select_graphics_object(hand1);
        draw_line(X1,X2,Y1,Y2,29);             
        }

 int Draw()
        {
        return 0; 
        }
This part works perfectly although i wouldnt mind putting in radial buttons so that i could change the colour if anyone knows how to do that. I'll post the full code up once iv finished it, although i dont think its well enough written or advanced enough to be a code submittal.
  #4  
Old 15-Feb-2004, 07:16
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi warny. I am glad to see you making progress with this. I know I can't be of much help because of the winio library you are using.

I would like to make a comment and if I am wrong I hope that someone will point it out. I don't think that standard C syntax allows for inline function declarations like you are showing. I personally have never seen them in C and I can't compile anything like that. Your current compiler may allow this, but most compilers won't. What compiler are you using? Visual C++?

The use of functions is excellent, but these should be defined outside of your main loop. Anyway, it is your program not mine, so you can do it the way that you are most comfortable. I thought I just might mention this.
  #5  
Old 15-Feb-2004, 07:55
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough
Im using Salford compiler, not my personnal choice butbeing able to use windows.h makes the program look nice and professional even if its not. This is my finished program,although im not sure how useful it will b to anyone seeing as iv got a compiler with different directories:
CPP / C++ / C Code:
pragma windows 500000,500000//means that the black box doesnt appear//
#include<stdio.h>
#include <windows.h>
#include <dbos\graphics.h> 

int hand1=1,ctrl; 
int X1=0,X2=0,Y1=0,Y2=0,R1=0,R2=0,W=0,C=0,Draw();
main()
{
winio("%bg%ca[Graphices Tablet Program]&",RGB(255,100,100));//box of title "graphics tablet program"//
char* shape[]={"Line","Rectangle","Circle","Ellipse",NULL};//drop down menu names//
int selection=1;
winio("Please Select a Shape:  %`9.4ls&",shape,&selection);//drop down menu width 9, 4 selections//
winio("%bc[red]%bt[Select]\n");

if (selection==1)
        { 
        winio("\t%fn[Paris]%tsStart Position X: \t\t%rd\n&",1.5,&X1); 
        winio("\tStart Position Y: \t\t%rd\n&",&Y1); 
        winio("\tEnd Position X: \t\t%rd\n&",&X2); 
        winio("\tEnd Position Y: \t\t%rd\n&",&Y2); 
        winio("\tLine Width: \t\t%rd\n&",&W);
        winio("\tLine Colour: 0-256 \t%rd\n&",&C);//set line colour to C// 
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);//button to close the window and create a grphics tablet//
        winio("%`gr&",400,300,hand1);//graphics tablet of size 400*300,reference name hand1//
        winio("%ww%lw",&ctrl);//this most b present with the line above//
        select_graphics_object(hand1);//makes sure the next lines refer to the tablet hand1//
        set_line_width(W);//sets line width to W//
        draw_line(X1,Y1,X2,Y2,C);//draws line start point:X1,Y1 end: X2,Y2 colour 80//             
        } 
        
if (selection==2)
        { 
        winio("\t%fn[Paris]%tsStart Position X: \t\t%rd\n&",1.5,&X1); 
        winio("\tStart Position Y: \t\t%rd\n&",&Y1); 
        winio("\tEnd Position X:\t\t%rd\n&",&X2); 
        winio("\tEnd Position Y: \t\t%rd\n&",&Y2); 
        winio("\tLine Width: \t\t%rd\n&",&W);
        winio("\tLine Colour: 0-256 \t%rd\n&",&C);
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);
        winio("%`gr&",400,300,hand1);
        winio("%ww%lw",&ctrl);
        select_graphics_object(hand1);
        set_line_width(W);
        draw_rectangle(X1,Y1,X2,Y2,C);
        }
        
if (selection==3)
        { 
        winio("\t%fn[Paris]%tsCentral Point X: \t\t%rd\n&",1.5,&X1); 
        winio("\tCentral Point Y: \t\t%rd\n&",&Y1); 
        winio("\tRadius: \t\t\t%rd\n&",&R1); 
        winio("\tLine Width: \t\t%rd\n&",&W);
        winio("\tLine Colour: 0-256 \t%rd\n&",&C); 
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);
        winio("%`gr&",400,300,hand1);
        winio("%ww%lw",&ctrl);
        select_graphics_object(hand1);
        set_line_width(W);
        draw_ellipse(X1,Y1,R1,R1,C);
        }
        
if (selection==4) 
        {
        winio("\t%fn[Paris]%tsCentral Point X: \t\t%rd\n&",1.5,&X1); 
        winio("\tCentral Point Y: \t\t%rd\n&",&Y1); 
        winio("\tRadius in X direction: \t%rd\n&",&R1); 
        winio("\tRadius in Y Direction: \t%rd\n&",&R2); 
        winio("\tLine Width: \t\t%rd\n&",&W);
        winio("\tLine Colour: 0-256 \t%rd\n&",&C); 
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);
        winio("%`gr&",400,300,hand1);
        winio("%ww%lw",&ctrl);
        select_graphics_object(hand1);
        set_line_width(W);
        draw_ellipse(X1,Y1,R1,R2,C); 
        }
   
}
int Draw()
        {
        return 0;//to make sure the window closes, so a new one is created// 
        }

Which functions could i define outside the main loop?
  #6  
Old 15-Feb-2004, 08:05
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Okay, my world has returned to normal now.

You are *not* using in-line function definitions. There was a small difference in what you posted this time:

CPP / C++ / C Code:
if (selection==4) 
        {
        winio("\t%fn[Paris]%tsCentral Point X: \t\t%rd\n&",1.5,&X1); 
        winio("\tCentral Point Y: \t\t%rd\n&",&Y1); 
        winio("\tRadius in X direction: \t%rd\n&",&R1); 
        winio("\tRadius in Y Direction: \t%rd\n&",&R2); 
        winio("\tLine Width: \t\t%rd\n&",&W);
        winio("\tLine Colour: 0-256 \t%rd\n&",&C); 
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);
        winio("%`gr&",400,300,hand1);
        winio("%ww%lw",&ctrl);
        select_graphics_object(hand1);
        set_line_width(W);
        draw_ellipse(X1,Y1,R1,R2,C); 
        }
   
}          //End of Main routine - we are now outside of main.
int Draw()
        {
        return 0;//to make sure the window closes, so a new one is created// 
        }

Compared to last time:
CPP / C++ / C Code:
if (selection==1)
        { 
        winio("\t%fn[Paris]%ts Start position X: \t%rd\n&",1.5,&X1); 
        winio("\tStart Position Y: \t%rd\n&",&Y1); 
        winio("\tEnd Position X: \t%rd\n&",&X2); 
        winio("\tEnd Position Y: \t%rd\n&",&Y2);
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);
        winio("%`gr&",400,300,hand1);
        winio("%ww%lw",&ctrl);
        select_graphics_object(hand1);
        draw_line(X1,X2,Y1,Y2,29);             
        }  // This is the end of the if statement.
//There is no end of the main statement though - we are still inside main!
 int Draw()
        {
        return 0; 
        }

Do you see where my confusion was?

Actually, I appreciate you posting your code. I am sure that there are others that use the winio library.

Have you looked at using a switch/case statement?
It would be set up like:
CPP / C++ / C Code:
switch(selection){
   case 1:
          //Do stuff for 1
          break;
   case 2:
          //Do stuff for 2
          break;
    ...
    default:
          //If nothing else - handle error
         break;
}

instead of doing several comparisons, you are doing only one, and then your code is jumping to that point.
  #7  
Old 15-Feb-2004, 09:08
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough
Quote:
Originally Posted by dsmith
Okay, my world has returned to normal now.
Do you see where my confusion was?
Yup sry bout that, its me being lazy and not posting my whole script seeing as im not workin on the rest.
Thanks for the help the switch statement makes the code neater and iv understood how to use it properly seeing as when i used it b4 i just ripped it off someone elses script.
This is my script now:
CPP / C++ / C Code:
#pragma windows 500000,500000//means that the black box doesnt appear//
#include<stdio.h>
#include <windows.h>
#include <dbos\graphics.h> 

int hand1=1,ctrl; 
int X1=0,X2=0,Y1=0,Y2=0,R1=0,R2=0,C=0,W=0,Draw();
main()
{
winio("%bg%ca[Graphices Tablet Program]&",RGB(255,100,100));//box of title "graphics tablet program"//
char* shape[]={"Line","Rectangle","Circle","Ellipse",NULL};//drop down menu names//
int selection=1;
winio("Please Select a Shape:  %`7.4ls&",shape,&selection);//drop down menu width 9, 4 selections//


winio("%bc[red]%bt[Select]\n");

switch(selection)//switch statement refering to drop down menu choice//
        {
        case 1:
        { 
        winio("\t%fn[Paris]%tsStart Position X: \t\t%rd\n&",1.5,&X1); 
        winio("\tStart Position Y: \t\t%rd\n&",&Y1); 
        winio("\tEnd Position X: \t\t%rd\n&",&X2); 
        winio("\tEnd Position Y: \t\t%rd\n&",&Y2); 
        winio("\tLine Width: \t\t%rd\n&",&W);
        winio("\tLine Colour: 0-256 \t%rd\n&",&C);//set line colour to C//
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);//button to close the window so the next appears//
        winio("%`gr&",400,300,hand1);//graphics tablet of size 400*300,reference name hand1//
        winio("%ww%lw",&ctrl);//this most b present with the line above//
        select_graphics_object(hand1);//makes sure the next lines refer to the tablet hand1//
        set_line_width(W);//sets line width to W//
        draw_line(X1,Y1,X2,Y2,C);//draws line start point:X1,Y1 end: X2,Y2 colour 80//             
        }        
        break;
        
        case 2:
        { 
        winio("\t%fn[Paris]%tsStart Position X: \t\t%rd\n&",1.5,&X1); 
        winio("\tStart Position Y: \t\t%rd\n&",&Y1); 
        winio("\tEnd Position X: \t\t%rd\n&",&X2); 
        winio("\tEnd Position Y: \t\t%rd\n&",&Y2); 
        winio("\tLine Width: \t\t%rd\n&",&W);
        winio("\tLine Colour: 0-256 \t%rd\n&",&C);
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);
        winio("%`gr&",400,300,hand1);
        winio("%ww%lw",&ctrl);
        select_graphics_object(hand1);
        set_line_width(W);
        draw_rectangle(X1,Y1,X2,Y2,C);
        }
        break;
        
        case 3:
        { 
        winio("\t%fn[Paris]%ts Central Point X: \t\t%rd\n&",1.5,&X1); 
        winio("\tCentral Point Y: \t\t%rd\n&",&Y1); 
        winio("\tRadius: \t\t\t%rd\n&",&R1); 
        winio("\tLine Width: \t\t%rd\n&",&W);
        winio("\tLine Colour: 0-256 \t%rd\n&",&C); 
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);
        winio("%`gr&",400,300,hand1);
        winio("%ww%lw",&ctrl);
        select_graphics_object(hand1);
        set_line_width(W);
        draw_ellipse(X1,Y1,R1,R1,C);
        }
        break;
        
        case 4: 
        {
        winio("\t%fn[Paris]%tsCentral Point X: \t\t%rd\n&",1.5,&X1); 
        winio("\tCentral Point Y: \t\t%rd\n&",&Y1); 
        winio("\tRadius in X direction: \t%rd\n&",&R1); 
        winio("\tRadius in Y Direction: \t%rd\n&",&R2); 
        winio("\tLine Width: \t\t%rd\n&",&W);
        winio("\tLine Colour: 0-256 \t%rd\n&",&C); 
        winio("\n\t\t  %bc[grey]%^bt[Draw]",Draw);
        winio("%`gr&",400,300,hand1);
        winio("%ww%lw",&ctrl);
        select_graphics_object(hand1);
        set_line_width(W);
        draw_ellipse(X1,Y1,R1,R2,C); 
        }
        break;
        }
   
}
int Draw()
        {
        return 0; 
        }
  #8  
Old 15-Feb-2004, 09:21
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Looks good!

A couple of things on the switch statement. The { } are not required on the case statement, but they don't hurt anything. Basically a case statement will run until it hits a break, therefore things like
CPP / C++ / C Code:
case 'a':
case 'A':
       //Do code
       break;
are perfectly valid. This can also be a bad thing, because if you forget the break statement all of the code in the entire switch statement will be executed (until it hits a break)
  #9  
Old 15-Feb-2004, 11:56
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough
Thanks for all the help my code looks alot better now.
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CD Burner Help - Power Calibration Error.... JonBoy420 Computer Hardware Forum 110 05-Feb-2008 18:34
burning problems PLEASE PLEASE HELP kelticeire Computer Hardware Forum 4 01-Dec-2006 15:39
Having a problem Chuckles Computer Hardware Forum 19 13-Sep-2004 12:17
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28
CD Buring Failed skanth2000 Computer Hardware Forum 1 15-Nov-2003 03:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:41.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.