13 Replies - 2126 Views - Last Post: 11 August 2011 - 07:30 PM Rate Topic: -----

#1 gee_1323  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-August 11

"InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 12:45 AM

I have an app that takes your full name: First Middle(If any) and Last and converts it to UserInitials String. If the name doesn't have a middle name, "X" should be displayed for the Middle Name.

Example name: First Middle Last = FML;
Example name: First Last = FXL

Obviously, if there is only ONE space present, there is no middle name. I'm having issues calling InStrRev to count from the right to the left.

Ex: InStrRev(Name_Input, " ")

How can I get these Initials???

Is This A Good Question/Topic? 0
  • +

Replies To: "InStrRev" function not Counting from Right to Left...

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 01:10 AM

There are many ways to achieve that, for instance if a full name is entered as a single string, then I can check for the index of space:
 If input.IndexOf(" ") = input.LastIndexOf(" ") Then
'if the index is the same means this user has no initial name
'So I will join the first char of the input + "X" + then next char after space
End If 
'Else means we have two different spaces
'So I will join the first char + the next char after the first space + next char after last space

Glad this pseudo will help
Was This Post Helpful? 1
  • +
  • -

#3 fixo  Icon User is offline

  • D.I.C Regular

Reputation: 85
  • View blog
  • Posts: 335
  • Joined: 10-May 09

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 01:39 AM

Try this one
 If Name_Input.Contains(" "c) Then
            MsgBox("There is no Middle Name")
        End If

Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 02:11 AM

View Postfixo, on 11 August 2011 - 02:24 PM, said:

Try this one
 If Name_Input.Contains(" "c) Then
            MsgBox("There is no Middle Name")
        End If

But the if will return true if there is atleast one space!! which will not really tell if the middle name exists or not.
Was This Post Helpful? 1
  • +
  • -

#5 Jeff H  Icon User is offline

  • D.I.C Regular

Reputation: 112
  • View blog
  • Posts: 308
  • Joined: 30-January 11

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 02:34 AM

Usually you store those values seperate but you could split and use length or count

    Public Function GetIntialials(ByVal name As String) As String
        Dim names() As String = name.Split(" ")
        If names.Length = 2 Then
            Return ''''''''''''''''''''''''''
        End If
        Return '''''''''''''''''''''''

    End Function


Was This Post Helpful? 0
  • +
  • -

#6 gee_1323  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-August 11

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 01:15 PM

View Postsmohd, on 11 August 2011 - 01:10 AM, said:

There are many ways to achieve that, for instance if a full name is entered as a single string, then I can check for the index of space:
 If input.IndexOf(" ") = input.LastIndexOf(" ") Then
'if the index is the same means this user has no initial name
'So I will join the first char of the input + "X" + then next char after space
End If 
'Else means we have two different spaces
'So I will join the first char + the next char after the first space + next char after last space

Glad this pseudo will help


Yes, this is what i needed! So what you're saying is if I type:

If Name_Input.IndexOf(" ") = Name_Input.LastIndexOf(" ") Then
SecondInitial = "X"
Else ?

How would I be able to extract the ThirdInitital? The first is simple enough: Microsoft.VisualBasic.Left(Name_Input, 1)

Thank you so much, by the way.
Was This Post Helpful? 0
  • +
  • -

#7 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 01:46 PM

Like this:
 'Second initial will be the next char after the first space
SecondInitial = input.Substring(input.IndexOf(" ") + 1, 1)
'and the last initial
LastInitial = input.Substring(input.LastIndexOf(" ") + 1, 1)


Hope this will help :)
Was This Post Helpful? 1
  • +
  • -

#8 gee_1323  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-August 11

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 02:14 PM

View Postsmohd, on 11 August 2011 - 01:46 PM, said:

Like this:
 'Second initial will be the next char after the first space
SecondInitial = input.Substring(input.IndexOf(" ") + 1, 1)
'and the last initial
LastInitial = input.Substring(input.LastIndexOf(" ") + 1, 1)


Hope this will help :)



I'm going to put this to the test as soon as i get home!

I was also looking for Len of Email_Input to see if the email is valid; the TextBox where the email is typed in.

If Len(Email_Input) >= 7 Then
Email = True
Return Email
Else: Email = False
Return Email
End If

This format should be correct: "a@a.com"
Yet I type: "@a.com" for example, and it returns True.
Why is this happening?
Was This Post Helpful? 0
  • +
  • -

#9 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 02:30 PM

Till I see your code, I cant say what is happening. But what you are required to check is if @ and . are there and also the first and last characters are not @ or .
Also you may use regex or regular expression like:
http://msdn.microsof...v=vs.71%29.aspx
http://msdn.microsof...y/01escwtf.aspx
http://www.dreaminco...snippet1394.htm
Was This Post Helpful? 0
  • +
  • -

#10 gee_1323  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-August 11

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 06:07 PM

View Postsmohd, on 11 August 2011 - 01:46 PM, said:

Like this:
 'Second initial will be the next char after the first space
SecondInitial = input.Substring(input.IndexOf(" ") + 1, 1)
'and the last initial
LastInitial = input.Substring(input.LastIndexOf(" ") + 1, 1)


Hope this will help :)



I tried this and it works fine with a First and Last name but when I put a Middle name in, i get this error message:

An unhandled exception of type 'System.InvalidCastException' occurred in system.windows.forms.dll

Additional information: Cast from string " " to type 'Double' is not valid.

It's not extracting the Middle Initial when there's three names.

CORRECTION!!! I forgot to close the parenthesis on the Space String :butbut:
It works beautifully!!

This post has been edited by gee_1323: 11 August 2011 - 06:15 PM

Was This Post Helpful? 0
  • +
  • -

#11 gee_1323  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-August 11

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 06:34 PM

View Postsmohd, on 11 August 2011 - 02:30 PM, said:

Till I see your code, I cant say what is happening. But what you are required to check is if @ and . are there and also the first and last characters are not @ or .
Also you may use regex or regular expression like:
http://msdn.microsof...v=vs.71%29.aspx
http://msdn.microsof...y/01escwtf.aspx
http://www.dreaminco...snippet1394.htm


The Email Validation I need is VERY simple. All I need is to make sure that it is in its most basic format:
"a@b.com"

I was thinking that if I used the Len Function I could ensure that nothing was missing.
For example:
[code]If Len(Email_Input) >= 7 Then
Email = True
Return Email
Else Email = False
Return Email
End If[code]

This isn't working out because I type "@a.com" and it still returns True. How can I get around this? Or make sure that the string contains a Character before and after the "@"?
Was This Post Helpful? 0
  • +
  • -

#12 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 07:00 PM

Then you will have an i statement to check if the first and last character is not @ or ".". And now you know how to get those characters and compare them ;)
If Len(Email_Input) >= 7 Then
   If fitstChar <> "@".......Then
      return true
   End If
End If
return false 

This post has been edited by smohd: 11 August 2011 - 07:05 PM

Was This Post Helpful? 0
  • +
  • -

#13 gee_1323  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-August 11

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 07:18 PM

View Postsmohd, on 11 August 2011 - 07:00 PM, said:

Then you will have an i statement to check if the first and last character is not @ or ".". And now you know how to get those characters and compare them ;)
If Len(Email_Input) >= 7 Then
   If fitstChar <> "@".......Then
      return true
   End If
End If
return false 


I can't seem to get it... I have Email_Input which is my textbox.
All I need is to check that if someone enters: "@a.com" OR "a@.com" OR "@.com" it doesn't return True.

After this I'm DONE!
Was This Post Helpful? 0
  • +
  • -

#14 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: "InStrRev" function not Counting from Right to Left...

Posted 11 August 2011 - 07:30 PM

Then the easiest way is to regex match. I have pointed you to a function that did that check for you otherwise you will have a very big if statement to check for those possibilities.
You will have to get the first character, character before dot and after it(and you have done how to get char at certain indexes) then check if they are valid or not.
The solution is in the third link I posted(function that returns true or false according to the passed string).
Patern matching is the solution here,
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1