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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Listbox help

Listbox help

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 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.
  • N Offline
    N Offline
    NewHSKid
    wrote on last edited by
    #1

    Hi all, I posted this a couple days ago but didn't get any response. Thought i would try to post it again and see if someone could help. Wanted to know if it is possible to both pad a hex numbers with leading 0's and also format the width of the message. I have a string and i just concat a hex number to it. I just want to space out the numbers so that they will line up with the next string added, so that it has the look of a table. Right now i am padding the hex number like this:

    int myString = 10005;
    int myString2 = 20003;
    testStr.Format("%03X" , myString);
    Str += testStr;
    testStr.Format("%03X" , myString2);
    Str += testStr;
    Listbox.AddString(Str);
    

    I know if i take away the 0, then it will set the width, but i need to do both. CAN THIS BE DONE? thanks in advance. Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

    J S 2 Replies Last reply
    0
    • N NewHSKid

      Hi all, I posted this a couple days ago but didn't get any response. Thought i would try to post it again and see if someone could help. Wanted to know if it is possible to both pad a hex numbers with leading 0's and also format the width of the message. I have a string and i just concat a hex number to it. I just want to space out the numbers so that they will line up with the next string added, so that it has the look of a table. Right now i am padding the hex number like this:

      int myString = 10005;
      int myString2 = 20003;
      testStr.Format("%03X" , myString);
      Str += testStr;
      testStr.Format("%03X" , myString2);
      Str += testStr;
      Listbox.AddString(Str);
      

      I know if i take away the 0, then it will set the width, but i need to do both. CAN THIS BE DONE? thanks in advance. Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      NewHSKid wrote: Wanted to know if it is possible to both pad a hex numbers with leading 0's and also format the width of the message. Sure: You know the width of your column, the length of your hex number, and the difference of both is the number of leading '0' you have to prepend.


      Who is 'General Failure'? And why is he reading my harddisk?!?

      1 Reply Last reply
      0
      • N NewHSKid

        Hi all, I posted this a couple days ago but didn't get any response. Thought i would try to post it again and see if someone could help. Wanted to know if it is possible to both pad a hex numbers with leading 0's and also format the width of the message. I have a string and i just concat a hex number to it. I just want to space out the numbers so that they will line up with the next string added, so that it has the look of a table. Right now i am padding the hex number like this:

        int myString = 10005;
        int myString2 = 20003;
        testStr.Format("%03X" , myString);
        Str += testStr;
        testStr.Format("%03X" , myString2);
        Str += testStr;
        Listbox.AddString(Str);
        

        I know if i take away the 0, then it will set the width, but i need to do both. CAN THIS BE DONE? thanks in advance. Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

        S Offline
        S Offline
        Steve S
        wrote on last edited by
        #3

        You could do it in two stages, format the hex value, then take that as further input to another Format call, using %8.8s (pad on right) or %-8.8s (pad on left) as the format string second time around eg testStr1.Format("%03X",myString); testStr2.Format("%03X",myString2); Str.Format("%10.10s%10.10s",testStr1,testStr2); Steve S I was 15 once. It was a long time ago. Today, it's 22 years since I started working full-time in IT.

        S 1 Reply Last reply
        0
        • S Steve S

          You could do it in two stages, format the hex value, then take that as further input to another Format call, using %8.8s (pad on right) or %-8.8s (pad on left) as the format string second time around eg testStr1.Format("%03X",myString); testStr2.Format("%03X",myString2); Str.Format("%10.10s%10.10s",testStr1,testStr2); Steve S I was 15 once. It was a long time ago. Today, it's 22 years since I started working full-time in IT.

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          and, (haven't used Format or printf for a while...) you can specify the field width as an argument itself, like this; testStr.Format("%0*X", n, myString) where n is the number of digits you want. Steve S

          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