-
Jan 3rd, 2016, 01:37 PM
#1
Thread Starter
PowerPoster
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!
-
Jan 3rd, 2016, 01:43 PM
#2
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.
-
Jan 3rd, 2016, 03:40 PM
#3
Thread Starter
PowerPoster
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.
-
Jan 3rd, 2016, 04:02 PM
#4
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.
-
Jan 3rd, 2016, 04:05 PM
#5
Thread Starter
PowerPoster
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.
-
Jan 3rd, 2016, 04:07 PM
#6
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.
-
Jan 3rd, 2016, 04:12 PM
#7
Thread Starter
PowerPoster
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?
-
Jan 3rd, 2016, 04:16 PM
#8
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
-
Jan 4th, 2016, 05:12 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|