Gamestudio Links
Zorro Links
Newest Posts
Is Text Box data check possible?
by gamers. 02/17/20 11:09
Behaviour of user-defined bars
by Petra. 02/15/20 13:34
Optimization parameters results
by Petra. 02/15/20 13:22
Bollinger Band - Multi Timeframe
by migo. 02/15/20 06:50
Votes for future features
by 7th_zorro. 02/13/20 05:50
Quote size
by Zheka. 02/12/20 17:10
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
6 registered members (AndrewAMD, thomasprv, jenGs, Zheka, gamers, txesmi), 800 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
DebraSteed, Ricard, Apollo1, ziphnor, thomasprv
18377 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Is Text Box data check possible? #479083
02/13/20 14:49
02/13/20 14:49
Joined: Jan 2012
Posts: 61
G
gamers Online OP
Junior Member
gamers  Online OP
Junior Member
G

Joined: Jan 2012
Posts: 61
Hello there,
How can I check if any data is entered into the textbox by users?
Also, how can I ensure that only numbers are entered in the text box?
Is it possible?

Re: Is Text Box data check possible? [Re: gamers] #479084
02/13/20 15:25
02/13/20 15:25
Joined: May 2009
Posts: 5,145
Caucasus
3run Online
Senior Expert
3run  Online
Senior Expert

Joined: May 2009
Posts: 5,145
Caucasus
Hey!

If you store text into the string, you can check it's length (str_len). As for 'numbers only' maybe str_stri can help, just a quick thought.

Greets!

Edit: I think str_stri was a bad idea, not going to work...probably str_cmpi is a better for this case.

Edit2: I've spent a little time and came up with this (since I don't know how to handle regex with lite-c and it might not even support it):
Code
#include <acknex.h>
#include <default.c>

#define PRAGMA_POINTER

STRING *non_numeric_str = "0123456789a";
STRING *numeric_str = "5325";
STRING *empty_str = "";

// receives a STRING and position (num) of a character in that STRING
// returns a single character as a STRING
STRING *get_next_char(STRING *src_str, int num)
{
	if(!src_str)
	{
		return NULL;
	}
	
	if(num > str_len(src_str))
	{
		return NULL;
	}
	
	STRING *temp_str = "";
	str_cpy(temp_str, src_str);
	str_trunc(temp_str, str_len(src_str) - num);
	str_clip(temp_str, num - 1);
	
	return temp_str;
}

// returns TRUE (1) if string is numeric
// otherwise returs FALSE (0)
var is_numeric_str(STRING *src_str)
{
	if(!src_str)
	{
		return false;
	}
	
	int i = 0, j = 0, res = true;
	
	for (i = 0; i < str_len(src_str); i++)
	{
		STRING *temp_str = get_next_char(src_str, i + 1);
		
		for (j = 0; j < 10; j++)
		{
			if (!str_cmpi(temp_str, str_for_num(NULL, j)))
			{
				res = false;
				continue;
			}
			
			res = true;
			break;
		}
		
		if(res == false)
		{
			break;
		}
	}
	
	return res;
}

// returns TRUE (1) is string's length is zero
// otherwise returns FALSE (0)
var is_empty_str(STRING *str)
{
	if(!str)
	{
		return false;
	}
	
	if(str_len(str) > 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

// main game function
void main()
{
	var numeric1 = is_numeric_str(non_numeric_str);
	var numeric2 = is_numeric_str(numeric_str);
	var empty = is_empty_str(empty_str);
	
	while(!key_esc)
	{
		DEBUG_VAR(numeric1, 0);
		DEBUG_VAR(numeric2, 20);
		DEBUG_VAR(empty, 40);
		
		wait(1);
	}
}


Edit3: my code above probably is not the best and easiest ways... I just wanted to give it a try. hopefully some other users may point out a better solution.

Last edited by 3run; 02/13/20 21:33.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Re: Is Text Box data check possible? [Re: 3run] #479087
02/14/20 12:50
02/14/20 12:50
Joined: Jan 2012
Posts: 61
G
gamers Online OP
Junior Member
gamers  Online OP
Junior Member
G

Joined: Jan 2012
Posts: 61
Originally Posted by 3run
Hey!

If you store text into the string, you can check it's length (str_len). As for 'numbers only' maybe str_stri can help, just a quick thought.

Greets!

Edit: I think str_stri was a bad idea, not going to work...probably str_cmpi is a better for this case.

Edit2: I've spent a little time and came up with this (since I don't know how to handle regex with lite-c and it might not even support it):
Code
#include <acknex.h>
#include <default.c>

#define PRAGMA_POINTER

STRING *non_numeric_str = "0123456789a";
STRING *numeric_str = "5325";
STRING *empty_str = "";

// receives a STRING and position (num) of a character in that STRING
// returns a single character as a STRING
STRING *get_next_char(STRING *src_str, int num)
{
	if(!src_str)
	{
		return NULL;
	}
	
	if(num > str_len(src_str))
	{
		return NULL;
	}
	
	STRING *temp_str = "";
	str_cpy(temp_str, src_str);
	str_trunc(temp_str, str_len(src_str) - num);
	str_clip(temp_str, num - 1);
	
	return temp_str;
}

// returns TRUE (1) if string is numeric
// otherwise returs FALSE (0)
var is_numeric_str(STRING *src_str)
{
	if(!src_str)
	{
		return false;
	}
	
	int i = 0, j = 0, res = true;
	
	for (i = 0; i < str_len(src_str); i++)
	{
		STRING *temp_str = get_next_char(src_str, i + 1);
		
		for (j = 0; j < 10; j++)
		{
			if (!str_cmpi(temp_str, str_for_num(NULL, j)))
			{
				res = false;
				continue;
			}
			
			res = true;
			break;
		}
		
		if(res == false)
		{
			break;
		}
	}
	
	return res;
}

// returns TRUE (1) is string's length is zero
// otherwise returns FALSE (0)
var is_empty_str(STRING *str)
{
	if(!str)
	{
		return false;
	}
	
	if(str_len(str) > 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

// main game function
void main()
{
	var numeric1 = is_numeric_str(non_numeric_str);
	var numeric2 = is_numeric_str(numeric_str);
	var empty = is_empty_str(empty_str);
	
	while(!key_esc)
	{
		DEBUG_VAR(numeric1, 0);
		DEBUG_VAR(numeric2, 20);
		DEBUG_VAR(empty, 40);
		
		wait(1);
	}
}


Edit3: my code above probably is not the best and easiest ways... I just wanted to give it a try. hopefully some other users may point out a better solution.


Thanks for your contribution. I will try this as soon as possible.

Re: Is Text Box data check possible? [Re: 3run] #479094
2 hours ago
2 hours ago
Joined: Jan 2012
Posts: 61
G
gamers Online OP
Junior Member
gamers  Online OP
Junior Member
G

Joined: Jan 2012
Posts: 61
Is there any way to limit the value to be written in the text box between 0 and 100?


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1