The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 parameter passing from column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

patrick031284

Germany
Posts

Posted - 09/17/2007 :  04:20:33 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,

i have a problem with Origin C. I programmed a function to convert hexadecimal values in decimal values.
The programm works very good in my code builder. But if i want it to use in the Origin worksheet I get values like 2.32504E8 ??
I think the problem is the parameter passing from the column where the hexadecimal values are located.
How can i programm it?

Here is the code:

#include <stdio.h>
#include <math.h>
#include <string.h>


int hex(String hexzahl)
{
int dec_sum=0, i=0, length=0, dec;

length = strlen(hexzahl);
length--;

for ( ; length >= 0 ; length--)
{
switch(hexzahl[length])
{
case '0': dec=0; break;
case '1': dec=1; break;
case '2': dec=2; break;
case '3': dec=3; break;
case '4': dec=4; break;
case '5': dec=5; break;
case '6': dec=6; break;
case '7': dec=7; break;
case '8': dec=8; break;
case '9': dec=9; break;
case 'A': dec=10; break;
case 'B': dec=11; break;
case 'C': dec=12; break;
case 'D': dec=13; break;
case 'E': dec=14; break;
case 'F': dec=15; break;
default: break;
}

dec_sum+=dec*(16^i);
i++;
}


// printf("\nDecimal: %d", dec_sum);
return dec_sum;

}


I hope anyone can help me.

Thank you very much.

Kind regards
Patrick

Mike Buess

USA
3037 Posts

Posted - 09/17/2007 :  11:24:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Patrick,

Your function works fine if you pass the cell values as strings as in this LabTalk script...

for(i=1;i<9;i++) {
%A=cell(i,1)$; // row i, col 1 as string
cell(i,2)=hex(%A);
};



Note: LabTalk has a built-in hex function...
quote:
hex(string)
The hex(string) function returns the base 10 equivalent to the hexadecimal value represented by the given string. The maximum number of hex characters in the given string is 4.


Mike Buess
Origin WebRing Member
Go to Top of Page

patrick031284

Germany
Posts

Posted - 09/19/2007 :  05:46:24 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you for your help.
But it didn't still work.

I change the values in my column into strings (text).

Do I have to write your example-code in my script or do i have to change anything in my script?

Kind regards
Patrick
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/19/2007 :  08:38:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Patrick,

>I used your function exactly as you posted it. (Except that I omitted the #includes which are unnecessary.)

>Column types were text & numeric.

>I ran my LabTalk script from the script window by selecting all lines and pressing Enter...
http://www.originlab.com/www/support/resultstech.aspx?ID=1056&language=English&Version=7.5

Mike Buess
Origin WebRing Member
Go to Top of Page

patrick031284

Germany
Posts

Posted - 09/20/2007 :  03:57:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Mike.

Thank you very much. Now it works :-)

kind regards
Patrick
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000