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 0 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 jharn

    Is that not an AND function? == I guess I am confused.....

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

    jharn wrote:

    Is that not an AND function? ==

    Uh, no. That is the equality operator. The two AND operators are bitwise (&) and logical (&&).

    "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 2 Replies Last reply
    0
    • D David Crow

      jharn wrote:

      in the part where I compare if (arg1 = a) it tells me expression must have a bool type.

      Right, you are confusing == with =.

      "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
      jharn
      wrote on last edited by
      #7

      Hi, I tried arg1==a, now it says that no operator "==" matches these operands.

      M 1 Reply Last reply
      0
      • D David Crow

        jharn wrote:

        Is that not an AND function? ==

        Uh, no. That is the equality operator. The two AND operators are bitwise (&) and logical (&&).

        "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
        jharn
        wrote on last edited by
        #8

        hahahaha......you are SO right, my apologies

        1 Reply Last reply
        0
        • D David Crow

          jharn wrote:

          Is that not an AND function? ==

          Uh, no. That is the equality operator. The two AND operators are bitwise (&) and logical (&&).

          "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
          jharn
          wrote on last edited by
          #9

          Hi, I tried arg1==a, now it says that no operator "==" matches these operands.

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

            N Offline
            N Offline
            Niklas L
            wrote on last edited by
            #10

            You declare your arrays to have 16 elements, but only initialize 15, then access the 17:th element.

            string vl_reg1[16] = { /* 15 strings */ };
            do{
            a = vl_reg1[counter];
            counter = counter + 1;
            } while (counter <= 16)

            It's a mess.

            home

            J 1 Reply Last reply
            0
            • N Niklas L

              You declare your arrays to have 16 elements, but only initialize 15, then access the 17:th element.

              string vl_reg1[16] = { /* 15 strings */ };
              do{
              a = vl_reg1[counter];
              counter = counter + 1;
              } while (counter <= 16)

              It's a mess.

              home

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

              OK, I see, sorry to bother, I know it usually is not much fun helping a newbie, but I really do appreciate your guidance.

              K 1 Reply Last reply
              0
              • J jharn

                Hi, I tried arg1==a, now it says that no operator "==" matches these operands.

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

                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 1 Reply Last reply
                0
                • J jharn

                  Hi, I tried arg1==a, now it says that no operator "==" matches these operands.

                  M Offline
                  M Offline
                  Matthew Barnett
                  wrote on last edited by
                  #13

                  I think you need to use the 'compare' method. It returns 0 if they're equal, a positive int the string is greater, or a negative int if the string is less. Therefore: if (arg1.compare(a) == 0)

                  1 Reply Last reply
                  0
                  • J jharn

                    OK, I see, sorry to bother, I know it usually is not much fun helping a newbie, but I really do appreciate your guidance.

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

                    First off, your code looks like it is supposed to be C++, I'm not an expert on this language. I'm going to assume it is something else because I don't see how this would compile. I agree with the assessment that the code is a mess no matter what language. The reason why you aren't blowing up with string vl_reg1[16] = {...} is because the variable is first defined with 16 values in an array and then the {} acts like you said vl_reg1 = new string[15] , followed by a loop that fills in 15 values into the new array. Like I said, I'm not an expert. That's what it looks like it is doing. As far as I know C++ doesn't have string as a field. The "new" is probably a mistake on my part because that works great in C#, but entails a huge amount of memory management headaches with C++. (Unless the .Net version of C++ fixes that problem as well.) Anyway in C# you can dynamically change the size of an array if you wish. In C# I would probably say string[] vl_reg1 = {...} I'm assuming your language supports ubounds(). From your error messages, maybe your language doesn't support "=="? Change your first while to }while (counter <= vl_reg1.ubounds(0)); In fact, change your whole do loop to: do{ a = vl_reg1[counter]; tp = counter++; }while (counter <= vl_reg1.ubounds(0) && arg1 != a); You don't have any error checking. Immediately after that execute if (arg1 != a) return -1.; You have return vl_reg3[bg][tp]; I don't understand how that would even compile. I know what you are trying to do, but this WON'T do it! (At least in any of the languages I know.) vl_reg3 is a string type single array. You are returning a double value from the routine. You can't change types. All of a sudden you are returning a double array setup from a single array string type. No, it won't automagically determine the string field vl_reg3[bg] needs to be converted to a double type array field and pass back that array's number from the tp location. (Which makes no sense either, but that's what it looks like you are trying to do. Forget the second loop it is total nonsense. vl_reg2 should be a pointer to the array values you want to use, so keep the numbering scheme you've put into it. These numbers should be a 1 to 1 correllation to the positions of the first argument found in vl_reg1. Set up a new double array. (call it, say "ret_vals") Instead of the second array, do some more error checking if (arg2 < 0) return -2.;// This could be the first line of the code if you want. if (tp > vl_reg1.ubounds(0)) return -

                    J 2 Replies 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]; }

                      S Offline
                      S Offline
                      Stuart Rubin
                      wrote on last edited by
                      #15

                      There have been many rookie errors pointed out by others, so I won't repeat them. There are a few general things that will help with your code: 1. Compile the code with the strictest warnings setting. The compiler will likely tell you about a lot of bugs, or potential bugs, lurking in the code. Do not use the code until there are no warnings. 2. Use a static code analyzer like Lint. It would have caught problems like your assign/compare bug. It will also offer many suggestions for cleaner code. See http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis[^] When you can compile code with no warnings, and get through Lint without much trouble, you are much less likely to have a real problem with your code. You'll be able to concentrate on the real meat of the code. Stuart

                      1 Reply Last reply
                      0
                      • K KP Lee

                        First off, your code looks like it is supposed to be C++, I'm not an expert on this language. I'm going to assume it is something else because I don't see how this would compile. I agree with the assessment that the code is a mess no matter what language. The reason why you aren't blowing up with string vl_reg1[16] = {...} is because the variable is first defined with 16 values in an array and then the {} acts like you said vl_reg1 = new string[15] , followed by a loop that fills in 15 values into the new array. Like I said, I'm not an expert. That's what it looks like it is doing. As far as I know C++ doesn't have string as a field. The "new" is probably a mistake on my part because that works great in C#, but entails a huge amount of memory management headaches with C++. (Unless the .Net version of C++ fixes that problem as well.) Anyway in C# you can dynamically change the size of an array if you wish. In C# I would probably say string[] vl_reg1 = {...} I'm assuming your language supports ubounds(). From your error messages, maybe your language doesn't support "=="? Change your first while to }while (counter <= vl_reg1.ubounds(0)); In fact, change your whole do loop to: do{ a = vl_reg1[counter]; tp = counter++; }while (counter <= vl_reg1.ubounds(0) && arg1 != a); You don't have any error checking. Immediately after that execute if (arg1 != a) return -1.; You have return vl_reg3[bg][tp]; I don't understand how that would even compile. I know what you are trying to do, but this WON'T do it! (At least in any of the languages I know.) vl_reg3 is a string type single array. You are returning a double value from the routine. You can't change types. All of a sudden you are returning a double array setup from a single array string type. No, it won't automagically determine the string field vl_reg3[bg] needs to be converted to a double type array field and pass back that array's number from the tp location. (Which makes no sense either, but that's what it looks like you are trying to do. Forget the second loop it is total nonsense. vl_reg2 should be a pointer to the array values you want to use, so keep the numbering scheme you've put into it. These numbers should be a 1 to 1 correllation to the positions of the first argument found in vl_reg1. Set up a new double array. (call it, say "ret_vals") Instead of the second array, do some more error checking if (arg2 < 0) return -2.;// This could be the first line of the code if you want. if (tp > vl_reg1.ubounds(0)) return -

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

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

                        1 Reply Last reply
                        0
                        • K KP Lee

                          First off, your code looks like it is supposed to be C++, I'm not an expert on this language. I'm going to assume it is something else because I don't see how this would compile. I agree with the assessment that the code is a mess no matter what language. The reason why you aren't blowing up with string vl_reg1[16] = {...} is because the variable is first defined with 16 values in an array and then the {} acts like you said vl_reg1 = new string[15] , followed by a loop that fills in 15 values into the new array. Like I said, I'm not an expert. That's what it looks like it is doing. As far as I know C++ doesn't have string as a field. The "new" is probably a mistake on my part because that works great in C#, but entails a huge amount of memory management headaches with C++. (Unless the .Net version of C++ fixes that problem as well.) Anyway in C# you can dynamically change the size of an array if you wish. In C# I would probably say string[] vl_reg1 = {...} I'm assuming your language supports ubounds(). From your error messages, maybe your language doesn't support "=="? Change your first while to }while (counter <= vl_reg1.ubounds(0)); In fact, change your whole do loop to: do{ a = vl_reg1[counter]; tp = counter++; }while (counter <= vl_reg1.ubounds(0) && arg1 != a); You don't have any error checking. Immediately after that execute if (arg1 != a) return -1.; You have return vl_reg3[bg][tp]; I don't understand how that would even compile. I know what you are trying to do, but this WON'T do it! (At least in any of the languages I know.) vl_reg3 is a string type single array. You are returning a double value from the routine. You can't change types. All of a sudden you are returning a double array setup from a single array string type. No, it won't automagically determine the string field vl_reg3[bg] needs to be converted to a double type array field and pass back that array's number from the tp location. (Which makes no sense either, but that's what it looks like you are trying to do. Forget the second loop it is total nonsense. vl_reg2 should be a pointer to the array values you want to use, so keep the numbering scheme you've put into it. These numbers should be a 1 to 1 correllation to the positions of the first argument found in vl_reg1. Set up a new double array. (call it, say "ret_vals") Instead of the second array, do some more error checking if (arg2 < 0) return -2.;// This could be the first line of the code if you want. if (tp > vl_reg1.ubounds(0)) return -

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

                          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 A 2 Replies 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]; }

                            T Offline
                            T Offline
                            thomas michaud
                            wrote on last edited by
                            #18

                            Silly question -- in whatever language your working in, is there no find command? If not, write one....you're doing the same action 3+ times. Take an value and an array and search through the array looking for the element. Return -1 if not found or the index value if it is found.

                            1 Reply Last reply
                            0
                            • 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
                                          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