giáo trình visual basic và pic phần 2
Số trang: 13
Loại file: pdf
Dung lượng: 247.23 KB
Lượt xem: 27
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu giáo trình visual basic và pic phần 2, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
giáo trình visual basic và pic phần 2Visual Basic Parsing Strings Dim sText As String Dim sMidText As String sText = Reynolds Electronics sMidText = Mid$(sText, 3, 8) After running this code sMidText should equal ynolds E, which starts at the 3rd letter and goes through the 11th (3+8=11). See how it works..? It should also be noted that if a length is not stated it will return all characters from the starting position to the end of the string, as you will see below... Putting It All Together Now for some real fun..! Lets say that you are receiving data from a Basic Stamp. This data is stored in a buffer called sBuffer. Each set of data is separated by an ASCII 13. You want to be able to separate each of these sets of data one by one and display them in the debug window. Here goes... Dim sBuffer As String Dim lEnd As Long Dim sData As String This is the data in your buffer sBuffer = Data1 & Chr$(13) & Data2 & Chr$(13) & Data3 & Chr $(13) & Data4 & Chr$(13) lEnd = InStr(sBuffer, Chr$(13)) Gets Starting position of ASCII 13 Do Starts the loop If lEnd > 0 Then If > 0 then we have an ASCII 13 in the buffer sData = Left$(sBuffer, lEnd - 1) sData will be all characters before lEnd sBuffer = Mid$(sBuffer, lEnd + 1) We want to delete the data that we just got from the buffer including the ASCII 13 Debug.Print sData Display the data lEnd = InStr(sBuffer, Chr$(13)) Gets Starting position of ASCII 13 in the new buffer End If Loop While lEnd > 0 Loop while ASCII 13 is still present in the buffer After running this code you should see Data1 through Data4 show up in your Debug Window.http://www.rentron.com/parsingstrings.htm (4 of 5)5/25/2004 8:47:51 PMVisual Basic Parsing Strings String manipulation is not really that hard. With the use of theses four functions you can parse any string that you want to. It just takes some planning as to how the data will be presented to you, and how you should go about getting the data that you want out of the big string. ;-) > Copyright © 1999-2001 Reynolds Electronics | Contact Information | Reynolds Electronics 3101 Eastridge Lane Canon City, Co. 81212 Voice: (719) 269-3469 Fax: (719) 276-2853http://www.rentron.com/parsingstrings.htm (5 of 5)5/25/2004 8:47:51 PMAdvanced Parsing With Visual Basic Micro-News Micro-Mailing-List Understanding and Using Visual Basic Part 4 By: Jared Hoylman - Advanced String Parsing In the last article we showed the four major string parsing functions along with a few simple examples. In this article we are going to kill two birds with one stone. PBASIC is not very friendly when it comes to conditional statements. Without the If...ElseIf...Else...EndIf kind of conditional statements, beginners find it difficult to program a Basic Stamp to do exactly what they want. If the PBASIC language had the If...ElseIf... Else...EndIf kind of conditional statements I believe it would be much easier for beginners to learn and program the Basic Stamp. So in this article we are going to use our VB string parsing functions to make a complete application that will manipulate true If...ElseIf...Else...EndIf VB style conditionals into functioning PBASIC code..! ...
Nội dung trích xuất từ tài liệu:
giáo trình visual basic và pic phần 2Visual Basic Parsing Strings Dim sText As String Dim sMidText As String sText = Reynolds Electronics sMidText = Mid$(sText, 3, 8) After running this code sMidText should equal ynolds E, which starts at the 3rd letter and goes through the 11th (3+8=11). See how it works..? It should also be noted that if a length is not stated it will return all characters from the starting position to the end of the string, as you will see below... Putting It All Together Now for some real fun..! Lets say that you are receiving data from a Basic Stamp. This data is stored in a buffer called sBuffer. Each set of data is separated by an ASCII 13. You want to be able to separate each of these sets of data one by one and display them in the debug window. Here goes... Dim sBuffer As String Dim lEnd As Long Dim sData As String This is the data in your buffer sBuffer = Data1 & Chr$(13) & Data2 & Chr$(13) & Data3 & Chr $(13) & Data4 & Chr$(13) lEnd = InStr(sBuffer, Chr$(13)) Gets Starting position of ASCII 13 Do Starts the loop If lEnd > 0 Then If > 0 then we have an ASCII 13 in the buffer sData = Left$(sBuffer, lEnd - 1) sData will be all characters before lEnd sBuffer = Mid$(sBuffer, lEnd + 1) We want to delete the data that we just got from the buffer including the ASCII 13 Debug.Print sData Display the data lEnd = InStr(sBuffer, Chr$(13)) Gets Starting position of ASCII 13 in the new buffer End If Loop While lEnd > 0 Loop while ASCII 13 is still present in the buffer After running this code you should see Data1 through Data4 show up in your Debug Window.http://www.rentron.com/parsingstrings.htm (4 of 5)5/25/2004 8:47:51 PMVisual Basic Parsing Strings String manipulation is not really that hard. With the use of theses four functions you can parse any string that you want to. It just takes some planning as to how the data will be presented to you, and how you should go about getting the data that you want out of the big string. ;-) > Copyright © 1999-2001 Reynolds Electronics | Contact Information | Reynolds Electronics 3101 Eastridge Lane Canon City, Co. 81212 Voice: (719) 269-3469 Fax: (719) 276-2853http://www.rentron.com/parsingstrings.htm (5 of 5)5/25/2004 8:47:51 PMAdvanced Parsing With Visual Basic Micro-News Micro-Mailing-List Understanding and Using Visual Basic Part 4 By: Jared Hoylman - Advanced String Parsing In the last article we showed the four major string parsing functions along with a few simple examples. In this article we are going to kill two birds with one stone. PBASIC is not very friendly when it comes to conditional statements. Without the If...ElseIf...Else...EndIf kind of conditional statements, beginners find it difficult to program a Basic Stamp to do exactly what they want. If the PBASIC language had the If...ElseIf... Else...EndIf kind of conditional statements I believe it would be much easier for beginners to learn and program the Basic Stamp. So in this article we are going to use our VB string parsing functions to make a complete application that will manipulate true If...ElseIf...Else...EndIf VB style conditionals into functioning PBASIC code..! ...
Tìm kiếm theo từ khóa liên quan:
giáo trình visual basic tin học ứng dụng lập trình windows lập trình C# mẹo hay cho tin học thủ thuật windowsTài liệu liên quan:
-
Tài liệu bồi dưỡng giáo viên sử dụng SGK Tin học 10 Cánh diều (Định hướng Tin học ứng dụng)
61 trang 247 0 0 -
101 trang 202 1 0
-
Cách gỡ bỏ hoàn toàn các add on trên Firefox
7 trang 190 0 0 -
Bài tập lập trình Windows dùng C# - Bài thực hành
13 trang 188 0 0 -
20 trang 185 0 0
-
Giáo trình Mạng máy tính (Nghề: Tin học ứng dụng - Trung cấp) - Trường Cao đẳng Cộng đồng Đồng Tháp
189 trang 164 0 0 -
bảo mật mạng các phương thức giả mạo địa chỉ IP fake IP
13 trang 161 0 0 -
Bài giảng Tin học ứng dụng: Kiểm định trung bình - Trường ĐH Y dược Huế
25 trang 152 0 0 -
Giáo trình Tin học ứng dụng: Phần 1 - Trường ĐH Tài nguyên và Môi trường Hà Nội
125 trang 151 0 0 -
175 trang 130 0 0