Results 1 to 9 of 9

Thread: Separate a label caption using a period as the separator?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Separate a label caption using a period as the separator?

    Hi there! I am working on a prog to teach kids about money (dollars and cents). I have a lbl called TotalLBL

    Is there a way to separate the caption, and put the left side (dollars) into DollarLBL and right of the decennial will be CentsLBL.

    Any help would be greatly appreciated!

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Separate a label caption using a period as the separator?

    Pretty basic stuff:

    1) Use InStr() to find the decimal, then Left & Mid to separate
    2) Use Split()
    3) Use math if the value is in a numeric data type:
    Dollars = Int(Money)
    Cents= CLng((Money - Int(Money)) * 100)
    Last edited by LaVolpe; Jan 3rd, 2016 at 04:38 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Separate a label caption using a period as the separator?

    Thank you!

    So I got this set up so it takes the left side (dollar side) off from the decimal.

    The only thing I want to fix is, it takes off the decimal too.

    Example

    'Now get the decimal cut off and get the dollar amount
    Dim iPos2 As Integer
    iPos2 = InStr(Checkout.TotalLBL.Caption, ".")
    If iPos2 Then

    Checkout.DollarsLBL.Caption = Left$(Checkout.TotalLBL.Caption, iPos2)
    Else
    ' no . , what to do now?
    End If

    in this case if the decimal was 2.75, the code would put 2. in the DollarLBL. I would like to just have the number with no decimal after it. Did I miss something? : )


    EDIT

    If I put - 1 after the iPos2, that so far seems to take care of the decimal, leaving me with only the dollar number, but are there any problems that could come from doing that?
    Last edited by Justin M; Jan 3rd, 2016 at 03:58 PM.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Separate a label caption using a period as the separator?

    No problems except if the region settings do not use a decimal for the cents. Some languages use a comma instead.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Separate a label caption using a period as the separator?

    What if I put an if statement to search the caption for a comma and replace it with a period before separating it?

    I know in the states and possibly other places they use commas to denote the thousands, but it my prob we will be lucky to go over $10.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Separate a label caption using a period as the separator?

    I think the best answer is not to use a string value, rather use a Currency variable for money. You can display the currency value in the label using the Format() function.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Separate a label caption using a period as the separator?

    Ok that sounds great!

    TotalLBL.Caption = Format$(TotalLBL.caption, "Currency")

    Would that always use a period for a decimal or would that be dependent of what country they are from?

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Separate a label caption using a period as the separator?

    Dependent on the regional settings. You can use math to separate the whole number from the fraction. You could also use the FormatCurrency() function. It will also display the correct symbol for money based on the regional settings and has a couple more options
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Separate a label caption using a period as the separator?

    I will sleep easier if you change your naming conventions -
    lblTotal
    lblDollar
    lblCents

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width