Reputation: 5
I need help in validation in VB6, where it will check if the user type-in www. on a text-box, because I wanted to make the www. static
Dim Text As String
Text = Text1.Text
If Text1.Text = "www." Then
MsgBox "www. is already present", vbExclamation + vbOKOnly, "Opps!..."
ElseIf Text1.Text = "WWW." Then
MsgBox "www. is already present", vbExclamation + vbOKOnly, "Opps!..."
Else
Open ("C:\Windows\System32\drivers\etc\hosts") For Append As #1
Print #1, "127.0.0.1 " + "www." + Text
Close #1
End If
This seems to be not working because the msgbox will only appear when a user just type in "www." But I want to make it like when the user type www. the message-box will appear.
Upvotes: 0
Views: 250
Reputation: 55
Don't bother to user to check the data, just remove the www. like this: replace(text1.text ,"www.","",,,vbTextCompare) Not matter if the test is upper or lower case.
Upvotes: 0
Reputation: 24313
You probably want to use the Left$()
function.
If StrComp(Left(Text1.Text, 4), "www.", vbTextCompare) = 0 Then
...
The StrComp()
with vbTextCompare
makes it case insensitive.
Upvotes: 2