How do I convert a string to a decimal digit?

  • Thread starter Guus van Waardenburg
  • Start date
G

Guus van Waardenburg

Good day,

I have two Userforms.

You can see the first one as the parentform so to speak and the second one
as the subform.

Now what I want to do when I'm finished with te subform is: sum up a digit
in the subform with a digit on the parentform and then replace the last digit
with the outcome. But when I try this with a simple 'formula' like:
Dim i As Double
i = frmParent.lblTotal.Caption + lblPremium.Caption
frmParent.lblTotal.Caption = i

VBA treats my outcome as a string. This means that when the caption was 100
and de new outcome would be 10 then it doesn't say 110 but 10010!!!

Now I know I have to use something like i = CDbl(frmParent.lblTotal.Caption
+ etc.

But I cant get it to work, can somebody help???
 
G

Greg Maxey

Try something like:

Sub Test()
Dim ptest1 As String
Dim ptest2 As String
Dim i As Long
ptest1 = 100
ptest2 = 10
i = CDbl(ptest1) + CDbl(ptest2)
MsgBox i
End Sub
 
G

Guus van Waardenburg

Yes! Thanks Greg,

Apart from some minor changes this worked great!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top