Thanks so much for your time and attention. I should note that I mislabeled my code. This is actually the tube material "70-30 Cu-Ni", "90-10 Cu-Ni", "Admiralty Metal", "Aluminum Brass", "Aluminum Bronze", "Arsenical Copper", "Cold-Rolled Low Carbon Steel", "Copper Iron 194 (Olin 194)", "Titanium Grades 1 & 2", "304 SS", "316/317 SS", "N08367 (AL6XN)", "S43035 (TP439)", "S44660 (Sea-Cure)", "S44735 (AL29-4C)" versus the tube gauge {12, 14, 16, 18, 20, 22, 23, 24, 25}; Which when matched up in x, y matrix returns the HEI gauge correction factor. On another note, I am tying to pass the tube gauge (int) and the tube material (string) from a VBA function: Declare Function TSx Lib "C:/cnd_perf.dll" (arg1 As Integer, arg2 As String) As Double and return the factor found in the array values you showed in your code (should be a double or a long) back to Excel, (and maybe later in another function return the tube material and gauge also.) Problem is I can pass the VBA string to C++, but have had no success in checking it against the tube material values as shown above so I can get the correct lookup value between the material and the gauge. I have tried char (with strcmp), BSTR, and std::string, but I am still not quite there
jharn
Posts
-
String array comparison -
String array comparisonAll I can say is: 1. Wow, thanks....!!!! 2. I have so much to learn about C++, I do have a book from when I took a course in college, guess I better drag it back out and start studying. 3. You guys on the list are great, I look forward so much to learning from all of you. Sincerely, Joe
-
String array comparisonOh, also I typed into my .cpp file as you wrote: double[][] vl_reg3 = {vl_reg12, vl_reg14, vl_reg16, vl_reg18, vl_reg20, vl_reg22, vl_reg23, vl_reg24, vl_reg25}; At first set of brackets: Error: expected an identifier At second set of brackets: Error: an array may not have elements of this type At text vl_reg3: Error: expectd a ';' for some reason it does not like it that way. I am not sure why.
-
String array comparisonKP, thanks for the help and the advice. I am persistent and stubborn, but when it comes to listening to the people on the list who know better I am all ears. You are right about the error checking for caller mistakes, I really should do more of that. I will try your multi-array as you suggested. I am still having a bit of trouble passing a string from VBA Declare statement to the C++ function correctly and checking if the string matches existing strings already in the C++ function. I think I am getting hung up on the ASCII/Unicode difference. I will keep toiling away. Again, thank you very much.
-
String array comparisonThis is the VBA code I was trying to translate from, it is a bit cleaner since I am a bit more familiar with it. Just posting so you can see what I was trying to do. Function HEI_F2(ByVal typ As Variant, bwg As Integer) As Double 'saturation pressure inHg from Temp Dim vl_reg1 As Variant, vl_reg2 As Variant, vl_reg3 As Variant, vl_reg12 As Variant Dim vl_reg14 As Variant, vl_reg16 As Variant, vl_reg18 As Variant, vl_reg20 As Variant Dim vl_reg22 As Variant, vl_reg23 As Variant, vl_reg24 As Variant, vl_reg25 As Variant Dim tp As Integer vl_reg1 = Array("70-30 Cu-Ni", "90-10 Cu-Ni", "Admiralty Metal", "Aluminum Brass", "Aluminum Bronze", _ "Arsenical Copper", "Cold-Rolled Low Carbon Steel", "Copper Iron 194 (Olin 194)", _ "Titanium Grades 1 & 2", "304 SS", "316/317 SS", _ "N08367 (AL6XN)", "S43035 (TP439)", "S44660 (Sea-Cure)", "S44735 (AL29-4C)") vl_reg2 = Array(12, 14, 16, 18, 20, 22, 23, 24, 25) vl_reg12 = Array(0.71, 0.8, 0.93, 0.92, 0.89, 0.98, 0.81, 1#, 0.64, 0.54, 0.53, 0.48, 0.63, 0.58, 0.58) vl_reg14 = Array(0.78, 0.85, 0.96, 0.95, 0.93, 1#, 0.86, 1.01, 0.71, 0.62, 0.61, 0.56, 0.71, 0.66, 0.66) vl_reg16 = Array(0.83, 0.89, 0.98, 0.97, 0.96, 1.01, 0.9, 1.02, 0.77, 0.69, 0.67, 0.63, 0.77, 0.72, 0.72) vl_reg18 = Array(0.88, 0.93, 1#, 0.99, 0.98, 1.02, 0.94, 1.03, 0.83, 0.75, 0.74, 0.7, 0.82, 0.79, 0.79) vl_reg20 = Array(0.92, 0.96, 1.01, 1.01, 1#, 1.03, 0.97, 1.03, 0.89, 0.82, 0.81, 0.78, 0.88, 0.85, 0.85) vl_reg22 = Array(0.95, 0.98, 1.02, 1.02, 1.01, 1.03, 0.98, 1.04, 0.91, 0.86, 0.85, 0.82, 0.91, 0.89, 0.89) vl_reg23 = Array(0.96, 0.99, 1.02, 1.02, 1.01, 1.04, 0.99, 1.04, 0.93, 0.88, 0.87, 0.84, 0.92, 0.9, 0.9) vl_reg24 = Array(0.97, 0.99, 1.03, 1.02, 1.02, 1.04, 1#, 1.04, 0.94, 0.9, 0.89, 0.86, 0.94, 0.92, 0.92) vl_reg25 = Array(0.97, 1#, 1.03, 1.03, 1.02, 1.04, 1#, 1.04, 0.95, 0.91, 0.9, 0.88, 0.95, 0.93, 0.93) vl_reg3 = Array(vl_reg12, vl_reg14, vl_reg16, vl_reg18, vl_reg20, vl_reg22, vl_reg23, vl_reg24, vl_reg25) counter = 0 Do While counter <= UBound(vl_reg1) If typ = vl_reg1(counter) Then tp = counter Exit Do End If counter = counter + 1 Loop counter = 0 Do While counter <= UBound(vl_reg2) If bwg = vl_reg2(counter) Then bg = counter Exit Do End If counter = counter + 1 Loop HEI_F2 = (vl_reg3(bg)(tp)) End Function
-
String array comparisonAll, thank you very much for your help and your constructive criticism. I do realize I am a complete newbie and I hope I can improve my programming skills. I do know that the last line of the code would not work (vl_reg3[bg][tp]).....it was written ion visual basic and I was in the process of converting it to C++. I have since found out that the function in C++ is not receiving the text string I am trying to send form a VBA Declare function, so I guess I need to figure that out first. All, I know I am not a good programmer, but I ma very persistent so I will keep trying to learn and I hope all of you are not offended by my less than intelligent coding and questions.
-
String array comparisonOK, I see, sorry to bother, I know it usually is not much fun helping a newbie, but I really do appreciate your guidance.
-
String array comparisonHi, I tried arg1==a, now it says that no operator "==" matches these operands.
-
String array comparisonhahahaha......you are SO right, my apologies
-
String array comparisonHi, I tried arg1==a, now it says that no operator "==" matches these operands.
-
String array comparisonIs that not an AND function? == I guess I am confused.....
-
String array comparisonSorry, I wasn't clear.... in the part where I compare if (arg1 = a) it tells me expression must have a bool type.
-
String array comparisonHey all, hope everyone had a great weekend. I have some code where I am passing a string array and some numbers and want to reconcile the two as far as a lookup table. When I want to compare a value in an array to a value passed to the function it wants arg1 to be boolean, but I am not sure the proper syntax. can anyone give me an idea of what I am doing wrong? Also, I am not sure the code will work as written anyway, but this is the only error popping up so far. double __stdcall HEI_F2(string &arg1, int &arg2) { int tp; int bg; int counter, typ, bwg, b; string vl_reg1[16] = {"70-30 Cu-Ni", "90-10 Cu-Ni", "Admiralty Metal", "Aluminum Brass", "Aluminum Bronze", "Arsenical Copper", "Cold-Rolled Low Carbon Steel", "Copper Iron 194 (Olin 194)", "Titanium Grades 1 & 2", "304 SS", "316/317 SS", "N08367 (AL6XN)", "S43035 (TP439)", "S44660 (Sea-Cure)", "S44735 (AL29-4C)"}; string a; int vl_reg2[10] = {12, 14, 16, 18, 20, 22, 23, 24, 25}; double vl_reg12[16] = {0.71, 0.8, 0.93, 0.92, 0.89, 0.98, 0.81, 1, 0.64, 0.54, 0.53, 0.48, 0.63, 0.58, 0.58}; double vl_reg14[16] = {0.78, 0.85, 0.96, 0.95, 0.93, 1, 0.86, 1.01, 0.71, 0.62, 0.61, 0.56, 0.71, 0.66, 0.66}; double vl_reg16[16] = {0.83, 0.89, 0.98, 0.97, 0.96, 1.01, 0.9, 1.02, 0.77, 0.69, 0.67, 0.63, 0.77, 0.72, 0.72}; double vl_reg18[16] = {0.88, 0.93, 1, 0.99, 0.98, 1.02, 0.94, 1.03, 0.83, 0.75, 0.74, 0.7, 0.82, 0.79, 0.79}; double vl_reg20[16] = {0.92, 0.96, 1.01, 1.01, 1, 1.03, 0.97, 1.03, 0.89, 0.82, 0.81, 0.78, 0.88, 0.85, 0.85}; double vl_reg22[16] = {0.95, 0.98, 1.02, 1.02, 1.01, 1.03, 0.98, 1.04, 0.91, 0.86, 0.85, 0.82, 0.91, 0.89, 0.89}; double vl_reg23[16] = {0.96, 0.99, 1.02, 1.02, 1.01, 1.04, 0.99, 1.04, 0.93, 0.88, 0.87, 0.84, 0.92, 0.9, 0.9}; double vl_reg24[16] = {0.97, 0.99, 1.03, 1.02, 1.02, 1.04, 1, 1.04, 0.94, 0.9, 0.89, 0.86, 0.94, 0.92, 0.92}; double vl_reg25[16] = {0.97, 1, 1.03, 1.03, 1.02, 1.04, 1, 1.04, 0.95, 0.91, 0.9, 0.88, 0.95, 0.93, 0.93}; string vl_reg3[16] = {"vl_reg12", "vl_reg14", "vl_reg16", "vl_reg18", "vl_reg20", "vl_reg22", "vl_reg23", "vl_reg24", "vl_reg25"}; counter = 0; do{ a = vl_reg1[counter]; if (arg1 = a) { tp = counter; } counter = counter + 1; }while (counter <= 16); counter = 0; do{ b = vl_reg2[counter]; if (tp = b) { bg = counter; } counter = counter + 1; }while (counter <= 10); return vl_reg3[bg][tp]; }
-
Creating .dll linked to Excel, add function error [modified]This function seems to be causing the assertion failure, but I cannot se why, it compiles without error. I think I found the error, it appears I cannot delete the arrays before I return x, does anyone know this to be true? delete [] J0; delete [] n0; delete [] Ir; delete [] Jr; delete [] nr; return(x); }
modified on Thursday, January 27, 2011 5:35 PM
-
Creating .dll linked to Excel, add function error [modified]Gentlemen, I hope everyone is having a good day. I have an problem with my .dll that is linked to Excel. I have 2 functions in the file, they are named in the def file and they work fine. I added a third this morning, added name to def file. I declared it in VBE. For some reason, when I try to type it into a cell and give it a variable, i.e. cell formula is =Hs_P(B8), immediately Excel has an error and shuts down. I am very perplexed. Any ideas? Have I given enough information? This is the error Excel is throwing out "Excel asertion error" And the line from the code _ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)); I haven't found the problem, but I believe it is the way I am calling one function from inside of another function.
-
else does nto return expected valueThank you very much for your help.....in troubleshooting this I realize that I need to figure out how to operate the debugger. I can attach it to Excel and add the breakpoints, however it seems to do nothing. Again, thank you so much...
-
else does nto return expected valueI played with the code, this returns the values I need: double __stdcall Ts_P(double &arg)//psia input, DegF output { double h_reg_1; double h_reg_2; double h_reg_3; double h_reg_4; double x; double vl_reg1[10] = {1167.0521452767, -724213.16703206, -17.073846940092, 12020.82470247,-3232555.0322333, 14.91510861353, -4823.2657361591, 405113.40542057, -0.23855557567849, 650.17534844798}; double p = (arg * 0.0068947572); //convert psia to MPa double beta = pow(p,0.25); if(p >= 0.000611657 && p <= 22.06495) { h_reg_1 = pow(beta,2) + vl_reg1[2] * beta + vl_reg1[5];//IFC 97 E term h_reg_2 = vl_reg1[0] * pow(beta,2) + vl_reg1[3] * beta + vl_reg1[6];//IFC 97 F term h_reg_3 = vl_reg1[1] * pow(beta,2) + vl_reg1[4] * beta + vl_reg1[7];//IFC 97 G term h_reg_4 = (2 * h_reg_3) / ((-1*h_reg_2) - (pow((pow(h_reg_2,2) - 4 * h_reg_1 * h_reg_3), 0.5)));//IFC 97 D term x = (((vl_reg1[9] + h_reg_4 - pow((pow((vl_reg1[9] + h_reg_4),2) - 4 * (vl_reg1[8] + vl_reg1[9] * h_reg_4)),0.5)) / 2) - 273.15) * (1.8) + 32; return(x); } else { x=-1; } return(x); }
-
else does nto return expected valueOnly in that from the Excel spreadsheet where I am entering the variable p into the function I can set it so that it is outside of the range of the if statement parameters. The value is returns when this is so is something like 1.7878e+308.
-
else does nto return expected valueI may not be clear on the code. p must be between these ranges for the calculation to execute, if it is outside of these ranges then the calculation does not apply and I want a 0 or a -1 returned.
-
else does nto return expected valueWhen you say please reformat the code I am not sure what you are suggesting. When I try to run the debugger it says that it cannot open the .dll file that was created. The only way I can run it is to open up the excel file that references the .dll and plug in values for p that are either inside or outside of the range of the if statement and view the results.