Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. String array comparison

String array comparison

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
31 Posts 10 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J jsc42

    You are trying to compare two strings. The == operator just compares simple scalar values, not arrays. I'm not a C++ / C# programmer, but if it was C, I'd suggest using the strcmp function - there must be a C++ / C# equivalent. If it was Java, you'd use the equals() method.

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #19

    jsc42 wrote:

    You are trying to compare two strings. The == operator just compares simple scalar values, not arrays.

    Neither arg1 nor a is an array. They are both string objects, which has this.

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "Man who follows car will be exhausted." - Confucius

    J 1 Reply Last reply
    0
    • J jharn

      This 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

      K Offline
      K Offline
      KP Lee
      wrote on last edited by
      #20

      Going from vba to a strongly typed language explains a lot. The main complaint I have with your original vba version is that you expect the caller to be reasonable and accurate. I find it best to assume the caller is the exact opposite until proven otherwise. That is best even if the caller is yourself. Set bg and tp to -1 before starting the loop and check to make sure both are >= 0 before setting the double value. You can set up a double[][] vl_reg3 = {vl_reg12, vl_reg14, vl_reg16, vl_reg18, vl_reg20, vl_reg22, vl_reg23, vl_reg24, vl_reg25}; and use the same index formats in the new language as you did in the old vba code. Don't appologize for being stubborn, that's a normal trait for a programmer. You have to be in order to be beaten down over and over again by the code you write and getting up and trying again. Just dial back the stubbornness when meeting other humans and listen. (That's something I have to watch out for.)

      J 2 Replies Last reply
      0
      • K KP Lee

        Going from vba to a strongly typed language explains a lot. The main complaint I have with your original vba version is that you expect the caller to be reasonable and accurate. I find it best to assume the caller is the exact opposite until proven otherwise. That is best even if the caller is yourself. Set bg and tp to -1 before starting the loop and check to make sure both are >= 0 before setting the double value. You can set up a double[][] vl_reg3 = {vl_reg12, vl_reg14, vl_reg16, vl_reg18, vl_reg20, vl_reg22, vl_reg23, vl_reg24, vl_reg25}; and use the same index formats in the new language as you did in the old vba code. Don't appologize for being stubborn, that's a normal trait for a programmer. You have to be in order to be beaten down over and over again by the code you write and getting up and trying again. Just dial back the stubbornness when meeting other humans and listen. (That's something I have to watch out for.)

        J Offline
        J Offline
        jharn
        wrote on last edited by
        #21

        KP, 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.

        1 Reply Last reply
        0
        • K KP Lee

          Going from vba to a strongly typed language explains a lot. The main complaint I have with your original vba version is that you expect the caller to be reasonable and accurate. I find it best to assume the caller is the exact opposite until proven otherwise. That is best even if the caller is yourself. Set bg and tp to -1 before starting the loop and check to make sure both are >= 0 before setting the double value. You can set up a double[][] vl_reg3 = {vl_reg12, vl_reg14, vl_reg16, vl_reg18, vl_reg20, vl_reg22, vl_reg23, vl_reg24, vl_reg25}; and use the same index formats in the new language as you did in the old vba code. Don't appologize for being stubborn, that's a normal trait for a programmer. You have to be in order to be beaten down over and over again by the code you write and getting up and trying again. Just dial back the stubbornness when meeting other humans and listen. (That's something I have to watch out for.)

          J Offline
          J Offline
          jharn
          wrote on last edited by
          #22

          Oh, 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.

          K 1 Reply Last reply
          0
          • J jharn

            Hey 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]; }

            M Offline
            M Offline
            MarvinMartian
            wrote on last edited by
            #23

            This code is not C. It could be C++ or Java. A string in C IS a character ARRAY and is not declared as string but as char[string length+1]. Try: if (arg1.equal(a)) { tp = counter; }

            1 Reply Last reply
            0
            • J jharn

              Oh, 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.

              K Offline
              K Offline
              KP Lee
              wrote on last edited by
              #24

              Sorry, thought that would work. Doesn't work in C# either. I don't use double array setups too often. (I do use multidimentional arrays -> [n, m]) You can declare double[][], but I don't know how to instantiate it.

              1 Reply Last reply
              0
              • D David Crow

                jsc42 wrote:

                You are trying to compare two strings. The == operator just compares simple scalar values, not arrays.

                Neither arg1 nor a is an array. They are both string objects, which has this.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "Man who follows car will be exhausted." - Confucius

                J Offline
                J Offline
                jsc42
                wrote on last edited by
                #25

                I apologise! I had forgotten that C++ allows operator overloading. :doh:

                1 Reply Last reply
                0
                • J jharn

                  This 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

                  A Offline
                  A Offline
                  Alain Rist
                  wrote on last edited by
                  #26

                  Hi,

                  jharn wrote:

                  This 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.

                  Indeed C++ and VBA are totally different beasts :) . The following should do the same, plus parameter validation, in modern C++ (requires std::tr1 coming with VC2010, VC2008 or gcc 4.5):

                  #include <string>
                  using std::string;
                  #include <array>
                  using std::array;
                  #include <stdexcept>
                  using std::invalid_argument;

                  typedef array<const string, 15> Names;
                  Names names =
                  {
                  "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)"
                  };

                  typedef array<const double, 15> SaturationPressure; // saturation pressure in Hg from Names at various temperatures
                  const SaturationPressure vl_reg12 = {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};
                  const SaturationPressure vl_reg14 = {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};
                  const SaturationPressure vl_reg16 = {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};
                  const SaturationPressure vl_reg18 = {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};
                  const SaturationPressure vl_reg20 = {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};
                  const SaturationPressure vl_reg22 = {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};
                  const SaturationPressure vl_reg23 = {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};
                  const SaturationPressure vl_reg24 = {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};
                  const SaturationPressure vl_reg25 = {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};

                  typedef array<const SaturationPressure, 9> Pressures;
                  Pressures pressures = {
                  vl_reg12, vl_reg14, vl_reg16, vl_reg18, vl_reg20, vl_reg22, vl_reg23, vl_reg24, vl_reg25};

                  typedef array<int, 9> Temperatures;
                  Temperatures temp = {12, 14, 16, 18, 20, 22, 23, 24, 25};

                  double HEI_F2(const string& n

                  J 2 Replies Last reply
                  0
                  • A Alain Rist

                    Hi,

                    jharn wrote:

                    This 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.

                    Indeed C++ and VBA are totally different beasts :) . The following should do the same, plus parameter validation, in modern C++ (requires std::tr1 coming with VC2010, VC2008 or gcc 4.5):

                    #include <string>
                    using std::string;
                    #include <array>
                    using std::array;
                    #include <stdexcept>
                    using std::invalid_argument;

                    typedef array<const string, 15> Names;
                    Names names =
                    {
                    "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)"
                    };

                    typedef array<const double, 15> SaturationPressure; // saturation pressure in Hg from Names at various temperatures
                    const SaturationPressure vl_reg12 = {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};
                    const SaturationPressure vl_reg14 = {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};
                    const SaturationPressure vl_reg16 = {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};
                    const SaturationPressure vl_reg18 = {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};
                    const SaturationPressure vl_reg20 = {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};
                    const SaturationPressure vl_reg22 = {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};
                    const SaturationPressure vl_reg23 = {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};
                    const SaturationPressure vl_reg24 = {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};
                    const SaturationPressure vl_reg25 = {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};

                    typedef array<const SaturationPressure, 9> Pressures;
                    Pressures pressures = {
                    vl_reg12, vl_reg14, vl_reg16, vl_reg18, vl_reg20, vl_reg22, vl_reg23, vl_reg24, vl_reg25};

                    typedef array<int, 9> Temperatures;
                    Temperatures temp = {12, 14, 16, 18, 20, 22, 23, 24, 25};

                    double HEI_F2(const string& n

                    J Offline
                    J Offline
                    jharn
                    wrote on last edited by
                    #27

                    All 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

                    A 2 Replies Last reply
                    0
                    • J jharn

                      All 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

                      A Offline
                      A Offline
                      Alain Rist
                      wrote on last edited by
                      #28

                      Hi Joe, Start with Bjarne Stroustrup's C++ Style and Technique FAQ[^] and C++0x - the next ISO C++ standard[^]. cheers, AR

                      When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

                      1 Reply Last reply
                      0
                      • J jharn

                        All 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

                        A Offline
                        A Offline
                        Alain Rist
                        wrote on last edited by
                        #29

                        I edited my code[^] which misinterpreted your input. Now simpler :) cheers, AR

                        When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

                        1 Reply Last reply
                        0
                        • A Alain Rist

                          Hi,

                          jharn wrote:

                          This 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.

                          Indeed C++ and VBA are totally different beasts :) . The following should do the same, plus parameter validation, in modern C++ (requires std::tr1 coming with VC2010, VC2008 or gcc 4.5):

                          #include <string>
                          using std::string;
                          #include <array>
                          using std::array;
                          #include <stdexcept>
                          using std::invalid_argument;

                          typedef array<const string, 15> Names;
                          Names names =
                          {
                          "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)"
                          };

                          typedef array<const double, 15> SaturationPressure; // saturation pressure in Hg from Names at various temperatures
                          const SaturationPressure vl_reg12 = {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};
                          const SaturationPressure vl_reg14 = {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};
                          const SaturationPressure vl_reg16 = {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};
                          const SaturationPressure vl_reg18 = {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};
                          const SaturationPressure vl_reg20 = {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};
                          const SaturationPressure vl_reg22 = {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};
                          const SaturationPressure vl_reg23 = {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};
                          const SaturationPressure vl_reg24 = {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};
                          const SaturationPressure vl_reg25 = {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};

                          typedef array<const SaturationPressure, 9> Pressures;
                          Pressures pressures = {
                          vl_reg12, vl_reg14, vl_reg16, vl_reg18, vl_reg20, vl_reg22, vl_reg23, vl_reg24, vl_reg25};

                          typedef array<int, 9> Temperatures;
                          Temperatures temp = {12, 14, 16, 18, 20, 22, 23, 24, 25};

                          double HEI_F2(const string& n

                          J Offline
                          J Offline
                          jharn
                          wrote on last edited by
                          #30

                          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

                          A 1 Reply Last reply
                          0
                          • J jharn

                            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

                            A Offline
                            A Offline
                            Alain Rist
                            wrote on last edited by
                            #31

                            Hi Joe,

                            jharn wrote:

                            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.

                            Change the names to relevant ones :)

                            jharn wrote:

                            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

                            This is a really different issue. I suppose VBA uses Unicode, so what is transmitted to your dll is a BSTR or a wchar_t*. First investigate around that. If you don't solve post in the Questions and Answers area with VBA C++ dll tags; cheers, AR

                            When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups