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. Doubles to Strings for Edit Box Output

Doubles to Strings for Edit Box Output

Scheduled Pinned Locked Moved C / C++ / MFC
helpgame-devdata-structurescryptographyquestion
16 Posts 3 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.
  • B Offline
    B Offline
    Brent Lamborn
    wrote on last edited by
    #1

    I'm writing a graphing program that draws x- and y- axis in a picture box and I want to label some of the hash marks. I cheated a little and used read only edit controls for the labels. My problem is this - I need to convert the array of labels (doubles) to an array of strings so that I can send them to the edit controls for display in the picture box. I've tried the CString.Format function and ToString function and even _gcvt but I can't seem to get any of them to do what I want. Can anyone help? Here my button click event that is supposed to handle this: void CGraphView::OnBnClickedBtnplot() { double* Labels; GetDlgItem(IDC_PICT)->GetWindowRect(pictRect); ScreenToClient(pictRect); //Labels [1 - 26] (one for each hash mark) //Don't use all of them though Labels = GetLabelVals(); SetDlgItemText(IDC_EDITINTERSECT, "INT"); SetDlgItemText(IDC_EDITX1, str); SetDlgItemText(IDC_EDITX2, "x2"); SetDlgItemText(IDC_EDITX3, "x3"); SetDlgItemText(IDC_EDITX4, "x4"); SetDlgItemText(IDC_EDITX5, "x5"); SetDlgItemText(IDC_EDITY1, "y1"); SetDlgItemText(IDC_EDITY2, "y2"); SetDlgItemText(IDC_EDITY3, "y3"); InvalidateRect(pictRect); } Instead of the "x1...y3" I want the label strings to go in. Any help would be appreciated! "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

    G T 2 Replies Last reply
    0
    • B Brent Lamborn

      I'm writing a graphing program that draws x- and y- axis in a picture box and I want to label some of the hash marks. I cheated a little and used read only edit controls for the labels. My problem is this - I need to convert the array of labels (doubles) to an array of strings so that I can send them to the edit controls for display in the picture box. I've tried the CString.Format function and ToString function and even _gcvt but I can't seem to get any of them to do what I want. Can anyone help? Here my button click event that is supposed to handle this: void CGraphView::OnBnClickedBtnplot() { double* Labels; GetDlgItem(IDC_PICT)->GetWindowRect(pictRect); ScreenToClient(pictRect); //Labels [1 - 26] (one for each hash mark) //Don't use all of them though Labels = GetLabelVals(); SetDlgItemText(IDC_EDITINTERSECT, "INT"); SetDlgItemText(IDC_EDITX1, str); SetDlgItemText(IDC_EDITX2, "x2"); SetDlgItemText(IDC_EDITX3, "x3"); SetDlgItemText(IDC_EDITX4, "x4"); SetDlgItemText(IDC_EDITX5, "x5"); SetDlgItemText(IDC_EDITY1, "y1"); SetDlgItemText(IDC_EDITY2, "y2"); SetDlgItemText(IDC_EDITY3, "y3"); InvalidateRect(pictRect); } Instead of the "x1...y3" I want the label strings to go in. Any help would be appreciated! "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

      G Offline
      G Offline
      Gary Kirkham
      wrote on last edited by
      #2

      Why doesn't CString.Format do what you want...it will give you a formatted string. If you want an array of strings then check out CStringArray. Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

      B 1 Reply Last reply
      0
      • G Gary Kirkham

        Why doesn't CString.Format do what you want...it will give you a formatted string. If you want an array of strings then check out CStringArray. Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

        B Offline
        B Offline
        Brent Lamborn
        wrote on last edited by
        #3

        Would it then look like this? void CGraphView::OnBnClickedBtnplot() { CStringArray strings; strings.SetSize(26); double* Labels; GetDlgItem(IDC_PICT)->GetWindowRect(pictRect); ScreenToClient(pictRect); //Labels [1 - 26] (one for each hash mark) //Don't use all of them though Labels = GetLabelVals(); strings[1].Format("%.3d\n", Labels[1]); SetDlgItemText(IDC_EDITINTERSECT, "INT"); SetDlgItemText(IDC_EDITX1, strings[1]); SetDlgItemText(IDC_EDITX2, "x2"); SetDlgItemText(IDC_EDITX3, "x3"); SetDlgItemText(IDC_EDITX4, "x4"); SetDlgItemText(IDC_EDITX5, "x5"); SetDlgItemText(IDC_EDITY1, "y1"); SetDlgItemText(IDC_EDITY2, "y2"); SetDlgItemText(IDC_EDITY3, "y3"); InvalidateRect(pictRect); } Am I using the .Format correctly? The output on the screen is not correct. If Labels[1] is 10.26356897 then I get something like -85478 or something like that in the edit control when i run it. Could you give me an example of what it would take for my output to look like this: 10.3 I don't have a lot of space in the picture box so the output needs to be rounded to have only one number after the decimal place. "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

        G 2 Replies Last reply
        0
        • B Brent Lamborn

          Would it then look like this? void CGraphView::OnBnClickedBtnplot() { CStringArray strings; strings.SetSize(26); double* Labels; GetDlgItem(IDC_PICT)->GetWindowRect(pictRect); ScreenToClient(pictRect); //Labels [1 - 26] (one for each hash mark) //Don't use all of them though Labels = GetLabelVals(); strings[1].Format("%.3d\n", Labels[1]); SetDlgItemText(IDC_EDITINTERSECT, "INT"); SetDlgItemText(IDC_EDITX1, strings[1]); SetDlgItemText(IDC_EDITX2, "x2"); SetDlgItemText(IDC_EDITX3, "x3"); SetDlgItemText(IDC_EDITX4, "x4"); SetDlgItemText(IDC_EDITX5, "x5"); SetDlgItemText(IDC_EDITY1, "y1"); SetDlgItemText(IDC_EDITY2, "y2"); SetDlgItemText(IDC_EDITY3, "y3"); InvalidateRect(pictRect); } Am I using the .Format correctly? The output on the screen is not correct. If Labels[1] is 10.26356897 then I get something like -85478 or something like that in the edit control when i run it. Could you give me an example of what it would take for my output to look like this: 10.3 I don't have a lot of space in the picture box so the output needs to be rounded to have only one number after the decimal place. "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

          G Offline
          G Offline
          Gary Kirkham
          wrote on last edited by
          #4

          student() wrote: Would it then look like this? Yes, however keep in mind that C arrays are 0 based...when you add a string to the CStringArray it will start at the 0 index. You can either handle it with the index or add a dummy string to the 0th location. student() wrote: Am I using the .Format correctly? No, change the d to an f Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

          B 1 Reply Last reply
          0
          • B Brent Lamborn

            Would it then look like this? void CGraphView::OnBnClickedBtnplot() { CStringArray strings; strings.SetSize(26); double* Labels; GetDlgItem(IDC_PICT)->GetWindowRect(pictRect); ScreenToClient(pictRect); //Labels [1 - 26] (one for each hash mark) //Don't use all of them though Labels = GetLabelVals(); strings[1].Format("%.3d\n", Labels[1]); SetDlgItemText(IDC_EDITINTERSECT, "INT"); SetDlgItemText(IDC_EDITX1, strings[1]); SetDlgItemText(IDC_EDITX2, "x2"); SetDlgItemText(IDC_EDITX3, "x3"); SetDlgItemText(IDC_EDITX4, "x4"); SetDlgItemText(IDC_EDITX5, "x5"); SetDlgItemText(IDC_EDITY1, "y1"); SetDlgItemText(IDC_EDITY2, "y2"); SetDlgItemText(IDC_EDITY3, "y3"); InvalidateRect(pictRect); } Am I using the .Format correctly? The output on the screen is not correct. If Labels[1] is 10.26356897 then I get something like -85478 or something like that in the edit control when i run it. Could you give me an example of what it would take for my output to look like this: 10.3 I don't have a lot of space in the picture box so the output needs to be rounded to have only one number after the decimal place. "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

            G Offline
            G Offline
            Gary Kirkham
            wrote on last edited by
            #5

            Disregard the first part of my last post...I didn't see that you had used SetSize. Since the array is zero based, in order to start at an index of 1 then you will need to make the array size one larger than the number of items you are storing. Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

            B 1 Reply Last reply
            0
            • G Gary Kirkham

              student() wrote: Would it then look like this? Yes, however keep in mind that C arrays are 0 based...when you add a string to the CStringArray it will start at the 0 index. You can either handle it with the index or add a dummy string to the 0th location. student() wrote: Am I using the .Format correctly? No, change the d to an f Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

              B Offline
              B Offline
              Brent Lamborn
              wrote on last edited by
              #6

              Alright! That worked perfectly! I REALLY appreciate the help. "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

              1 Reply Last reply
              0
              • G Gary Kirkham

                Disregard the first part of my last post...I didn't see that you had used SetSize. Since the array is zero based, in order to start at an index of 1 then you will need to make the array size one larger than the number of items you are storing. Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

                B Offline
                B Offline
                Brent Lamborn
                wrote on last edited by
                #7

                One last question.. Why will this work... strLabels[3].Format("%.2f\n", dblLabels[3]); But this won't?:wtf: for (int i = 1; i < 26; i++) strLabels[i].Format("%.2f\n", dblLabels[i]); "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

                G 1 Reply Last reply
                0
                • B Brent Lamborn

                  One last question.. Why will this work... strLabels[3].Format("%.2f\n", dblLabels[3]); But this won't?:wtf: for (int i = 1; i < 26; i++) strLabels[i].Format("%.2f\n", dblLabels[i]); "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

                  G Offline
                  G Offline
                  Gary Kirkham
                  wrote on last edited by
                  #8

                  I don't see anything wrong with what you posted. What does it do? Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

                  B 1 Reply Last reply
                  0
                  • G Gary Kirkham

                    I don't see anything wrong with what you posted. What does it do? Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

                    B Offline
                    B Offline
                    Brent Lamborn
                    wrote on last edited by
                    #9

                    The output on the screen shows -9255 for every string no matter what is in my dblLabels array when I use a for loop. If I put the literal index in it works but that would be too many lines of code. Heres the whole thing again just in case: void CGraphView::OnBnClickedBtnplot() { GetDlgItem(IDC_PICT)->GetWindowRect(pictRect); ScreenToClient(pictRect); //Array of label strings CStringArray strLabels; strLabels.SetSize(26); //Array of double labels [1-26] one for each has mark //Don't use all of them though double* dblLabels = GetLabelVals(); for (int i = 1; i < 26; i++) strLabels[i].Format("%.2f\n", dblLabels[i]); SetDlgItemText(IDC_EDITINTERSECT, "INT"); SetDlgItemText(IDC_EDITY1, strLabels[3]); SetDlgItemText(IDC_EDITY2, strLabels[6]); SetDlgItemText(IDC_EDITY3, strLabels[9]); SetDlgItemText(IDC_EDITX1, strLabels[12]); SetDlgItemText(IDC_EDITX2, strLabels[15]); SetDlgItemText(IDC_EDITX3, strLabels[18]); SetDlgItemText(IDC_EDITX4, strLabels[21]); SetDlgItemText(IDC_EDITX5, strLabels[24]); InvalidateRect(pictRect); } "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

                    G 3 Replies Last reply
                    0
                    • B Brent Lamborn

                      The output on the screen shows -9255 for every string no matter what is in my dblLabels array when I use a for loop. If I put the literal index in it works but that would be too many lines of code. Heres the whole thing again just in case: void CGraphView::OnBnClickedBtnplot() { GetDlgItem(IDC_PICT)->GetWindowRect(pictRect); ScreenToClient(pictRect); //Array of label strings CStringArray strLabels; strLabels.SetSize(26); //Array of double labels [1-26] one for each has mark //Don't use all of them though double* dblLabels = GetLabelVals(); for (int i = 1; i < 26; i++) strLabels[i].Format("%.2f\n", dblLabels[i]); SetDlgItemText(IDC_EDITINTERSECT, "INT"); SetDlgItemText(IDC_EDITY1, strLabels[3]); SetDlgItemText(IDC_EDITY2, strLabels[6]); SetDlgItemText(IDC_EDITY3, strLabels[9]); SetDlgItemText(IDC_EDITX1, strLabels[12]); SetDlgItemText(IDC_EDITX2, strLabels[15]); SetDlgItemText(IDC_EDITX3, strLabels[18]); SetDlgItemText(IDC_EDITX4, strLabels[21]); SetDlgItemText(IDC_EDITX5, strLabels[24]); InvalidateRect(pictRect); } "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

                      G Offline
                      G Offline
                      Gary Kirkham
                      wrote on last edited by
                      #10

                      Should work... Run it in debug mode and check each value set by this call student() wrote: double* dblLabels = GetLabelVals(); make sure each value in dblLabels is set properly. I ran the following on my machine at it worked perfectly

                      CStringArray strLabels;
                      strLabels.SetSize(26);
                      
                      double arr\[\] = { 0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
                      	             11, 12, 13, 14, 15, 16, 17, 18, 18, 20,
                      				 21, 22, 23, 26, 25 };
                      
                      
                      for (int i = 1; i < 26; i++)
                      {
                      	strLabels\[i\].Format("%.2f\\n", arr\[i\]);
                      	AfxMessageBox(strLabels\[i\]);
                      }
                      

                      Other than that I don't know what to tell you Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

                      B 1 Reply Last reply
                      0
                      • G Gary Kirkham

                        Should work... Run it in debug mode and check each value set by this call student() wrote: double* dblLabels = GetLabelVals(); make sure each value in dblLabels is set properly. I ran the following on my machine at it worked perfectly

                        CStringArray strLabels;
                        strLabels.SetSize(26);
                        
                        double arr\[\] = { 0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
                        	             11, 12, 13, 14, 15, 16, 17, 18, 18, 20,
                        				 21, 22, 23, 26, 25 };
                        
                        
                        for (int i = 1; i < 26; i++)
                        {
                        	strLabels\[i\].Format("%.2f\\n", arr\[i\]);
                        	AfxMessageBox(strLabels\[i\]);
                        }
                        

                        Other than that I don't know what to tell you Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

                        B Offline
                        B Offline
                        Brent Lamborn
                        wrote on last edited by
                        #11

                        Gary... Yeah something weird is going on. I ran it in the debugger and my dbl array is fine. The weird part is that after only one iteration of the for loop, all 26 of the values in the string array are set to -9255 plus about ten other numbers after that. I don't understand how one iteration could change all the values in the array. Anyway..Thanks for your help..I really appreciate it. "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

                        G 1 Reply Last reply
                        0
                        • B Brent Lamborn

                          Gary... Yeah something weird is going on. I ran it in the debugger and my dbl array is fine. The weird part is that after only one iteration of the for loop, all 26 of the values in the string array are set to -9255 plus about ten other numbers after that. I don't understand how one iteration could change all the values in the array. Anyway..Thanks for your help..I really appreciate it. "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

                          G Offline
                          G Offline
                          Gary Kirkham
                          wrote on last edited by
                          #12

                          Just for kicks, try using the CStringArray GetAt and SetAt functions instead of the [] operator. Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

                          1 Reply Last reply
                          0
                          • B Brent Lamborn

                            The output on the screen shows -9255 for every string no matter what is in my dblLabels array when I use a for loop. If I put the literal index in it works but that would be too many lines of code. Heres the whole thing again just in case: void CGraphView::OnBnClickedBtnplot() { GetDlgItem(IDC_PICT)->GetWindowRect(pictRect); ScreenToClient(pictRect); //Array of label strings CStringArray strLabels; strLabels.SetSize(26); //Array of double labels [1-26] one for each has mark //Don't use all of them though double* dblLabels = GetLabelVals(); for (int i = 1; i < 26; i++) strLabels[i].Format("%.2f\n", dblLabels[i]); SetDlgItemText(IDC_EDITINTERSECT, "INT"); SetDlgItemText(IDC_EDITY1, strLabels[3]); SetDlgItemText(IDC_EDITY2, strLabels[6]); SetDlgItemText(IDC_EDITY3, strLabels[9]); SetDlgItemText(IDC_EDITX1, strLabels[12]); SetDlgItemText(IDC_EDITX2, strLabels[15]); SetDlgItemText(IDC_EDITX3, strLabels[18]); SetDlgItemText(IDC_EDITX4, strLabels[21]); SetDlgItemText(IDC_EDITX5, strLabels[24]); InvalidateRect(pictRect); } "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

                            G Offline
                            G Offline
                            Gary Kirkham
                            wrote on last edited by
                            #13

                            You can also us a vector. Here is an example

                            vector strLabels;
                            strLabels.reserve(26);
                            CString string;
                            
                            strLabels.push\_back("");  // this takes care of index 0
                            
                            for (int i = 1; i < 26; i++)
                            {
                            	string.Format("%.2f\\n", dblLabels\[i\]);
                            	strLabels.push\_back(string);
                            }
                            

                            put this at the top of you cpp file #include using std::vector; Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

                            1 Reply Last reply
                            0
                            • B Brent Lamborn

                              The output on the screen shows -9255 for every string no matter what is in my dblLabels array when I use a for loop. If I put the literal index in it works but that would be too many lines of code. Heres the whole thing again just in case: void CGraphView::OnBnClickedBtnplot() { GetDlgItem(IDC_PICT)->GetWindowRect(pictRect); ScreenToClient(pictRect); //Array of label strings CStringArray strLabels; strLabels.SetSize(26); //Array of double labels [1-26] one for each has mark //Don't use all of them though double* dblLabels = GetLabelVals(); for (int i = 1; i < 26; i++) strLabels[i].Format("%.2f\n", dblLabels[i]); SetDlgItemText(IDC_EDITINTERSECT, "INT"); SetDlgItemText(IDC_EDITY1, strLabels[3]); SetDlgItemText(IDC_EDITY2, strLabels[6]); SetDlgItemText(IDC_EDITY3, strLabels[9]); SetDlgItemText(IDC_EDITX1, strLabels[12]); SetDlgItemText(IDC_EDITX2, strLabels[15]); SetDlgItemText(IDC_EDITX3, strLabels[18]); SetDlgItemText(IDC_EDITX4, strLabels[21]); SetDlgItemText(IDC_EDITX5, strLabels[24]); InvalidateRect(pictRect); } "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

                              G Offline
                              G Offline
                              Gary Kirkham
                              wrote on last edited by
                              #14

                              the first line of code sould look like this vector<CString>strLabels; I forgot the message software doesn't like the <> symbols Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

                              B 1 Reply Last reply
                              0
                              • B Brent Lamborn

                                I'm writing a graphing program that draws x- and y- axis in a picture box and I want to label some of the hash marks. I cheated a little and used read only edit controls for the labels. My problem is this - I need to convert the array of labels (doubles) to an array of strings so that I can send them to the edit controls for display in the picture box. I've tried the CString.Format function and ToString function and even _gcvt but I can't seem to get any of them to do what I want. Can anyone help? Here my button click event that is supposed to handle this: void CGraphView::OnBnClickedBtnplot() { double* Labels; GetDlgItem(IDC_PICT)->GetWindowRect(pictRect); ScreenToClient(pictRect); //Labels [1 - 26] (one for each hash mark) //Don't use all of them though Labels = GetLabelVals(); SetDlgItemText(IDC_EDITINTERSECT, "INT"); SetDlgItemText(IDC_EDITX1, str); SetDlgItemText(IDC_EDITX2, "x2"); SetDlgItemText(IDC_EDITX3, "x3"); SetDlgItemText(IDC_EDITX4, "x4"); SetDlgItemText(IDC_EDITX5, "x5"); SetDlgItemText(IDC_EDITY1, "y1"); SetDlgItemText(IDC_EDITY2, "y2"); SetDlgItemText(IDC_EDITY3, "y3"); InvalidateRect(pictRect); } Instead of the "x1...y3" I want the label strings to go in. Any help would be appreciated! "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

                                T Offline
                                T Offline
                                TomKat
                                wrote on last edited by
                                #15

                                #include #include char buf1[50]="",buf2[50]=""; DWORD x1=1923; float x2=0.5; sprintf(buf1,"%d",x1); sprintf(buf2,"%f",x2); x1=atol(buf1); x2=atof(buf2); quite simple ? right ! //be cool I am the mighty keeper of the book on knowledge . Contact me to get your copy .

                                1 Reply Last reply
                                0
                                • G Gary Kirkham

                                  the first line of code sould look like this vector<CString>strLabels; I forgot the message software doesn't like the <> symbols Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks

                                  B Offline
                                  B Offline
                                  Brent Lamborn
                                  wrote on last edited by
                                  #16

                                  Just thought I would let you know since you helped me so much... I didn't even need to convert to strings. I add some code to my GetLabelVals function and changed the name of it to SetLabels(). I didn't realize it before but you can attach a double variable to the edit controls then, I just set the var attached to each box using the corresponding element in my double array. Then to have it appear on the screen -- I call UpdateData(false). I knew I could get the value in the box with an attached variable but I just figured out that I can set it using a variable also, using the UpdateData(false) call. So much work just for that!! ...Brent "It has become appallingly obvious that our technology has exceeded our humanity." - Albert Einstein (1879-1955) "I think there is a world market for maybe five computers." - Thomas Watson (1874-1956), Chairman of IBM, 1943 "640K ought to be enough for anybody." - Bill Gates (1955-), in 1981 "Half this game is ninety percent mental." - Yogi Berra

                                  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