Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

splitting string and placing letters/numbers in an array

Status
Not open for further replies.

gnibbles

Programmer
Mar 15, 2000
79
CA
Im trying to split a string placed in a text box and place it in an array so then I can check to see if it is a valid postal code L#L-#L#. If someone can help meout id really appreciate it thanks.
 
Yes you can use the split function in VB <br><br>eg to split the string mentioned above <br><br>dim myArray() as string <br><br>MyArray = split(text1.text,&quot;-&quot;)<br><br>'This will create two elements inthe array <br><br>myArray(0) = L#L<br>myArray(1) = #L#<br><br>Hope this is what you were looking for <br><br>
 
actually I want to take each letter or number and place them into the array such as<br>&nbsp;myarray(0) = L<br>&nbsp;myarray(1) = #<br>&nbsp;myarray(2) = L<br>&nbsp;ETC..
 
dim myArray(Len(text1.text))<br>dim i as integer<br><br>for i = 1 to len(text1.text)<br>&nbsp;&nbsp;myArray(i-1) = mid(text1.text,i,1)<br>next i <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
*L* now for question Number 2 is there a way I can check to see if it is a letter or number
 
use the like statement <br><br><br>if ucase(myArray(x)) Like &quot;[A-Z]&quot; then <br>&nbsp;&nbsp;&nbsp;msgbox &quot;Letter&quot;<br>elseif myarray(x) Like &quot;[0-9]&quot; then<br>&nbsp;&nbsp;msgbox &quot;Number&quot;<br>end if <br><br><br>For more help check out MSDN on Like operator <br><br>Hope this helps <br><br><br>
 
<br>You can also use the IsNumeric function<br><br>If IsNumeric(myvar) Then<br>&nbsp;&nbsp;&nbsp;Msgbox &quot;Numeric data&quot;<br>Else<br>&nbsp;&nbsp;&nbsp;Msgbox &quot;Alpha data&quot;<br>End If<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top