Modular functions and substring

vargf

Member
Joined
Feb 15, 2006
Messages
13
Programming Experience
Beginner
Hi can any body help me on understand the Modular function and the sub string?

here is an exalple of a modular function and the sub string
VB.NET:
Function LocationOfPeriod(ByVal Text As String) As Integer 
  Dim MaxSize As Integer = Text.Length ' get size for loop 
  Dim counter, Index As Integer ' used as a counter 
  For counter = 0 To MaxSize - 1 ' loop through the string 
    If (Text.Substring(counter, 1) = ".") Then 'check if the letter at location "counter" is a period, if so set index to this postion 
      Index = counter 
    End If 
  Next 
  Return = Index 'return the value of the index 
End Function

because I want to make a Presonal Application. I need to put a telephone number,first name, last name, Address, Zipcode.

Can Any Body Help me thanks.:confused:

JB: I think i straightened it out, I also added the [ code] tags
 
Last edited by a moderator:
This is very difficult to read and understand. If you could place your code inside a code block(Highlight it with your mouse and hit the button on the tool bar that looks like a hash) and explain in detail what your are trying to achieve, then you are more likely to get a satisfactory response to your query.
 
What's a "modular function"? That code has a serious issue. Index is set to zero by default because it is never explicitly initialised. If no period is found in the string then that function will return zero, which implies that the first character in the string is a period. Bad! The String class already has IndexOf and LastIndexOf methods to do this job. They both return -1 if the substring is not found, which doesn't clash with any actual character index.
 
Back
Top