Gamestudio Links
Zorro Links
Newest Posts
retrain - data?
by danatrader. 09/20/20 05:27
Single advise model for portfolio
by jmlocatelli. 09/19/20 22:24
New Zorro version 2.30
by danatrader. 09/19/20 08:25
Special Bars Script
by danatrader. 09/19/20 00:41
NeoDumont's open world treadmill project
by NeoDumont. 09/19/20 00:30
Key_Pressed Variable
by Dooley. 09/18/20 22:46
lock profit without trail
by Grat. 09/18/20 14:30
how to use BrokerHistory2
by Grat. 09/18/20 14:29
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
5 registered members (danatrader, NewBorn, Grat, AndrewAMD, 1 invisible), 429 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
NewBorn, 3dvg, secretagentman, distribution, EditeY
18515 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: 79
G
gamers Offline OP
Junior Member
gamers  Offline OP
Junior Member
G

Joined: Jan 2012
Posts: 79
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,293
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,293
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: 79
G
gamers Offline OP
Junior Member
gamers  Offline OP
Junior Member
G

Joined: Jan 2012
Posts: 79
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
02/17/20 11:09
02/17/20 11:09
Joined: Jan 2012
Posts: 79
G
gamers Offline OP
Junior Member
gamers  Offline OP
Junior Member
G

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

Re: Is Text Box data check possible? [Re: gamers] #479095
02/17/20 14:05
02/17/20 14:05
Joined: May 2009
Posts: 5,293
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,293
Caucasus
I think it depends on how you created your text box. As far as I know, there is no default text box in acknex... if you use (f.e.) imgui there is already implemented text box with limitation etc.. You can check it out here.

Best regards!

Edit: maybe I misunderstood your question.. to input only 0...99 numbers, I would check for the length on the string (make sure it's numeric), if the length >= 3, then value is 100 and higher.

Last edited by 3run; 02/17/20 14:07.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Re: Is Text Box data check possible? [Re: 3run] #479098
02/18/20 05:29
02/18/20 05:29
Joined: Jan 2012
Posts: 79
G
gamers Offline OP
Junior Member
gamers  Offline OP
Junior Member
G

Joined: Jan 2012
Posts: 79
Thank you for your answer 3run. Actually, I want to use only the textbox part of IMGUI. How can I do that? In other words, I want to create a text box that I want, to ensure that the data entered is only between 0 and 100, and to check whether the data is entered or not, and to warn the user if any data has not been entered into textbox.

Re: Is Text Box data check possible? [Re: gamers] #479100
02/18/20 07:20
02/18/20 07:20
Joined: Jul 2007
Posts: 577
Turkey, izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 577
Turkey, izmir
So, you want to input box for only numbers, between 0&100. Here is another way. Not the good one but at least it can give some idea;

Code
#include <acknex.h>


STRING* defstr="#100";
STRING* test_str="";


//is input box open
int is_input_box_on=0;

//test variable
int test_num;

//debug
function textx_startup()
{
	while(1)
	{
		if(is_input_box_on==1)
		{
			draw_text("Enter any number",1,1,COLOR_GREEN);
			draw_text(test_str,1,200,COLOR_GREEN);

			
		}
		DEBUG_VAR(test_num,20);
		wait(1);
	}
}

function on_f1_event() 
{
	beep();
	
	//clear all strings

	str_cpy(test_str,"");
	test_num=0;
	

	

	char this_char = 0;
	is_input_box_on=1;
	
	while(this_char!=13)//wait until press enter
	{
		

		this_char = inchar(defstr);
		if(this_char!=1)  
		{
			//if is numeric
			if(str_stri(this_char,"0")||
			str_stri(this_char,"1")||
			str_stri(this_char,"2")||
			str_stri(this_char,"3")||
			str_stri(this_char,"4")||
			str_stri(this_char,"5")||
			str_stri(this_char,"6")||
			str_stri(this_char,"7")||
			str_stri(this_char,"8")||
			str_stri(this_char,"9"))
			{
				str_cat(test_str,defstr);
				
			}
			else
			{
				//if isn't numeric don't do anything
			}
			
		}
		wait(1);
	}

	//convert string to number
	test_num=str_to_int(test_str);
	
	//turn of the box
	is_input_box_on=0;

	
	//if bigger than 100
	if(test_num>100)
	{
		printf("Error: Value is bigger than 100!");
		
		//try again
		on_f1_event(); 
	}

}




function main()
{

	on_f1_event();
}
void on_esc_event()
{
	sys_exit("");
}


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