06-06-2010 02:16 PM
Hi,
I am new to Lab Windows and I really need your help.
I have created a server and a client. The server extracts a number randomly between 1 and 20 and after that depending on that number he extracts again randomly number between 1 and 20(ex. if the first number extracted randomly is "5" he extracts 5 number between 1 and 20.).
When the client connects to the server he must receive the data extracted randomly.
So I try to send the data from the server to the client. For the first number extracted works but for the next ones doesn`t. Please Help!
Here is my code:
first file: - the sever sends data to the client
second file: - the number extractions
third file: - where the client receives the data from the server
//first file
case TCP_CONNECT:
conversation=handle;
GetTCPPeerAddr (conversation, var, 256);
sprintf(text,"Client from %s is connected",var);
InsertTextBoxLine (server, PANEL_historic, -1, text);
ServerTCPWrite (conversation, n, sizeof(n), 0);
for(i=0;i<nr;i++){
sprintf(r,"%d ",extrase[i]);
ServerTCPWrite (conversation, r, sizeof(r), 0);
printf("estras=%s\n",r);
}
break;
//second file
void extragere(){
for(i=1;i<=20;i++)
k[i]=i;
nr=rand()%19+1;
printf("%d\n",nr);
sprintf(n,"%d",nr);
printf("nr=%s\n",n);
srand(time(NULL));
do{
extras=rand()%19+1;
for(i=1;i<=20;i++){
if (k[i]==extras){
k[i]=0;
extrase[contor]=extras;
contor++;
}
}
}while(contor<nr);
for(i=0;i<nr;i++)
printf("extrase [%d]=%d\n",i,extrase[i]);
}
//third file
case TCP_DATAREADY:
ClientTCPRead (conversation, n, 3, 0);
sscanf(n,"%d",&nr);
printf("%d",nr);
break;
06-06-2010 11:54 PM
06-07-2010 03:28 PM
I managed to send the data. Thanks.
The client created, after receiving the "id" from the server, searches for files and must print in textboxes some data.
I tried to use:
SetCtrlAttribute (proiect1, Proiect1TEXTBOX, ATTR_FRAME_COLOR, VAL_RED);
and I get the following errors:
Proiect1.c - 4 errors
294, 29 Expecting an identifier.
294, 29 syntax error; found 'integer constant' expecting ')'.
294, 73 Extraneous formal parameter specification.
294, 73 Redeclaration of 'SetCtrlAttribute' previously declared at userint.h:2150.
And also can you tell me how to color a textbox using code?
Please help!
06-07-2010 05:00 PM
It is not possible to colour some text only in a textbox leaving the rest of text in the default colour: textboxes only accept a single colour valid for the whole text shown. You may obtain different colours using a listbox instead of a textbox, but you must be aware that this control is very different from a texbox so you must consider its characteristics before moving to it: using a listbox instead of a textbox just to gain colouring ability may not be the right way to address your probems.
Regarding the errors you are receiving, the most evident is the use of 'Proiect1TEXTBOX' keyword to indicate a control: the correct sytax is PanelConstantName_ControlConstantName, which in your case could be Proiect1_TEXTBOX. I am also a little bit puzzled by the difference between 'project1' and 'Project1' in your code: keep in mind that the first parameter in SetCtrlAttribute command must be a valid panel handle; in this case either you are using the panel constant name instead of the panel handle or you have set a variable name very similar to panel constant name. The first case is an error, while the second could lead to confusion and should be avoided.
Finally, ATTR_FRAME_COLOUR is not a valid attribute for the text colour: it refers to the colour of the frame that is surrounding the control, and is valid only if 'use windows visual style for controls' attribute is not enabled on the panel. I haven't CVI here to check, but the correct attribute should be something like ATTR_TEXT_COLOUR: in the help for the control you can find the list of valid attributes for it, with a detailed description of each of them.