Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default bad data when i change string to double

I created macro in excel and i have problem. I created buttons with
numbers(like in windows calculator) and when i add two integer numbers
everything is ok but when i add two fractions i have bad result. I think
problem is when i change string to double(becouse when i add point i use
string).
thanks Pawel
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default bad data when i change string to double

Post some code...
--
HTH...

Jim Thomlinson


" wrote:

I created macro in excel and i have problem. I created buttons with
numbers(like in windows calculator) and when i add two integer numbers
everything is ok but when i add two fractions i have bad result. I think
problem is when i change string to double(becouse when i add point i use
string).
thanks Pawel

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default bad data when i change string to double


first form:

Public mpl As Double

Private Sub dodawanie_Click()
If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty And liczba2 < Empty Then

Dim b, a As Double
a = CSng(liczba1)
b = CSng(liczba2)

wynik = a + b

End If
End Sub

Public Sub odejmowanie_Click()
If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty And liczba2 < Empty Then
Dim a, b As Double
a = CSng(liczba1)
b = CSng(liczba2)

wynik = a - b

End If
End Sub

Private Sub mnozenie_Click()
If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty And liczba2 < Empty Then
Dim a, b As Double
a = CSng(liczba1)
b = CSng(liczba2)

wynik = a * b

End If

End Sub

Private Sub dzielenie_Click()

If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty And liczba2 < Empty Then

Dim a, b As Double
a = CSng(liczba1)
b = CSng(liczba2)

If b = 0 Then
x = MsgBox("nie dzielimy przez 0", vbCritical + vbOKOnly,
"DEBILU!!!")
End If

If b < 0 Then
wynik = a / b
End If
End If
End Sub

Private Sub sin_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty Then
Dim a As Double
a = CSng(liczba1)

wynik = Math.sin(a)
End If

End Sub

Private Sub cos_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty Then
Dim a As Double
a = CSng(liczba1)

wynik = Math.cos(a)

End If
End Sub

Private Sub tan_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
Dim a As Double
a = CSng(liczba1)

wynik = Math.tan(a)
End If
End Sub


Private Sub ctg_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
Dim a As Double
a = CSng(liczba1)

wynik = 1 / Math.tan(a)
End If
End Sub


Private Sub CommandButton1_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
liczba1 = liczba1 * (-1)
End If
End Sub

Private Sub CommandButton2_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
Dim a As Double
a = CSng(liczba1)
If a <= 0 Then
x = MsgBox("nie pierwiastkujemy liczb mniejszych od 0", vbCritical +
vbOKOnly, "DEBILU!!!")
End If
If a 0 Then
wynik = Sqr(a)
End If
End If
End Sub

Private Sub cyferki1_Click()

cyferki.Show

End Sub

Private Sub na16_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
Dim a As Double, b As String

a = CSng(liczba1)

b = Conversion.Hex(a)

wynik = b
End If
End Sub


Private Sub silnia_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
Dim a As Double
Dim b As Double
a = CSng(liczba1)
b = 1
If a < 0 Then
x = MsgBox("nie ma silni z liczb mniejszych od 0", vbCritical +
vbOKOnly, "DEBILU!!!")
End If
If a = 0 And a <= 170 Then

For x = 1 To a

b = b * x

Next x
End If

If a 170 Then
x = MsgBox("nie policze silni z wiekszej liczby niz 170",
vbCritical + vbOKOnly, "SORRY!!!")
End If
wynik = b
End If
End Sub

Sub Mplus_Click()
If wynik = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If wynik < Empty Then
mpl = wynik
End If
End Sub

Private Sub Mr_Click()
Dim a As Double
a = Val(mpl)
liczba1 = a

End Sub

Private Sub xdoy_Click()
If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty And liczba2 < Empty Then
Dim a, b As Double
a = CSng(liczba1)
b = CSng(liczba2)
On Error Resume Next
wynik = a ^ b

If wynik 1E+301 Then
x = MsgBox("za duza wartosc", vbCritical + vbOKOnly, "DUPA!!!")
End If

End If
End Sub


second form:

Private Sub C_Click()

UserForm1.liczba2 = Empty
UserForm1.liczba1 = Empty

End Sub

Private Sub CommandButton2_Click()
Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1

Dim CzyJest As Variant

CzyJest = InStr(d, ",")
If CzyJest = 0 Then

d = d & ","
Else
x = MsgBox("nie za duzo tych przecinkow?", vbCritical + vbOKOnly,
"COS PRZEGINASZ!!!")
End If

UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2

CzyJest = InStr(d, ",")
If CzyJest = 0 Then

d = d & ","
Else
x = MsgBox("nie za duzo tych przecinkow?", vbCritical + vbOKOnly,
"COS PRZEGINASZ!!!")
End If

UserForm1.liczba2 = d
End If
End Sub

Private Sub cztery_Click()

Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1
d = d & "4"


UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2
d = d & "4"

UserForm1.liczba2 = d
End If
End Sub

Private Sub dwa_Click()

Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1
d = d & "2"

UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2
d = d & "2"

UserForm1.liczba2 = d
End If
End Sub

Private Sub dziesiec_Click()

Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1
d = d & "0"

UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2
d = d & "0"

UserForm1.liczba2 = d
End If
End Sub

Private Sub dziewiec_Click()

Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1
d = d & "9"


UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2
d = d & "9"

UserForm1.liczba2 = d
End If
End Sub

Private Sub jeden_Click()


Dim d As String
Dim a As Double
If wyb1 = True Then
d = UserForm1.liczba1
d = d & "1"

UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2
d = d & "1"

UserForm1.liczba2 = d
End If
End Sub


Private Sub osiem_Click()

Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1
d = d & "8"

UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2
d = d & "8"

UserForm1.liczba2 = d
End If
End Sub

Private Sub piec_Click()

Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1
d = d & "5"

UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2
d = d & "5"

UserForm1.liczba2 = d
End If
End Sub

Private Sub siedem_Click()

Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1
d = d & "7"

UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2
d = d & "7"

UserForm1.liczba2 = d
End If
End Sub

Private Sub szesc_Click()

Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1
d = d & "6"

UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2
d = d & "6"

UserForm1.liczba2 = d
End If
End Sub

Private Sub trzy_Click()

Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1
d = d & "3"

UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2
d = d & "3"

UserForm1.liczba2 = d
End If
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default bad data when i change string to double

Let me know how this goes...

Public mpl As Double

Private Sub dodawanie_Click()
Dim b as Double, a As Double 'otherwise b is variant

If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty And liczba2 < Empty Then

msgbox isnumeric(liczba1)
msgbox isnumeric(liczba2)
a = Cdbl(liczba1)
b = Cdbl(liczba2)

wynik = a + b

End If
End Sub

--
HTH...

Jim Thomlinson


" wrote:


first form:

Public mpl As Double

Private Sub dodawanie_Click()
If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty And liczba2 < Empty Then

Dim b, a As Double
a = CSng(liczba1)
b = CSng(liczba2)

wynik = a + b

End If
End Sub

Public Sub odejmowanie_Click()
If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty And liczba2 < Empty Then
Dim a, b As Double
a = CSng(liczba1)
b = CSng(liczba2)

wynik = a - b

End If
End Sub

Private Sub mnozenie_Click()
If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty And liczba2 < Empty Then
Dim a, b As Double
a = CSng(liczba1)
b = CSng(liczba2)

wynik = a * b

End If

End Sub

Private Sub dzielenie_Click()

If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty And liczba2 < Empty Then

Dim a, b As Double
a = CSng(liczba1)
b = CSng(liczba2)

If b = 0 Then
x = MsgBox("nie dzielimy przez 0", vbCritical + vbOKOnly,
"DEBILU!!!")
End If

If b < 0 Then
wynik = a / b
End If
End If
End Sub

Private Sub sin_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty Then
Dim a As Double
a = CSng(liczba1)

wynik = Math.sin(a)
End If

End Sub

Private Sub cos_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If

If liczba1 < Empty Then
Dim a As Double
a = CSng(liczba1)

wynik = Math.cos(a)

End If
End Sub

Private Sub tan_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
Dim a As Double
a = CSng(liczba1)

wynik = Math.tan(a)
End If
End Sub


Private Sub ctg_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
Dim a As Double
a = CSng(liczba1)

wynik = 1 / Math.tan(a)
End If
End Sub


Private Sub CommandButton1_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
liczba1 = liczba1 * (-1)
End If
End Sub

Private Sub CommandButton2_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
Dim a As Double
a = CSng(liczba1)
If a <= 0 Then
x = MsgBox("nie pierwiastkujemy liczb mniejszych od 0", vbCritical +
vbOKOnly, "DEBILU!!!")
End If
If a 0 Then
wynik = Sqr(a)
End If
End If
End Sub

Private Sub cyferki1_Click()

cyferki.Show

End Sub

Private Sub na16_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
Dim a As Double, b As String

a = CSng(liczba1)

b = Conversion.Hex(a)

wynik = b
End If
End Sub


Private Sub silnia_Click()
If liczba1 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty Then
Dim a As Double
Dim b As Double
a = CSng(liczba1)
b = 1
If a < 0 Then
x = MsgBox("nie ma silni z liczb mniejszych od 0", vbCritical +
vbOKOnly, "DEBILU!!!")
End If
If a = 0 And a <= 170 Then

For x = 1 To a

b = b * x

Next x
End If

If a 170 Then
x = MsgBox("nie policze silni z wiekszej liczby niz 170",
vbCritical + vbOKOnly, "SORRY!!!")
End If
wynik = b
End If
End Sub

Sub Mplus_Click()
If wynik = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If wynik < Empty Then
mpl = wynik
End If
End Sub

Private Sub Mr_Click()
Dim a As Double
a = Val(mpl)
liczba1 = a

End Sub

Private Sub xdoy_Click()
If liczba1 = Empty Or liczba2 = Empty Then
x = MsgBox("puste pole", vbCritical + vbOKOnly, "Uzupelnij!!!")
End If
If liczba1 < Empty And liczba2 < Empty Then
Dim a, b As Double
a = CSng(liczba1)
b = CSng(liczba2)
On Error Resume Next
wynik = a ^ b

If wynik 1E+301 Then
x = MsgBox("za duza wartosc", vbCritical + vbOKOnly, "DUPA!!!")
End If

End If
End Sub


second form:

Private Sub C_Click()

UserForm1.liczba2 = Empty
UserForm1.liczba1 = Empty

End Sub

Private Sub CommandButton2_Click()
Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1

Dim CzyJest As Variant

CzyJest = InStr(d, ",")
If CzyJest = 0 Then

d = d & ","
Else
x = MsgBox("nie za duzo tych przecinkow?", vbCritical + vbOKOnly,
"COS PRZEGINASZ!!!")
End If

UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2

CzyJest = InStr(d, ",")
If CzyJest = 0 Then

d = d & ","
Else
x = MsgBox("nie za duzo tych przecinkow?", vbCritical + vbOKOnly,
"COS PRZEGINASZ!!!")
End If

UserForm1.liczba2 = d
End If
End Sub

Private Sub cztery_Click()

Dim d As String
Dim a As Double

If wyb1 = True Then
d = UserForm1.liczba1
d = d & "4"


UserForm1.liczba1 = d
End If
If wyb2 = True Then
d = UserForm1.liczba2

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
dot / comma and string to double conversion snaggy^^ Excel Programming 2 January 30th 06 07:56 PM
VBA - find double quote (") in string Brassman[_3_] Excel Programming 1 August 19th 04 04:15 PM
Searching for double quote in a string Jeff Harbin[_4_] Excel Programming 2 August 6th 04 04:00 PM
Convert an empty string to a double Adrian T Excel Programming 3 June 7th 04 11:24 PM
Formatting Problem on Double-Zero String Tom Ogilvy Excel Programming 1 July 18th 03 06:56 PM


All times are GMT +1. The time now is 03:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"