LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

function in button

hello evrybody 🙂

 

i have same function and i don't know how can i use it in the interface LabWindows/CVI :

 void saisir(struct Atelier *A,int Na)	  ;
	   float Tind(struct Atelier *A,int NA)   ;
	   void affiche(struct Atelier *A,int Na)  ;
	   void ecrirefichier(struct Atelier *A,int Na)		 ;

 

 

my header file 

#ifndef _header_H_
#define _header_H_

struct Employer
{
	char *nom ;
	int NPF ;
	char IndiceP ;
	float IndP ;
};
struct Atelier {
	char *NAF ;
	char *NRA ;
	float TInd ;
	struct Employer *EMP ;
	int NE ;
};

	 void saisir(struct Atelier *A,int Na)	  ;
	   float Tind(struct Atelier *A,int NA)   ;
	   void affiche(struct Atelier *A,int Na)  ;
	   void ecrirefichier(struct Atelier *A,int Na)		 ;





#endif
0 Kudos
Message 1 of 12
(4,434 Views)

Hello,

the short answer is "simply call the functions in control callbacks" Smiley Wink

 

Seriously speaking, this is a **Very** basic question that makes me think you are very new to CVI. If this is your situation, you should spend some time reading a few resources on CVI: open CVI and if the welcome page does not show select Help >> Welcome page... menu item; in the window that shows this way, select "Getting started with LabWindows/CVI" and read the document linked to have an overview of the IDE and the facilities it offers to you.

After stidying that document you could execut New >> Project from template in the welcome screen and choose "User interface application" among the templates offered: you'll have a generic framework where you can start adding controls and functions to build up your application.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 12
(4,430 Views)

i do it but 😞

 

 

455555.png

 

0 Kudos
Message 3 of 12
(4,432 Views)

I see.

Would you mind posting your project here so that we can speak about some concrete situation instead of speculating in theory? Please tell us also the version of CVI you are using.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 12
(4,427 Views)

54545.png

0 Kudos
Message 5 of 12
(4,423 Views)

"Posting the project" means post UIR and code files so that we can see which control is used and how, how functions / variables are defined and passed to functions, which libraries are loaded...

If you do not want / you are not permitted to post actual code, you could create a sample project that shows the problem and post that one here.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 12
(4,418 Views)

thank you 

that what i'm do 

i create a button and i write the name of my function in the callback 

labwiew.png

 

the prototype of the function :

void saisir(struct Atelier *A,int Na) 

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 7 of 12
(4,415 Views)

 

Ok, even if you have not posted your actual code, we can see the problem.

You cannot directly use your function as the button function: controls require a special function prototype; CVI IDE can create that for you. Inside that function, you can add your code and call your function.

It seems complicated but it will be clear once you read the documents I listed in my first post: that tutorial will guide you through the creation of a user interface and the related code.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 12
(4,411 Views)

my actuel Code

project.c

#include <cvirte.h>		
#include <userint.h>
#include "projet.h"
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
static int panelHandle;






void saisir(Atelier *A,int Na)
{
	int i ,j,taux=0 ;
	char aide[100] ;
	char intro[100] ;
	char intro2[100] ;
		for(i=0;i<Na;i++)
	{
		(A+i)->TInd=0 ;
	}
	for(i=0;i<Na;i++)
	{
		printf("-->Donner le nom d'Atlier n=%d \n",i+1);
    	scanf("%s",aide);
    	(A+i)->NAF=malloc(strlen(aide)+1);
    	strcpy((A+i)->NAF,aide) ;
    	printf("-->Donner du Responsable d'Atlier n=%d \n",i+1);
    	scanf("%s",intro) ;
    	(A+i)->NRA=malloc(strlen(intro)+1);
    	strcpy((A+i)->NRA,intro) ;
    	printf("-->Donner le Nombre d'Employer pour l'Ateier n=%d \n",i+1);
    	scanf("%d",&(A+i)->NE);
    	 if(!((A+i)->EMP=malloc(((A+i)->NE)*sizeof(Employer)))) exit(-1);
    	for(j=0;j<(A+i)->NE;j++)
    	{
    	printf("-->Donner le nom d'Employer n=%d \n",j+1);
    	gets(intro2) ;
    	gets(intro2) ;
        (A+i)->EMP[j].nom=malloc(strlen(intro2)+1);
    	strcpy((A+i)->EMP[j].nom,intro2) ;
    	printf("-->Donner le NPF d'Employer n=%d \n",j+1);
    	scanf("%d",&(A+i)->EMP[j].NPF) ;
        printf("-->Donner l'indiceP d'Employer n=%d \n",j+1);
    	scanf("%c",&(A+i)->EMP[j].IndiceP) ;
        scanf("%c",&(A+i)->EMP[j].IndiceP) ;
    	if ((A+i)->EMP[j].IndiceP =='A')
         taux=20 ;
		 else if  	((A+i)->EMP[j].IndiceP =='B')
		 taux=10 ;
		 else
		 taux=5 ;
		(A+i)->EMP[j].IndP=taux*((A+i)->EMP[j].NPF) ;
    	(A+i)->TInd += ((A+i)->EMP[j].IndP) ;
		}

	}

}
float Tind(Atelier *A,int NA)
{
	float Total=0 ;
	int i ;
	for(i=0;i<NA;i++)
	{
		Total += ((A+i)->TInd) ;
	}
	return Total ;
}
void affiche(Atelier *A,int Na)
{
int i,j ;
float TotalID ;
TotalID=Tind(A,Na) ;
printf("\n");
printf("--------------------------------------------------------------------------------\n");
printf("FICHE DE GESTION DES INDEMNITES DES EMPLOYES MOTOPROD (par journee)\n");
printf("--------------------------------------------------------------------------------\n");
for(i=0;i<Na;i++)
{
	printf("Nom Atelier de Fabrication %d=%s | Nom Responsable Atelier %d=%s \n",i+1,(A+i)->NAF,i+1,(A+i)->NRA);
	printf("                Nom\tNPF\tIndiceP\tIndP\n");
	for(j=0;j<(A+i)->NE;j++)
{
printf("                %s\t%d\t%c\t%.2f\n",(A+i)->EMP[j].nom,(A+i)->EMP[j].NPF,(A+i)->EMP[j].IndiceP,(A+i)->EMP[j].IndP);
}
printf("--------------------------------------------------------------------------------\n");
printf("                                                 Total Indemnite=%.2f\n",(A+i)->TInd) ;
printf("--------------------------------------------------------------------------------\n");
}
printf("Totaux des indemnites des employes du Groupe MotoProd pendant la journee=%.2f\n",TotalID) ;
printf("--------------------------------------------------------------------------------");

}
void ecrirefichier(Atelier *A,int Na)
{
    int i,j ;
    float TotalID=0;
    FILE *EMPLOYESMOTOPROD=NULL ;
    TotalID=Tind(A,Na) ;
    EMPLOYESMOTOPROD=fopen("employesmotoprod.txt","w") ;
if(EMPLOYESMOTOPROD !=NULL)
{
    printf("le fichier a etait bien creer");
fprintf(EMPLOYESMOTOPROD,"--------------------------------------------------------------------------------\n");
fprintf(EMPLOYESMOTOPROD,"FICHE DE GESTION DES INDEMNITES DES EMPLOYES MOTOPROD (par journee)\n\n");
fprintf(EMPLOYESMOTOPROD,"--------------------------------------------------------------------------------\n");
for(i=0;i<Na;i++)
{
fprintf(EMPLOYESMOTOPROD,"Nom Atelier de Fabrication %d=%s | Nom Responsable Atelier %d=%s \n",i+1,(A+i)->NAF,i+1,(A+i)->NRA) ;
fprintf(EMPLOYESMOTOPROD,"                Nom\tNPF\tIndiceP\tIndP\n") ;
for(j=0;j<(A+i)->NE;j++)
{
	fprintf(EMPLOYESMOTOPROD,"                %s\t%d\t%c\t%.2f\n",(A+i)->EMP[j].nom,(A+i)->EMP[j].NPF,(A+i)->EMP[j].IndiceP,(A+i)->EMP[j].IndP) ;
}
fprintf(EMPLOYESMOTOPROD,"--------------------------------------------------------------------------------\n");
fprintf(EMPLOYESMOTOPROD,"                                                 Total Indemnite=%.2f\n",(A+i)->TInd) ;
fprintf(EMPLOYESMOTOPROD,"--------------------------------------------------------------------------------\n");
}
fprintf(EMPLOYESMOTOPROD,"Totaux des indemnites des employes du Groupe MotoProd pendant la journee=%.2f\n",TotalID) ;
fprintf(EMPLOYESMOTOPROD,"--------------------------------------------------------------------------------\n");
fclose(EMPLOYESMOTOPROD) ;
}
else
    printf("le fichier n'est pas creer");
}






int main (int argc, char *argv[])
{
	if (InitCVIRTE (0, argv, 0) == 0)
		return -1;	/* out of memory */
	if ((panelHandle = LoadPanel (0, "projet.uir", PANEL)) < 0)
		return -1;
	DisplayPanel (panelHandle);
	RunUserInterface ();
	DiscardPanel (panelHandle);
	return 0;
}

int CVICALLBACK QuitCallback (int panel, int control, int event,
							  void *callbackData, int eventData1, int eventData2)
{
	switch (event)
	{
		case EVENT_COMMIT:
			QuitUserInterface (0);
			break;
	}
	return 0;
}

project.h

/**************************************************************************/
/* LabWindows/CVI User Interface Resource (UIR) Include File */
/* */
/* WARNING: Do not add to, delete from, or otherwise modify the contents */
/* of this include file. */
/**************************************************************************/

#include <userint.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Panels and Controls: */

#define PANEL 1
#define PANEL_QUITBUTTON 2 /* control type: command, callback function: QuitCallback */
#define PANEL_COMMANDBUTTON 3 /* control type: command, callback function: (none) */


/* Control Arrays: */

/* (no control arrays in the resource file) */


/* Menu Bars, Menus, and Menu Items: */

/* (no menu bars in the resource file) */


/* Callback Prototypes: */

int CVICALLBACK QuitCallback(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);


#ifdef __cplusplus
}
#endif

0 Kudos
Message 9 of 12
(4,409 Views)
  1. "Post the code" means to zip prj, uir, h, c, files and attach them to a forum post
  2. As I told you, you cannot use your 'saisir' function as a button callback. Take a look at QuitCallback in your code: that one is a control callback. Your function isn't.
  3. Among other things, the compiler is claiming that 'atelier' is not defined in your project: it's true. The header file you posted in your first post is not included in the source file, so the corresponding definitions cannot be found by the compiler
  4. You have really not attached your function to the button: as you can see in project.h file, no callback is attached to PANEL_COMMANDBUTTON (it says "callback function: (none)")

You seriously should read that tutorial...



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 10 of 12
(4,403 Views)