Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   Dev Hardware ForumsSOFTWAREProgramming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Hardware Forums Sponsor:
  Trader Rating: 0 · #1  
Old January 2nd, 2007, 02:22 PM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 294 Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 23 h 37 m 7 sec
Reputation Power: 5
Parsing Strings

I currently have some text in a multiline textbox, how can the the following code be adapted to parse characters 3 to 8 on line 1 of the textbox. Then characters 2 to 6 on line to of the text box, and store both extracted strings in two separate variables.

The following code extracts from line 1 then store the extracted string inside sMidText

vb Code:
Original - vb Code
  1. Dim sText As String
  2. Dim sMidText As String
  3.  
  4. sText = text1.text
  5. sMidText = Mid$(sText, 3, 8)
  6. Debug.Print sMidText
Many Thanks,

Last edited by Nilpo : February 8th, 2007 at 01:18 AM.

Reply With Quote
  Trader Rating: 2 · #2  
Old January 2nd, 2007, 06:45 PM
Nilpo's Avatar
Nilpo Nilpo is offline
Click here for more information.
 
Join Date: May 2004
Location: Salem, OH
Posts: 5,326 Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)  Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 Week 2 Days 18 h 58 m 33 sec
Reputation Power: 5341
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
MySpace Orkut
Basically, you use the Split function to separate your string at newline characters. This results in an array containing one substring for each line. You finish up by parsing each line for the requested characters with the Mid function.
vb Code:
Original - vb Code
  1. Dim sText As String
  2. Dim line1 As String
  3. Dim line2 As String
  4. Dim seg1 As String
  5. Dim seg2 As String
  6. Dim arrText() As String
  7. Dim count As Integer
  8.  
  9. sText = text1.text
  10.  
  11. ' Get line count
  12. count = InStr(sText, "\n")
  13.  
  14. ' Size our dynamic array
  15. ReDim arrText(count + 1)
  16.  
  17. ' Split our text string into an array housing individual lines
  18. arrText = Split(sText, "\n", -1, 1)
  19.  
  20. line1 = arrText(0)
  21. line2 = arrText(1)
  22.  
  23. ' Parse our lines
  24. seg1 = Mid(line1, 3, 6)
  25. seg2 = Mid(line2, 2, 5)
__________________
Click the image if at any point you don't like my decision.

10011100011000101111100011100000011000000100000011 10010011011110110001101101011011110100011000001110 0100111101000100001

Visit Nilpo.com and Ask the Windows Guru!

Open me for some very useful links!    

Last edited by Nilpo : February 8th, 2007 at 12:47 AM.

Reply With Quote
  Trader Rating: 0 · #3  
Old January 2nd, 2007, 06:56 PM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 294 Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 23 h 37 m 7 sec
Reputation Power: 5
Quote:
Originally Posted by Nilpo
Basically, you use the Split function to separate your string at newline characters. This results in an array containing one substring for each line. You finish up by parsing each line for the requested characters with the Mid function.
Code:
Dim sText As String
Dim line1 As String
Dim line2 As String
Dim seg1 As String
Dim seg2 As String
Dim arrText() As String
Dim count As Integer

sText = text1.text

' Get line count
count = InStr(sText, "\n")

' Size our dynamic array
ReDim arrText(count + 1)

' Split our text string into an array housing individual lines
arrText = Split(sText, "\n", -1, 1)

line1 = arrText(0)
line2 = arrText(1)

' Parse our lines
seg1 = Mid(line1, 3, 6)
seg2 = Mid(line2, 2, 5)
How come when the above code is pasted into Visual Basic 6.0, i get a "Subscript out of range" error message. (problem item shown in bold above)

Many Thanks,

Reply With Quote
  Trader Rating: 2 · #4  
Old January 2nd, 2007, 07:04 PM
Nilpo's Avatar
Nilpo Nilpo is offline
Click here for more information.
 
Join Date: May 2004
Location: Salem, OH
Posts: 5,326 Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)  Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 Week 2 Days 18 h 58 m 33 sec
Reputation Power: 5341
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
MySpace Orkut
Quote:
Originally Posted by Salchester
How come when the above code is pasted into Visual Basic 6.0, i get a "Subscript out of range" error message. (problem item shown in bold above)

Many Thanks,
That would indicate that your array doesn't have that many elements. That means one of two things: either sText doesn't contain multiple lines, or it's not using the \n newline character. In this case, most likely the second. Try this:

vb Code:
Original - vb Code
  1. Dim sText As String
  2. Dim line1 As String
  3. Dim line2 As String
  4. Dim seg1 As String
  5. Dim seg2 As String
  6. Dim arrText() As String
  7. Dim count As Integer
  8.  
  9. sText = text1.text
  10.  
  11. ' Get line count
  12. count = InStr(sText, vbNewLine)
  13.  
  14. ' Size our dynamic array
  15. ReDim arrText(count + 1)
  16.  
  17. ' Split our text string into an array housing individual lines
  18. arrText = Split(sText, vbNewLine, -1, 1)
  19.  
  20. line1 = arrText(0)
  21. line2 = arrText(1)
  22.  
  23. ' Parse our lines
  24. seg1 = Mid(line1, 3, 6)
  25. seg2 = Mid(line2, 2, 5)

Last edited by Nilpo : February 8th, 2007 at 12:48 AM.

Reply With Quote
  Trader Rating: 2 · #5  
Old January 2nd, 2007, 07:07 PM
Nilpo's Avatar
Nilpo Nilpo is offline
Click here for more information.
 
Join Date: May 2004
Location: Salem, OH
Posts: 5,326 Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)  Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 Week 2 Days 18 h 58 m 33 sec
Reputation Power: 5341
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
MySpace Orkut
You can cut this code down considerably, but I wanted to demonstrate the thought process behind it.

Reply With Quote
  Trader Rating: 0 · #6  
Old January 2nd, 2007, 07:19 PM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 294 Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 23 h 37 m 7 sec
Reputation Power: 5
I currently have the following information a text box:

Date: 12/12/06
Name: Bill
Age: 19

How can the data after each field be extracted, and store in a text file. To result in the text file containing only (12/12/06, Bill, 19 etc)

The data after the fields changes i.e. (12/12/06, Bill, 19 etc).

Reply With Quote
  Trader Rating: 2 · #7  
Old January 2nd, 2007, 07:25 PM
Nilpo's Avatar
Nilpo Nilpo is offline
Click here for more information.
 
Join Date: May 2004
Location: Salem, OH
Posts: 5,326 Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)Nilpo User rank is General 65th Grade (Above 100000 Reputation Level)  Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1Folding Points: 186632 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 Week 2 Days 18 h 58 m 33 sec
Reputation Power: 5341
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
MySpace Orkut
Quote:
Originally Posted by Salchester
I currently have the following information a text box:

Date: 12/12/06
Name: Bill
Age: 19

How can the data after each field be extracted, and store in a text file. To result in the text file containing only (12/12/06, Bill, 19 etc)

The data after the fields changes i.e. (12/12/06, Bill, 19 etc).
Okay, we were dealing with that in another thread. Is this the same question? (And you can do it with the above code)

Reply With Quote
  Trader Rating: 0 · #8  
Old January 2nd, 2007, 07:28 PM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 294 Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level)Salchester User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 23 h 37 m 7 sec
Reputation Power: 5
Quote:
Originally Posted by Nilpo
Okay, we were dealing with that in another thread. Is this the same question? (And you can do it with the above code)
Sort of, how does the code need to be adapted?

Many Thanks, much appreciated

Reply With Quote