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: 293 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
Dev Hardware God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2004
Location: Salem, OH
Posts: 5,673 Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 Week 5 Days 20 h 1 m 5 sec
Reputation Power: 8888
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
Facebook 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)
__________________
Don't like me? Click it.

Scripting problems? Windows questions? Ask the Windows Guru!

Stay up to date with all of my latest content. Follow me on Twitter!

Help us help you! Post your exact error message with these easy tips!

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: 293 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
Dev Hardware God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2004
Location: Salem, OH
Posts: 5,673 Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 Week 5 Days 20 h 1 m 5 sec
Reputation Power: 8888
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
Facebook 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
Dev Hardware God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2004
Location: Salem, OH
Posts: 5,673 Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 Week 5 Days 20 h 1 m 5 sec
Reputation Power: 8888
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
Facebook 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: 293 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
Dev Hardware God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2004
Location: Salem, OH
Posts: 5,673 Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 Week 5 Days 20 h 1 m 5 sec
Reputation Power: 8888
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
Facebook 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: 293 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
  Trader Rating: 2 · #9  
Old January 2nd, 2007, 07:56 PM
Nilpo's Avatar
Nilpo Nilpo is offline
Dev Hardware God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2004
Location: Salem, OH
Posts: 5,673 Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 Week 5 Days 20 h 1 m 5 sec
Reputation Power: 8888
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
Facebook MySpace Orkut
Well, if you don't need to preserve the existing lines, this can be done a lot easier like this:

(I'm assuming that the beginning of the email could have multiple lines, so I'm counting backwards. This assumes that the 3 fields we want are always listed LAST)
vb Code:
Original - vb Code
  1. Dim sText As String
  2. Dim sDate As String
  3. Dim sName As String
  4. Dim sAge As String
  5. Dim arrText() As String
  6. Dim count As Integer
  7.  
  8. sText = text1.text
  9.  
  10. ' Get line count
  11. count = InStr(sText, vbNewLine)
  12.  
  13. ' Size our dynamic array
  14. ReDim arrText(count + 1)
  15.  
  16. ' Split our text string into an array housing individual lines
  17. arrText = Split(sText, vbNewLine, -1, 1)
  18.  
  19. ' Pull the last 3 strings from our array
  20. sDate = arrText(Ubound(arrText) - 3)
  21. sName = arrText(Ubound(arrText) - 2)
  22. sAge = arrText(Ubound(arrText) - 1)
  23.  
  24. ' Search for all characters after the : and then trim any extraneous spaces
  25. sDate = Trim(Right(sDate, Len(sDate) - InStr(sAge, ":")))
  26. sName = Trim(Right(sName, Len(sName) - InStr(sName, ":")))
  27. sAge = Trim(Right(sAge, Len(sAge) - InStr(sAge, ":")))
It would probably be more efficient to create a function for all of the string parsing. You could also save some effort by reversing the strings and using the Left function instead, but again, I wanted to demonstrate the actual thought process involved.

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

Reply With Quote
  Trader Rating: 0 · #10  
Old January 2nd, 2007, 08:06 PM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 293 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
Well, if you don't need to preserve the existing lines, this can be done a lot easier like this:

(I'm assuming that the beginning of the email could have multiple lines, so I'm counting backwards. This assumes that the 3 fields we want are always listed LAST)
Code:
Dim sText As String
Dim sDate As String
Dim sName As String
Dim sAge As String
Dim arrText() As String
Dim count As Integer

sText = text1.text

' Get line count
count = InStr(sText, vbNewLine)

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

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

' Pull the last 3 strings from our array
sDate = arrText(Ubound(arrText) - 3)
sName = arrText(Ubound(arrText) - 2)
sAge = arrText(Ubound(arrText) - 1)

' Search for all characters after the : and then trim any extraneous spaces
sDate = Trim(Right(sDate, Len(sDate) - InStr(sAge, ":")))
sName = Trim(Right(sName, Len(sName) - InStr(sName, ":")))
sAge = Trim(Right(sAge, Len(sAge) - InStr(sAge, ":")))
It would probably be more efficient to create a function for all of the string parsing. You could also save some effort by reversing the strings and using the Left function instead, but again, I wanted to demonstrate the actual thought process involved.
How do you save the extracted data into a textfile?

Many Thanks, much appreciated!

Reply With Quote
  Trader Rating: 2 · #11  
Old January 2nd, 2007, 08:08 PM
Nilpo's Avatar
Nilpo Nilpo is offline
Dev Hardware God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2004
Location: Salem, OH
Posts: 5,673 Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)Nilpo User rank is General 119th Grade (Above 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 Week 5 Days 20 h 1 m 5 sec
Reputation Power: 8888
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
Facebook MySpace Orkut
How do you want your text file formatted? Plain text, CSV? Give me a sample of what a text file output should look like.

Reply With Quote
  Trader Rating: 0 · #12  
Old January 2nd, 2007, 08:13 PM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 293 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
What is CSV?

Is there anyway of making the file unreadable, via storing the data as binary etc.

Many Thanks, much appreciated!

Reply With Quote
  Trader Rating: 0 · #13  
Old January 2nd, 2007, 08:14 PM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 293 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
Is there anyway you could comment you code, in order for me to work out how it all works, and what values are going in to where?

Many Thanks,

Reply With Quote
  Trader Rating: 0 · #14  
Old January 2nd, 2007, 08:31 PM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 293 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
Well, if you don't need to preserve the existing lines, this can be done a lot easier like this:

(I'm assuming that the beginning of the email could have multiple lines, so I'm counting backwards. This assumes that the 3 fields we want are always listed LAST)
Code:
Dim sText As String
Dim sDate As String
Dim sName As String
Dim sAge As String
Dim arrText() As String
Dim count As Integer

sText = text1.text

' Get line count
count = InStr(sText, vbNewLine)

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

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

' Pull the last 3 strings from our array
sDate = arrText(Ubound(arrText) - 3)
sName = arrText(Ubound(arrText) - 2)
sAge = arrText(Ubound(arrText) - 1)

' Search for all characters after the : and then trim any extraneous spaces
sDate = Trim(Right(sDate, Len(sDate) - InStr(sAge, ":")))
sName = Trim(Right(sName, Len(sName) - InStr(sName, ":")))
sAge = Trim(Right(sAge, Len(sAge) - InStr(sAge, ":")))
It would probably be more efficient to create a function for all of the string parsing. You could also save some effort by reversing the strings and using the Left function instead, but again, I wanted to demonstrate the actual thought process involved.
With text1 containing:

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

the date, name, and age returned is as follows:

: 12/12/06
Bill
19

is there anyway of extracting the date, with ": " before it?

Many Thanks, much appreciated!

Reply With Quote
  Trader Rating: 0 · #15  
Old January 2nd, 2007, 08:39 PM
Salchester Salchester is offline
Contributing User
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 293 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
Oh yeah, i forgot to mention, the information currently in the textbox is actually the following, including line breaks:

<Name Field> has sent the following information:


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


What needs to be changed in the code now to ignore <Name Field> has sent the following information: and the two line breaks?

Sorry, Many Thanks, much appreciated!!!! :-)

Last edited by Salchester : January 2nd, 2007 at 08:53 PM.

Reply With Quote
Reply

Viewing: Dev Hardware ForumsSOFTWAREProgramming > Parsing Strings


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
     
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT