‎08-23-2006 12:17 PM
‎08-23-2006 01:40 PM
It might be easier to use 4 numeric fields. That way, the data is forced to be numeric at least.
Then use a sprintf statement to put them into a string with the dots between the numbers.
sprintf(StringName, "%i.%i.%i.%i", IP_Addr1, IP_Addr2, IP_Addr3, IP_Addr4);
‎08-24-2006 02:14 AM - edited ‎08-24-2006 02:14 AM
// String control callback
// - validate & reformat an IP address string
int CVICALLBACK IPAddressCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
unsigned n1, n2, n3, n4;
int i, items;
char ip[20], IPAddress[20] = "Invalid!";
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panel, control, ip);
// _Rough_ check for valid IP address string
items = Scan (ip, "%i[u].%i[u].%i[u].%i[u]",
&n1, &n2, &n3, &n4);
if ((items == 4) &&
(n1 <= 0xE0) && // Class A, B or C
(n2 <= 255) &&
(n3 <= 255) &&
(n4 <= 255))
Fmt (IPAddress, "%i.%i.%i.%i", n1, n2, n3, n4);
SetCtrlVal (panel, control, IPAddress);
break;
}
return 0;
}
Message Edited by cdk52 on 08-24-2006 06:15 PM
‎08-31-2006 11:34 AM
‎08-31-2006 12:57 PM