[RESOLVED] I want only 1 "," in a row of numbers
Hi, i am making a caculater, and 1 of the buttons you can click is one with the
"," for broken numbers. What I want is that you can only add 1 "," in a row of
numbers. So I am looking for a code, that looks if there is already a "," in the
row of numbers in the textbox add that moment. If it is, DON'T add a "," again.
Re: I want only 1 "," in a row of numbers
srry, i meant "AT that moment" :-)
Re: I want only 1 "," in a row of numbers
Hai,
What about this piece of code?
[vbcode]
Private Sub Command1_Click()
Dim strnumrow As String
Dim rslt As Integer
strnumrow = "1232,1213"
rslt = InStr(1, strnumrow, ",")
If rslt > 0 Then
MsgBox "found"
Else
MsgBox "not found"
End If
End Sub
[/vbcode]
Re: I want only 1 "," in a row of numbers
euhm... strnumrow = "1232,1213"
is that for al kind of lengts? because here are 8 numerbers and in the middle
a ",". It does also work for 233233224,56 and 34,34343443 ect. ?
Re: I want only 1 "," in a row of numbers
If you look two lines up, "strnumrow" in this example is just a string variable, not some kind of special VB command or anything. The InStr() function will tell you if one string is in another string. As shown by Fazi, if "," is in strnumrow, the function will return non-zero. I believe the function returns the position it finds the string. So using InStr(), you can see if it exists in the string before adding it.
Re: I want only 1 "," in a row of numbers
[QUOTE=///Jeffrey\\\It does also work for 233233224,56 and 34,34343443 ect. ?[/QUOTE]
No problem !!
Re: [RESOLVED] I want only 1 "," in a row of numbers