

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hello,
I've been struggling with this all afternoon. I have a 16 digit number that for each iteration I need to add 1 to and then convert that into a string parameter for use later on. But I'm not able to figure out how to do this with the function reference library in VuGen. Here's an example of what I'm trying to do:
float flt = atof("1111119999999999");
float flt2 = flt + 1;
const char* chr;
sprintf(chr,"%.0f",flt2);
lr_save_string(chr,"OutParm");
lr_vuser_status_message("Output: %s",lr_eval_string("{outParm}"));
I'm hoping to get:
Output: 1111120000000000
But instead it's throwing error messages.
Thoughts?
Accepted Solutions


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
there are more problems that just those two.
1) define your string as char chr[16];
2) in my testing atof does not give you the value that you want. You can see what I mean by pasting in the example code from the help file in VuGen 11.52
float x;
char *s = "7.2339";
x = atof(s);
/* The %.2f formatting string limits the output to 2 decimal places */
lr_output_message("%.2f", x);
According to the help the output should be 7.23 but when run in VuGen the output is 105132216.00 So there is a problem with the atof function. I can check to see if it is resolved in VuGen 12.01 but I don't think it has.
3) you have to many digits. VuGen will only be able to process the first 10 digits before you will get a memory exception.
I changed your code to the following and it runs with no error:
Action()
{
//1111119999999999
float flt = 1111119999;
float flt2 = flt + 1;
char chr[16];
sprintf(chr,"%.0f",flt2);
lr_save_string(chr,"OutParm");
lr_output_message("%.0f", flt);
lr_output_message("%.0f", flt2);
lr_output_message("output: %s", lr_eval_string("{OutParm}"));
return 0;
}
Craig Drummond
HP SW Premier Support, Technical Account Manger - ALM Products

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Issue 1: allocate memory for "chr".
Issue 2: change "outParam" to "OutParam" in last line.
R&D Manager, Performance Engineering Core


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
there are more problems that just those two.
1) define your string as char chr[16];
2) in my testing atof does not give you the value that you want. You can see what I mean by pasting in the example code from the help file in VuGen 11.52
float x;
char *s = "7.2339";
x = atof(s);
/* The %.2f formatting string limits the output to 2 decimal places */
lr_output_message("%.2f", x);
According to the help the output should be 7.23 but when run in VuGen the output is 105132216.00 So there is a problem with the atof function. I can check to see if it is resolved in VuGen 12.01 but I don't think it has.
3) you have to many digits. VuGen will only be able to process the first 10 digits before you will get a memory exception.
I changed your code to the following and it runs with no error:
Action()
{
//1111119999999999
float flt = 1111119999;
float flt2 = flt + 1;
char chr[16];
sprintf(chr,"%.0f",flt2);
lr_save_string(chr,"OutParm");
lr_output_message("%.0f", flt);
lr_output_message("%.0f", flt2);
lr_output_message("output: %s", lr_eval_string("{OutParm}"));
return 0;
}
Craig Drummond
HP SW Premier Support, Technical Account Manger - ALM Products


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I checked Vugen 12.01 and the atof function is not producing the same result as 11.52 but 12.01 is still wrong. I will open a case to have HP look at why.
Craig

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Craig, did you ever get an update from HP on this?
Thanks,
Chris


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Unfortunately no, I have not been able to open any cases on the support site because of the changes they made recently.
Craig

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I'll make sure to check this and have it fixed.
R&D Manager, Performance Engineering Core

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi All,
As it's described in Functional Reference example, you should add the following text:
double atof(const char *string) before the Action ().
double atof( const char *string); /* Explicit declaration */
vuser_init() {
float x;
char *s = "7.2339 by these hilts or I am a villain else";
x = atof(s);
/* The %.2f formatting string limits the output to 2 decimal places */
lr_output_message("%.2f", x);
return 0;
}
That fixes the problem
Thanks,
Vladimir,
LoadRunner QA Engineer