error coding please help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bhavesh1978
    New Member
    • Mar 2007
    • 32

    error coding please help

    well i have my mouse working and now im trying to make my exit button working when the mouse clicked onto exit button and it will exit the application


    here is my coding for the mouse function to exit the application

    ............... ............... ............... ............... ............... ............... ............... .........

    //The function getmousepos gets the position of the mouse alongwith the mouse button state. Like which
    //button is pressed 1,2. If button =1 then it is left mouse and if it is 2 then right mouse button click.
    Code:
    void getmousepos(int *button,int *x,int *y)
    	{
    	char *ss;
    	union REGS i,o;
    	i.x.ax=3;
    	int86(0x33,&i,&o);
    	*button=o.x.bx;
    	*x=o.x.cx;
    	*y=o.x.dx;
    	}
    
    
    
    //The below loop executes until anything is pressed and then getmousepos is called to get the position of
    //the mouse and if it falls in between x>=70 && x<=100 && y>=410 && y<=420 then exit from the program.
    //void thisismycode()
    {
    	 while(!kbhit())
    	 {
    	  getmousepos(&button,&x,&y);
    	  if((button&1)==1)
    	  {
    	    getmousepos(&button,& x,& y);
    	    if(x>=70 && x<=100 && y>=410 && y<=420)
    		 exit(0);
    	  }
    	 }
    
     }
    ............... ............... ............... ............... ............... ............... ............... .......

    My error message when i complile


    undefined symbol 'button'
    undefined symbol 'x'
    undefined symbol 'y'
    ............... ............... ............... ............... ............... ............... ............... ........

    what have i done.. have i missed something there..
    Last edited by horace1; Mar 20 '07, 04:47 PM. Reason: added code tags
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    where u define these variables ??????

    Comment

    • Bhavesh1978
      New Member
      • Mar 2007
      • 32

      #3
      Originally posted by dmjpro
      where u define these variables ??????
      how you mean where i define these variables???
      well im using old version of turbo c

      Comment

      • horace1
        Recognized Expert Top Contributor
        • Nov 2006
        • 1510

        #4
        Originally posted by Bhavesh1978
        how you mean where i define these variables???
        well im using old version of turbo c
        need to define button, x and y and initialise the mouse - try this as a test program
        Code:
        int main()
        {
             int button, x,y;                        // << define variables
            union REGS registers;                  /* variable to hold 8086 registers */
        
            registers.x.ax = 0;                          /* reset the Microsoft mouse */
            int86(0x33, &registers, &registers);
        	 while(!kbhit())
        	 {
        	  getmousepos(&button,&x,&y);
        	  printf("%d %d %d \n", button, x, y);
        	  if((button&1)==1)
        	  {
        	    getmousepos(&button,& x,& y);
        	    if(x>=70 && x<=100 && y>=410 && y<=420)
        		 exit(0);
        	  }
        	 }
        
         }

        Comment

        • Bhavesh1978
          New Member
          • Mar 2007
          • 32

          #5
          Code:
          /* list the include file */
          /*#include <direct.h>*/
          #include <conio.h>
          #include <stdio.h>
          #include <stdlib.h>
          #include <math.h>
          #include <string.h>
          #include <time.h>
          #include <ctype.h>
          #include <dos.h>
          #include <graphics.h>
          
          
          /* check the colours !!!! */
          int	black 	=	0;
          int	deepblue =	1;
          int	deepgreen =	2;
          int	deepcyan	= 	3;
          int	deepred	=	4;
          int	deepmagenta=	5;
          int	brown		=	6;
          int	gray		=	7;
          int	blue		=	8;
          int	green 	=	10;
          int	cyan		=	11;
          int	red		=	12;
          int	magenta	=	13;
          int	yellow	=	14;
          int	white 	=	15;
          
          int yline0= 0 ;   /* position of a Y line */
          int yline1= 20 ;  /* position of a Y line */
          int yline2= 40 ;   /* position of a Y line */
          int yline3= 60 ;   /* position of a Y line */
          int yline4= 80 ;   /* position of a Y line */
          int yline5= 100 ;  /* position of a Y line */
          int yline6= 120 ;  /* position of a Y line */
          int yline7= 140;  /* position of a Y line */
          int yline8= 160;  /* position of a Y line */
          int yline9= 180;  /* position of a Y line */
          int yline10 = 200 ;  /* position of a Y line */
          int yline11 = 220 ;  /* position of a Y line */
          int yline12 = 240 ;  /* position of a Y line */
          int yline13 = 260 ;   /* position of a Y line */
          int yline14 = 280 ;   /* position of a Y line */
          int yline15 = 300 ;   /* position of a Y line */
          int yline16 = 320 ;   /* position of a Y line */
          int yline17 = 340;  /* position of a Y line */
          int yline18 = 360 ;   /* position of a Y line */
          int yline19 = 380 ;   /* position of a Y line */
          int yline20 = 400 ;   /* position of a Y line */
          int yline21 = 420 ;   /* position of a Y line */
          int yline22 = 440 ;   /* position of a Y line */
          int yline23 = 460 ;   /* position of a Y line */
          void heading(char *string);
          void centreline(char *string);
          void gcls(void) ;
          void gsolidrectangle(int x1, int y1, int x2, int y2,int col);
          
          //mouse int function
          int GetX(void);
          int GetY(void);
          int GetKey(void);
          void ShowCursor(void);
          void HideCursor(void);
          int ButtonStatus(void);
          void SetMouseMode(int);
          void PrintMousePosition(void);
          void UpdateMousePosition(void);
          void PrintMouseButtonStatus(void);
          void UpdateMouseButtonStatus(void);
          void CheckMouseButtonStatus(void);
          void DrawOneButton(void);
          void OnButtonClick(void);
          void LabelButtons(void);
          void RelabelButtons(int);
          void About(void);
          void InitializeMouse(void);
          void Startup(void);
          void LoadOne(void);
          void RestrictMouse(int,int,int,int);
          
          // cpu register structure for dos function calls.
          struct REGPACK reg;
          union REGS regs;
          
          
          //Mouse function coding here..
          
          int GetX(void)
          {
          // get mouse X position
          	reg.r_ax=3;
          	intr(51,&reg);
          	return(reg.r_cx);
          }
          
          int GetY(void)
          {
          // get mouse Y position
          	reg.r_ax=3;
          	intr(51,&reg);
          	return(reg.r_dx);
          }
          
          
          void ShowCursor(void)
          {
          // Turn on mouse cursor
          	reg.r_ax=1;
          	intr(51,&reg);
          }
          
          void HideCursor(void)
          {
          // Turn off mouse cursor.
          	reg.r_ax=2;
          	intr(51,&reg);
          }
          
          void RestrictMouse(int x1,int y1,int x2,int y2)
          {
          union REGS i,o;
          i.x.ax=7;
          i.x.cx=x1;
          i.x.dx=x2;
          int86(0x33,&i,&o);
          
          i.x.ax=8;
          i.x.cx=y1;
          i.x.dx=y2;
          int86(0x33,&i,&o);
          }
          void getmousepos(int *button,int *x,int *y)
          	{
          	char *ss;
          	union REGS i,o;
          	i.x.ax=3;
          	int86(0x33,&i,&o);
          	*button=o.x.bx;
          	*x=o.x.cx;
          	*y=o.x.dx;
          	}
          
          void CheckMouseButtonStatus(void)
          {
          // gets mouse buttons pressed.
          
          /*	status=ButtonStatus();
          
          	LeftButton=0;
          	RightButton=0;
          	MiddleButton=0;
          
          	if(status==1){LeftButton=1;}
          	if(status==2){RightButton=1;}
          	if(status==3){LeftButton=1;RightButton=1;}
          	if(status==4){MiddleButton=1;}
          	if(status==5){LeftButton=1;MiddleButton=1;}
          	if(status==6){LeftButton=1;MiddleButton=1;}
          	if(status==7){LeftButton=1;RightButton=1;MiddleButton=1;}*/
          }
          
          
          
          
          
          
          
          
          
          
          
          
          int main()
          	{
          	/* request auto detection */
          	int gdriver = DETECT, gmode, errorcode,button=1,x,y;
          
          	/* initialize graphics mode */
          	initgraph(&gdriver, &gmode, "c:\\turboc");
          
          	/* read result of initialization */
          	errorcode = graphresult();
          
          	if (errorcode != grOk)  /* an error occurred */
          		{
          		printf("Graphics error: %s\n", grapherrormsg(errorcode));
          		printf("Press any key to halt:");
          		getch();
          		exit(1);             /* return with error code */
          		}
          
          	/* do some graphics */
          	//Heading
          
          
          
          	//green background
          		gsolidrectangle(640,570,0,0,deepcyan );
          		//text
          		setcolor(black);
          		moveto(515,130);
          		outtext("Control Panel");
          		setcolor(black);
          		rectangle(500,150,620,350);
          		rectangle(510,160,610,180);//screen
          		gsolidrectangle(510,160,610,180,cyan); //colour screen
          		//1st row button
          		rectangle(515,210,540,190);
          		rectangle(572,210,545,190);
          		rectangle(605,210,581,190);
          		moveto(525,200);
          		outtext("1");	//text keypad 1
          		moveto(555,200);
          		outtext("2");	//text keypad 2
          		moveto(590,200);
          		outtext("3");	//text keypad 3
          
          		//2nd row button
          		rectangle(515,220,540,243);
          		rectangle(572,220,545,243);
          		rectangle(580,220,605,243);
          		moveto(525,230);
          		outtext("4"); 	//text keypad 4
          		moveto(555,230);
          		outtext("5");   //text keypad 5
          		moveto(590,230);
          		outtext("6");	//text keypad 6
          
          		//3rd row button
          		rectangle(540,275,515,250);
          		rectangle(574,275,545,250);
          		rectangle(605,275,580,250);
          		moveto(525,260);
          		outtext("7");  	//text keypad 7
          		moveto(555,260);
          		outtext("8");   //text keypad 8
          		moveto(590,260);
          		outtext("9");   //text keypad 9
          
          		//4th row button
          		rectangle(540,305,515,279);
          		rectangle(574,305,545,280);
          		rectangle(605,305,580,280);
          		moveto(525,290);
          		outtext("*");  	//text keypad *
          		moveto(555,290);
          		outtext("0");   //text keypad 0
          		moveto(590,290);
          		outtext("#");   //text keypad #
          
          
          		//background of rectangle
          		gsolidrectangle(10,100,100,120,cyan);
          		gsolidrectangle(10,140,100,160,green);
          		gsolidrectangle(10,180,100,200,yellow);
          		gsolidrectangle(10,220,100,240,deepmagenta);
          		gsolidrectangle(10,260,100,280,deepgreen);
          		gsolidrectangle(10,300,100,320,cyan);
          
          		setcolor(deepblue);
          		rectangle(10,100,100,120);
          		rectangle(10,140,100,160);
          		rectangle(10,180,100,200);
          		rectangle(10,220,100,240);
          		rectangle(10,260,100,280);
          		rectangle(10,300,100,320);
          
          		//switch box
          
                  	moveto(390,130);
          		outtext("Switch Box");
          		setcolor(black);
          		rectangle(490,350,350,150);
          		gsolidrectangle(450,160,485,190,red);//sw switch select
          		circle(468,175,10);
          		moveto(355,170);
                          outtext("SW Select");
          		//bit0 switch
          		gsolidrectangle(450,220,485,195,red);//bit0 switch
          		circle(468,207,10);
          		moveto(360,205);
          		outtext("Bit-0");
          		//bit1 switch
          		gsolidrectangle(450,250,485,225,red);//bit1 switch select
          		circle(468,237,10);
          		moveto(360,235);
                          outtext("Bit-1");
          		//bit2 switch
          		gsolidrectangle(450,280,485,255,red);//bit2 switch
          		circle(468,267,10);
          		moveto(360,265);
                          outtext("Bit-2");
          		gsolidrectangle(450,310,485,285,red);//bit2 switch
          		circle(468,297,10);
          		moveto(360,295);
          		outtext("Bit-3");
          
          		//middle button for sw swtich
          		circle(468,175,5);
          		moveto(355,170);
          		//middle button for bit-0
                          circle(468,207,5);
          		moveto(360,205);
          		//middle button for bit-1
          		circle(468,237,5);
          		moveto(360,235);
          		//middle button for bit-2
          		circle(468,267,5);
          		moveto(360,265);
          		//middle button for bit-3
          		circle(468,297,5);
          		moveto(360,295);
          
          		//Instruction box
          		rectangle(345,450,620,360);
          		moveto(360,370);
          		outtext("1 - Press S Start Motor");
          		moveto(360,390);
          		outtext("2 - Press T stop motor");
          		moveto(360,410);
          		outtext("3 - Press O Heater on");
          		moveto(360,430);
          		outtext("4 - Press 1 Heater off");
          
          		//Temperature box
          		rectangle(350,80,620,110);
          		gsolidrectangle(480,85,580,100,red);
          		moveto(360,90);
          		outtext("Temperature:");
          
          		//ON and OFF Switches
          		rectangle(350,60,620,10);
          		moveto(360,20);
          		outtext("Switches ON/OFF");
          		circle(361,40,5);
          		moveto(370,40);
          		outtext("ON");
          		circle(420,40,5);
          		moveto(430,40);
          		outtext("OFF");
          
          		//restart button
          		circle(500,40,5);
          		moveto(510,40);
          		outtext("Restart");
          
          		//Exit Button
          		rectangle(48,428,123,398);
          		gsolidrectangle(50,425,120,400,red);
          		moveto(70,410);
          		outtext("EXIT");
          
          
          		ShowCursor();
          		RestrictMouse(0,0,getmaxx(),getmaxy());
          int main()
          {
               int button, x,y;                        // << define variables
              union REGS registers;                  /* variable to hold 8086 registers */
          
              registers.x.ax = 0;                          /* reset the Microsoft mouse */
              int86(0x33, &registers, &registers);
          	 while(!kbhit())
          	 {
          	  getmousepos(&button,&x,&y);
          	  printf("%d %d %d \n", button, x, y);
          	  if((button&1)==1)
          	  {
          	    getmousepos(&button,& x,& y);
          	    if(x>=70 && x<=100 && y>=410 && y<=420)
          		 exit(0);
          	  }
          	 }
          
           }
          
          void heading(char *string)
          	{
          	gcls() ;
          	moveto(320 - (strlen(string) * 8) , yline0); /* centre text */
          	settextstyle(0,0,2);
          	outtext(string) ; /* print text */
          	settextstyle(0,0,1);
          	}
          
          void centreline(char *string)
          	{
          	int length,start ;
          	start = ((80 - strlen(string))/2) * 8 ;
          	length = strlen(string) *9 ;
          	rectangle(start-6,yline11 - 10, start + length + 16 , yline12 + 10);
          	rectangle(start-4,yline11 - 8, start + length + 14 , yline12 + 8);
          	moveto(start + 10, yline11); /* centre text */
          	outtext(string) ; /* print text */
          	}
          
          /* clear the screen */
          void gcls(void)
          	{
          	gsolidrectangle(0,0,639,479,black);
          	}
          
          /* draw solid rectangle */
          void gsolidrectangle(int x1, int y1, int x2, int y2,int col)
          	{
          	int poly[8],tcol;
          	tcol = getcolor();
          	poly[0] = poly[6] = x1; 		 /* 1st vertex */
          	poly[1] = poly[3] = y1;
          	poly[2] = poly[4] = x2; 		 /* 1st vertex */
          	poly[7] = poly[5] = y2;
          	setfillstyle(SOLID_FILL,col);
          	setcolor(col);
          	fillpoly(4, poly);
          	setcolor(tcol);
          	}

          Comment

          • Bhavesh1978
            New Member
            • Mar 2007
            • 32

            #6
            hi.

            I have managed to correct from your code to mine.. some how i got an error saying

            please check above thanks

            Declaration is not allowed here
            Declaration syntax error
            Declaration missing ;
            function should return a value

            Comment

            • DeMan
              Top Contributor
              • Nov 2006
              • 1799

              #7
              I can see two implementations of main. The second one comes ion the middle of the first, and I suspect the parentheses are mixed up as a result. So: get rid of the second "int main()" and then make sure all your parentheses line up as required...

              Comment

              • Bhavesh1978
                New Member
                • Mar 2007
                • 32

                #8
                Originally posted by DeMan
                I can see two implementations of main. The second one comes ion the middle of the first, and I suspect the parentheses are mixed up as a result. So: get rid of the second "int main()" and then make sure all your parentheses line up as required...
                i have managed to get rid of the main int() in the middle.. still same error message

                please help any1

                Comment

                • DeMan
                  Top Contributor
                  • Nov 2006
                  • 1799

                  #9
                  Might like to move the iont and union declarations (where the int main() originally was) up to the top of teh method.....

                  Comment

                  Working...