Hi all, again me
How to use the Replace function at the array of controls (the array TextBoxes)?
thanks in advance
Printable View
Hi all, again me
How to use the Replace function at the array of controls (the array TextBoxes)?
thanks in advance
You'll have to be more clear. Do you want to use the Replace function on the text of each textbox in the array?
With a simple loop:Code:Dim N As Long
For N = 0 To (Text1.Count - 1)
Text1(N).Text = Replace$(Text1(N).Text, "to replace", "replace with")
Next N
thanks for replies
@Logophobic:
Yes, exactly. The sign of comma in my Country it's using as separate at decimals. And because I want to use the function Val then I have to exchange for calculations the sign of comma on sign the dot.
tamgovb
I believe Format is a locale-aware (= it knows your language) function. Try this without Replace.
MsgBox Format(MyTextBoxValue, "#####.##")
OK, OK Martin
I want to use function Val in my programme, So….all users would have probably to alter settings, is not it?
My programme will not be probably such attractive then as I would want this? What about this you think Martin?
I greet tamgovb
The simplest you could do is is to use Val and Replace comma with dot before using it. Like: Value = Val(Replace(Text1(Index).Text, ",", "."))
Hi Merri
to get to know you pleasantly.
I write unfortunately therefore that this doesn't want me to work.
i greet tamgovb
Please show your code that includes the Replace.
obviously!!!
What about something like:
So an example could be from 33.333,25 = 33333.25Code:Private Sub Command1_Click()
Dim Index As Integer
Label1.Caption = _
Val(Replace(Replace( _
(Replace(Text1(Index).Text, ",", "|") _
), ".", "") _
, "|", "."))
End Sub
Is that what you're looking for?
sorry malik641 but still works only Text1 (0).text
I meant the return value for Val() in your procedure. Because in your original procedure if you have 33.333,25 you would end up with 33.333 and I thought you might want something different.
Anyways, for the rest of your question I would just go with gavio's suggestion:
Code:Private Sub Command1_Click()
Dim Index As Integer
For Index = 0 To (Text1.Count - 1)
Text1(Index).Text = _
Val(Replace(Replace( _
(Replace(Text1(Index).Text, ",", "|") _
), ".", "") _
, "|", "."))
Next Index
End Sub
Forgot to mention it will change the values in the text boxes instead of labels
Do you need to use Val? You may be able to use CDbl instead, but you'll need to make sure the string is numeric first.
As a function: (Returns 0 if not numeric)Code:If IsNumeric(Text1.Text) Then
dblValue = CDbl(Text1.Text)
Else
dblValue = 0
End If
Code:Public Function MyVal(Number As String) As Double
If IsNumeric(Number) Then MyVal = CDbl(Number)
End Function
Does malik641's answer work for you?