Solved Delete unwanted characters in the TextBox Value

Hisoka

New member
Local time
Today, 19:04
Joined
Sep 20, 2023
Messages
17
Hello,
I have this code to open a conversation with customers on WhatsApp through the WhatsApp application,
Code:
CreateObject("Shell.Application").Open "https://wa.me/" & Me.tbMobNum & "/?text=" & Me.tbWaMessage

As you can see, I have the customer's number in the TextBox, But the number format in the control, like (+968)1111 1111,
But it must be like +96811111111 to work with the code above,
This means that I just want to delete the parentheses and the space in the middle

Maybe VBA Regex will do the trick, But I don't know how to use it, or is there a better way to implement this thing?

Thanks in advance
 
Solution
Following should serve:
Replace(Replace(Replace(Me.tbMobNum, " ", ""), "(", ""), ")", "")

I expect Regex could do it and if this gets more complicated, might want to or use VBA custom function.
Following should serve:
Replace(Replace(Replace(Me.tbMobNum, " ", ""), "(", ""), ")", "")

I expect Regex could do it and if this gets more complicated, might want to or use VBA custom function.
 
Solution
Here's another:
Code:
Function StringToPlusNumber(yourText as String) as string
    Dim res As String
    Dim i As Long
    For i = 1 To Len(yourText)
        If IsNumeric(Mid(yourText, i, 1)) Or Mid(yourText, i, 1) = "+" Then
            res = res & Mid(yourText, i, 1)
        End If
    Next i
    StringToPlusNumber= res
End Function

It's ugly as hell, but it works. OK, I'll add explanation to this ugly thing:
1. Define function, takes string as parameter
2. Loops character by character by checking how many characters it has starting from 1
3. If current character is numeric or a plus sign, it adds it to the result
4. That is all
 
Last edited:
Doesn't matter if format is generated by Format property of textbox or field in table. It doesn't change saved value. So, my presumption is those unwanted characters are actually in data.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom