String's manipulation?

For questions about using Classic.

Post » Mon Apr 02, 2012 7:59 pm

Hello people,

I know that it's a noob question, but I began to use Construct yesterday, and I don't know much about it.

I'm doing a software to my dad that generates a radar code to his GPS. I thinked it would be simple to do, but I'm having many difficulties.

Well, first, I have an Edit Box. In this editbox, user must enter latitude (e.g.: S3.34022). So, I would like that when user clicks on the button, a Text would be defined to -3.34022 (remove the "S", add a "-" and so write the number). I tried many things, but nothing works.

If I use float(EDITBOX.Text), doesn't work too. Because when I write "S" on Editbox, the program ignores all numbers after it.

Am I doing something wrong?
Thanks.
B
1
G
1
Posts: 4
Reputation: 433

Post » Mon Apr 02, 2012 8:18 pm

Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon Apr 02, 2012 8:30 pm

When converting a string to a number, the string must begin with the number. It stops as soon as there is anything else. For example int("2g34") will return 2, float("3.2H45") will return 3.2, and float("S3.34022") will return 0, as it starts with a letter.

But there is an easier way to achieve the results. As I understand, latitudes may be written as with "N" and "S" or "+" and "-" in the beginning. If so, then just use replace()

+ Button: On Button clicked
-> System: Set global variable 'latitude' to replace(Uppercase(EditBox.Text), "N", "+")
-> System: Set global variable 'latitude' to replace(global('latitude'), "S", "-")
-> Text: Set text to global('latitude')

latitude is a text variable

This event will first convert the text of the editbox to uppercase, then replace all "N" in that text with "+" and all "S" with "-". This way, the user can enter the latitude in any way, e.g. "+3.34", "N3.34", "n3.34"
However, you still have to make sure the latitude is not entered incorrectly.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Apr 02, 2012 9:09 pm

Thanks to both =)

Well, I tried to read a tutorial written by Ashley, but it didn't help me... and I searched in Google, but didn't find nothing too.

Tulamide, it didn't work. But thanks anyway! I'll try again later =).
B
1
G
1
Posts: 4
Reputation: 433

Post » Tue Apr 03, 2012 12:07 am

[QUOTE=Eskyz]Tulamide, it didn't work. But thanks anyway! I'll try again later =).[/QUOTE] If it doesn't work, then you've done something wrong. For me it works like a charme, as you can see here:



I will share the cap with you, but you should try to find your mistake, in order to learn. And maybe try something else for a start, to get used to CC?

LatitudeConversion.cap
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest