-
Oct 25th, 2009, 09:23 AM
#1
Thread Starter
Member
[RESOLVED] I can't sum demical numbers...(vb6)
hi guys!
i have put this code in my project.
Code:
Private Sub Command1_Click()
Form1.Textx = Val(Form1.Textx) + Val(Form2.Textz)
End Sub
i cant sum demical numbers but only integer numbers...
What am i doing wrong? Could u tell me pleaze?!
-
Oct 25th, 2009, 09:54 AM
#2
Member
Re: I can't sum demical numbers...(vb6)
The problem might be with the definition of the textx and textz properties.
What are they?
Peter Schoots
-
Oct 25th, 2009, 10:10 AM
#3
Thread Starter
Member
Re: I can't sum demical numbers...(vb6)
Originally Posted by Peter Schoots
The problem might be with the definition of the textx and textz properties.
What are they?
Peter Schoots
Just simple text boxes!i didn't do anything with their properties...
-
Oct 25th, 2009, 10:25 AM
#4
Member
Re: I can't sum demical numbers...(vb6)
Text1.Text = Val(Text1) + Val(Text2)
Textx and textz being textboxes it should work if the strings have decimal points in it. I tried the above statement which works. What are the values in the textz and textx boxes?
-
Oct 25th, 2009, 10:39 AM
#5
Re: I can't sum demical numbers...(vb6)
Originally Posted by Sup3r
hi guys!
i have put this code in my project.
Code:
Private Sub Command1_Click()
Form1.Textx = Val(Form1.Textx) + Val(Form2.Textz)
End Sub
i cant sum demical numbers but only integer numbers...
What am i doing wrong? Could u tell me pleaze?!
Caution! Try this code in Immedate window:
Code:
?Val("123,4")
123
?Val("123.4")
123,4
?Val("123,4") + Val("123,4")
246
?Val("123.4") + Val("123.4")
246,8
-
Oct 25th, 2009, 10:43 AM
#6
Re: I can't sum demical numbers...(vb6)
Try this
vb Code:
Private Sub Command1_Click() Form1.Textx = CDbl(Val(Form1.Textx)) + CDbl(Val(Form2.Textz)) End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 25th, 2009, 11:09 AM
#7
Re: I can't sum demical numbers...(vb6)
Originally Posted by koolsid
vb Code:
Private Sub Command1_Click()
Form1.Textx = CDbl(Val(Form1.Textx)) + CDbl(Val(Form2.Textz))
End Sub
Same thing, same result:
Code:
?Val("123.4") + Val("123.4")
246,8
?CDbl(Val("123.4")) + CDbl(Val("123.4"))
246,8
?Val("123,4") + Val("123,4")
246
?CDbl(Val("123,4")) + CDbl(Val("123,4"))
246
-
Oct 25th, 2009, 11:17 AM
#8
New Member
Re: I can't sum demical numbers...(vb6)
You can use the following function that makes use of CDbl and you solve the problem in all forms. Remember to write the Text (Form2.Textz.Text) property.
Code:
Option Explicit
'----------------------------------
Public Function Ctr(strTesto As String) As Double
On Error Resume Next
If IsNumeric(strTesto) = True Then
Ctr = CDbl((strTesto))
Else: Ctr = 0
End If
End Function
'----------------------------------
Sub Command1_Click()
Form1.Textx.Text = Ctr(Form1.Textx.Text) + Ctr(Form2.Textz.Text)
End Sub
-
Oct 25th, 2009, 11:20 AM
#9
Thread Starter
Member
Re: I can't sum demical numbers...(vb6)
Still nothing... I am not confused with (,) or (.) and this code
Code:
Form1.Textx = CDbl(Val(Form1.Textx)) + CDbl(Val(Form2.Textz))
sums correct only the first time that i am putting a demical number in the textbox! Then the result is not right! ;/
Any other ideas?
-
Oct 25th, 2009, 11:29 AM
#10
-
Oct 25th, 2009, 11:33 AM
#11
Thread Starter
Member
Re: I can't sum demical numbers...(vb6)
Originally Posted by LouisItaly
You can use the following function that makes use of CDbl and you solve the problem in all forms. Remember to write the Text (Form2.Textz.Text) property.
Code:
Option Explicit
'----------------------------------
Public Function Ctr(strTesto As String) As Double
On Error Resume Next
If IsNumeric(strTesto) = True Then
Ctr = CDbl((strTesto))
Else: Ctr = 0
End If
End Function
'----------------------------------
Sub Command1_Click()
Form1.Textx.Text = Ctr(Form1.Textx.Text) + Ctr(Form2.Textz.Text)
End Sub
LouisItaly that is working perfect but i have not enable the (,) button in the text box... The user can type only the (.) button for demical point...and this is not working with (.) button! Can u make your magics pleaze??? hahahaha!
-
Oct 25th, 2009, 11:36 AM
#12
Thread Starter
Member
Re: I can't sum demical numbers...(vb6)
Originally Posted by koolsid
Works for me...
I have 2 forms in my project.Thats maybe why is not working to my project.
-
Oct 25th, 2009, 11:38 AM
#13
Re: I can't sum demical numbers...(vb6)
Can u upload u r project?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 25th, 2009, 11:43 AM
#14
Member
Re: I can't sum demical numbers...(vb6)
I don't think you need dbl(val(textx.text)). dbl(textx.text) will do.
-
Oct 25th, 2009, 11:44 AM
#15
Thread Starter
Member
Re: I can't sum demical numbers...(vb6)
Originally Posted by koolsid
Can u upload u r project?
Sure! here it is!
http://rapidshare.com/files/29775960..._____.rar.html
Check it out!
-
Oct 25th, 2009, 11:51 AM
#16
Re: I can't sum demical numbers...(vb6)
The link tells me
This file can only be downloaded by becoming a Premium member.
There are no more download slots available for free users right now. If you don't want to become a premium member, you might want to try again later.
Can you upload a zip file or mail it to me?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 25th, 2009, 12:20 PM
#17
Thread Starter
Member
Re: I can't sum demical numbers...(vb6)
Originally Posted by koolsid
The link tells me
This file can only be downloaded by becoming a Premium member.
There are no more download slots available for free users right now. If you don't want to become a premium member, you might want to try again later.
Can you upload a zip file or mail it to me?
Sorry in my panic i forgot that i have a rapidshare premium account...
Here it is again...
http://rapidshare.com/files/29777216...__________.rar
Thanks a lot!!!
-
Oct 25th, 2009, 12:23 PM
#18
Re: I can't sum demical numbers...(vb6)
Seems like you panicked again....
I am getting the same message again...
I have pm'd you my email address. you can mail it to me...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 25th, 2009, 01:20 PM
#19
Re: I can't sum demical numbers...(vb6)
As discussed the problem is not the code but the regional settings... the decimal was not being recognized since you had Greece setting on.... Change it to English US from "Regional and language Options" and it will work fine.... as we tested it...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 25th, 2009, 02:25 PM
#20
Re: [RESOLVED] I can't sum demical numbers...(vb6)
You can do some tricks to make your application to be compatible with any regional settings. The only thing you have to do is replace the commas.
vb Code:
Dim A As String, B As String, D As Double Dim sFormatComma As String A = "10,0006" B = "2.345" sFormatComma = Left$(Format$(CStr(1 / 2), ".0"), 1) 'lets see what the Format$ will gives you for the decimal sign If sFormatComma = "," Then 'convert comma to dot A = Replace$(A, ",", ".") B = Replace$(B, ",", ".") End If D = val(A) + val(B) Debug.Print D
There might be other ways to do this, but it is definitely does the job.
Last edited by Jim Davis; Oct 25th, 2009 at 02:31 PM.
-
Oct 25th, 2009, 04:21 PM
#21
Thread Starter
Member
Re: [RESOLVED] I can't sum demical numbers...(vb6)
Originally Posted by Jim Davis
You can do some tricks to make your application to be compatible with any regional settings. The only thing you have to do is replace the commas.
vb Code:
Dim A As String, B As String, D As Double
Dim sFormatComma As String
A = "10,0006"
B = "2.345"
sFormatComma = Left$(Format$(CStr(1 / 2), ".0"), 1) 'lets see what the Format$ will gives you for the decimal sign
If sFormatComma = "," Then
'convert comma to dot
A = Replace$(A, ",", ".")
B = Replace$(B, ",", ".")
End If
D = val(A) + val(B)
Debug.Print D
There might be other ways to do this, but it is definitely does the job.
Thank u too Jim Davis! I 'll keep that to my mind!
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
|