Friday, October 24, 2008

Split String so simple and easy by VB function [vb split string]

1. Format of Raw Data for split You should know about data format for your spliting, such as 1.1 what delimiter ? space(” “) or slash(”/”) or mix format
1.2 what data type to convert
2. Function to use
Use Split Function for split data


Sample Code
creat one textbox and one button

1:  Private Sub CommandButton1_Click()  
2:  ’error handler for Do Loop action over one step  
3:  On Error GoTo Err  
4:  Dim RawData As String  
5:  Dim SplitData() As String  
6:  Dim i, IndexData As Integer  
7:  Dim Answer As Variant  
8:  IndexData = 1  
9:  RawData = TextBox1.Text  
10:  SplitData = Split(RawData)  
11:  ‘find number of data array  
12:  Do Until IndexData = 0  
13:  If IsNull(SplitData(IndexData - 1)) = False  
14:  Then IndexData = IndexData + 1  
15:  Else: IndexData = 0  
16:  End If  
17:  Loop Err:  
18:  For i = 0 To IndexData - 2 Step 1  
19:  ’subtract for IndexData startpoint at 1 and overstep  
20:  Do Loop 1  
21:  MsgBox SplitData(i)  
22:  Next i  
23:  End Sub  

The part of this article is credit to http://www.blogbov.co.cc/

No comments:

Post a Comment