PDA

View Full Version : Solved: independents from system separators



white_flag
11-23-2010, 08:27 AM
Question
- Is there a way to change the decimal separator of VBA?
I use an textbox for entering the data (numeric). and 0.25 become 25
Wen I insert 0,25 I have 0,25 but I have an error on formula. Excel use "," as separator and I receive an error that formula is wrong.

the code


For i = 1 To 5
If Me.Controls("CheckBox" & i) = True Then
If Me.Controls("TextBox" & i + 15).Text = vbNullString Then Me.Controls("TextBox" & i + 15).Text = 0
If Me.Controls("Label" & i + 38).Caption = vbNullString Or Not IsNumeric(Me.Controls("Label" & i + 38)) Then Me.Controls("Label" & i + 38).Caption = 0
'Formula_A = Formula_A + CDbl(Application.Evaluate((Me.Controls("TextBox" & i + 15).Text) & "*(1+" & (Me.Controls("TextBox" & i + 5).Text) & "/100)"))
Me.Controls("Label" & i + 38).Caption = CDbl(Application.Evaluate(Me.Controls("TextBox" & i + 15).Text & "*(1+" & Me.Controls("TextBox" & i + 5).Text & "/100)"))

End If
Next

after that the VBA has the following formula:


.FormulaR1C1 = "=" _
& .FormulaR1C1 & "*" & Formula_A _ 'here if the value from Formula_A solved in previews code is 3,25 I have an error
& "+" & Formula_B _
& "+" & .FormulaR1C1 & "*" & "r" & rTopLeft.Row & "c/1000" & "*" & Formula_C _

how can I become somehow independent from system separators? because wen I try Tools--International-- I have almost the same errors
wen I try replace function ..sometime it is going sometime not

Any help is highly appreciated.

white_flag
11-23-2010, 09:04 AM
In the end I putted like this:


For i = 1 To 5
If Me.Controls("CheckBox" & i) = True Then
If Me.Controls("TextBox" & i + 15).Text = vbNullString Then Me.Controls("TextBox" & i + 15).Text = 0
If Me.Controls("Label" & i + 38).Caption = vbNullString Or Not IsNumeric(Me.Controls("Label" & i + 38)) Then Me.Controls("Label" & i + 38).Caption = 0
Formula_A = Formula_A + CDbl(Replace(Application.Evaluate((Me.Controls("TextBox" & i + 15).Text) & "*(1+" & (Me.Controls("TextBox" & i + 5).Text) & "/100)")), "." , ","))
Me.Controls("Label" & i + 38).Caption = CDbl(Application.Evaluate(Me.Controls("TextBox" & i + 15).Text & "*(1+" & Me.Controls("TextBox" & i + 5).Text & "/100)"))

End If
Next

and

.FormulaR1C1 = "=" _
& .FormulaR1C1 & "*" & Replace(Formula_A, ",", ".") _
& "+" & Replace(Formula_B, ",", ".") _
& "+" & .FormulaR1C1 & "*" & "r" & rTopLeft.Row & "c/1000" & "*" & Replace(Formula_C, ",", ".") _