Conversions

PoweRoyPoweRoy Member Posts: 43
edited 2006-07-26 in Navision Attain
2 bad my other 2 topics arent solved yet but i bumped to another one.

note: programmed in c#.net

i use the stringbuilder to collect data from the database using cfront.dll (see here)
but i have some troubles with the conversions (aka not getting the results i should have)

so i made a small program to give a string, and transform it and then back again.

the functions that are available in cfront.dll and how i used them:
//textBox1 is the input and textBox2 the output

bcd_2_str
[DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] 
private static extern void DBL_BCD_2_Str(System.Text.StringBuilder _string, int strLength, string deciStr);
//bcd to string 
System.Text.StringBuilder sbuilder = new System.Text.StringBuilder(35);
DBL_BCD_2_Str(sbuilder,35,textBox1.Text);
textBox2.Text = sbuilder.ToString();
input: "1234"
result: "0,00000000000000000000000000343332"

str_2_bcd
[DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] 
private static extern void DBL_Str_2_BCD(System.Text.StringBuilder _string, string dateStr);
//string to bcd
System.Text.StringBuilder sbuilder = new System.Text.StringBuilder(35);
DBL_Str_2_BCD(sbuilder,textBox1.Text);
textBox2.Text = sbuilder.ToString();
input: "1234" other input: 0,00000000000000000000000000343332 (result bcd_2_str)
result: "C" output: %

[Dlbcd_2_double[/b] //note i use the stringbuilder cause if i used as 1param a double i didnt get anything
[DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] 
private static extern void DBL_BCD_2_Double(System.Text.StringBuilder _value, string bcdstr);
//bcd to double
System.Text.StringBuilder sbuilder = new System.Text.StringBuilder(35);
DBL_BCD_2_Double(sbuilder,textBox1.Text);
textBox2.Text = Convert.ToString(sbuilder.ToString());
input: "1234"
result: "OyØ1Øÿp:"

[Dldouble_2_bcd[/b]
[DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] 
private static extern void DBL_Double_2_BCD( string bcdstr, double _value);
//double to bcd
string getal = "";
DBL_Double_2_BCD(getal,Convert.ToDouble(textBox2.Text));
textBox2.Text = getal;
input: "1234"
result: error inputstring was not in a correct format

[Dldate_2_str[/b]
[DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] 
private static extern void DBL_Date_2_Str(System.Text.StringBuilder _string, int strLength, string dateStr);
//date to string
System.Text.StringBuilder sbuilder = new System.Text.StringBuilder(35);
DBL_Date_2_Str(sbuilder,35,textBox1.Text);
textBox2.Text = sbuilder.ToString();
input: any date
result: "U11-06-1697" <-- always gives this in return

[Dlstr_2_date[/b]
[DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)] 
private static extern void DBL_Str_2_Date(System.DateTime date, string dateStr);
//string to date
System.DateTime datum = new System.DateTime();
DBL_Str_2_Date(datum,textBox1.Text);
textBox2.Text = Convert.ToString(datum);
input: Any date
result: object reference not set to an instance of an object

Where does it go wrong and what is a sollution
thx in advance!

Comments

  • jaisajaisa Member Posts: 6
    you can call to the function with:

    StringBuilder sbuilder = new StringBuilder();
    DBL_BCD_2_Str(sbuilder,35,textBox1.Text);
    textBox2.Text = sbuilder.ToString();

    i think that the string builder is buid dynamic and if you put the length the string builder fill with ceros.

    i hope that it's ok.
    Jacinto Aisa
Sign In or Register to comment.