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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 parameter passing from column

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
patrick031284 Posted - 09/17/2007 : 04:20:33 AM
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
4   L A T E S T    R E P L I E S    (Newest First)
patrick031284 Posted - 09/20/2007 : 03:57:03 AM
Hello Mike.

Thank you very much. Now it works :-)

kind regards
Patrick
Mike Buess Posted - 09/19/2007 : 08:38:33 AM
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
patrick031284 Posted - 09/19/2007 : 05:46:24 AM
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
Mike Buess Posted - 09/17/2007 : 11:24:50 AM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000