variable inside string?

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

variable inside string?

Post by hyperion007 »

Don't know exactly how to phrase the subject but what I need to know is how I can take this String:
"AT+HTTPPARA=\"URL\",\"http://www.domain.com/insert.php?temperature01=200\""

and change out the '200' part, for a variable inside this string...

Should it be like:
Calc: STRING_VARIABLE = ToString$(INT_VARIABLE)

"AT+HTTPPARA=\"URL\",\"http://www.level6.se/insert2.php?temper ... G_VARIABLE\'\""

or

"AT+HTTPPARA=\"URL\",\"http://www.level6.se/insert2.php?temper ... G_VARIABLE'\""

Or is this not possible?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: variable inside string?

Post by Benj »

Hello,

I don't think you can place the variable inside the string but it should be possible to merge together strings into a variable.

Calc: STRING_VAR1 = ToString$(INT_VARIABLE)
Calc: STRING_VAR2 = "Fixed string data " + STRING_VAR1

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: variable inside string?

Post by hyperion007 »

Ok, the problem with that, I think, is that the variable needs to be inserted before the " and if I do this:

Temp = Temp + 1
Data_String = ToString$ (Temp)
Data_String2="AT+HTTPPARA=\"URL\",\"http://www.domain.com/insert.php?temperature01=" + Data_String
Data_String2=Data_String2 + "\""

then
Call component Macro:
SendCommand(Data_String2,1)

I get a compilation error saying "missing semi colon" in the Calculation

My guess is because the \" is "missing" from the calculation:
Data_String2="AT+HTTPPARA=\"URL\",\"http://www.domain.com/insert.php?temperature01=[b]\"[/b]" + Data_String

Or what do you think?
Last edited by hyperion007 on Wed Apr 30, 2014 12:02 pm, edited 1 time in total.

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: variable inside string?

Post by hyperion007 »

I found this from a post on some forum:

String url = "AT+HTTPPARA=\"URL\",\"http://domain.com/insert.php?";
url.concat("temperature01=");
url.concat(Temp);
url.concat("\"");
//Serial.println(url);

But I don't know how to do something similar in Flowcode

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: variable inside string?

Post by LeighM »

Looks like you have found a Flowcode bug
Seems it does not like // in strings
Here is a workaround ...

Code: Select all

Temp = Temp + 1
Data_String = ToString$ (Temp)
Data_String2 = "AT+HTTPPARA=\"URL\",\"http:/"
Data_String2 = Data_String2 + "/www.domain.com/insert.php?temperature01="
Data_String2 = Data_String2 + Data_String
Data_String2 = Data_String2 + "\""

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: variable inside string?

Post by hyperion007 »

Hi LeighM

Thanks, now it works! I don't even need the "http://" part so I removed that and it worked (I had my strings set to [40] which was way to small, now at [80] it works fine)

Best day in a VERY long time :) Got the Sim900 working, sending data to my hosted MySQL database. Thanks again!

Rudi
Posts: 666
Joined: Mon Feb 10, 2014 4:59 am
Has thanked: 493 times
Been thanked: 187 times

Re: variable inside string?

Post by Rudi »

hyperion007 wrote:Hi LeighM

Got the Sim900 working, sending data to my hosted MySQL database.
super! ;-) ...

Best wishes
Rudi
:-)

Post Reply