cguygo 09-08-2003, 02:21 PM I have a file that has records like this :
þP103B35I333S0þþ9E10D692-354B-4B18-AFCE-A33041240A8Bþ
þP103B35I2274S0þþ9E10D692-354B-4B18-AFCE-A33041240A8Bþ
there are more than this but this is for the example. Anyway I think I know how to read it. I just dont know if the ascii characters pose a problem.
I want the #'s after the "P", "B", "I" and the "S"
I am going to write those values into a txt file.
What (if anything) do i have to do to read in the þ and ?
Any help or site with this info would be apprciated.
Thanks,
Guy
What I was understood is u want split only strings, isnt it...
þP103B35I333S0þþ9E10D692-354B-4B18-AFCE-A33041240A8Bþ
Output is PBISEDBBAFCEAAB
Private Sub Command1_Click()
MsgBox SplitString("þP103B35I333S0þþ9E10D692-354B-4B18-AFCE-A33041240A8Bþ")
End Sub
Function SplitString(strText As String) As String
Dim TempStr As String
If Len(Trim(strText)) = 0 Then Exit Function
For i = 1 To Len(strText)
If Mid(strText, i, 1) Like "[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]" Then
TempStr = TempStr + Mid(strText, i, 1)
End If
Next i
SplitString = TempStr
End Function
I hope this would helps u...
xBox
Banjo 09-08-2003, 04:59 PM It looks like you have two halves per line separated by what to me appears as Chr$(20). You should check it at your end using the Asc function though to ensure it hasn't been changed between you and me.
You need to use a combination of Instr and Mid$ parse out the numbers.
cguygo 09-08-2003, 09:03 PM þP103B35I333S0þþ9E10D692-354B-4B18-AFCE-A33041240A8Bþ
þP103B35I2274S0þþ9E10D692-354B-4B18-AFCE-A33041240A8Bþ
What I have is a file with records like those listed above in it.
What I want to do is extract the numbers that follow the 'P', 'B', 'I', and 'S'. Like youll see a 103 follows the P, or the 35 that follows the B, so on and so forth. However, everything to the right of the þþ is garbage that i dont need.
I want to take these numbers following the 'P', 'B', 'I', and 'S' and write them to a new file for easier reading. Where they arent crammed together. Preferably, maybe farther down the line I want to Make a new file based on the value following the B.
I hope this clears it up. I am working on it now and would appreciate some more ideas...thanks
passel 09-08-2003, 09:25 PM Give this a shot. replace inputfilnamehere and output.... with the
filenames you want.
Private Sub Command2_Click()
Dim d As String, v As Long
d = "PBIS"
Open "inputfilnamehere" For Input As #1
Open "outputfilenamehere" For Output As #2
While Not EOF(1)
Line Input #1, a$
For i = 1 To Len(d)
v = Val(Mid$(a$, InStr(a$, Mid$(d, i, 1)) + 1))
Print #2, v,
Next
Print #2, vbNullString
Wend
Close 1, 2
End Sub
cguygo 09-08-2003, 11:30 PM That worked great thanks....I understand all of that except for the a$. It has been a while since I took a VB class, maybe I knew then and just forgot. What does the a$ represent?
Thanks for your help...now I can tweak it out to do some other cool stuff...thanks.
passel 09-09-2003, 07:29 AM It's old basic notation. It just means a is a string, a$ (I pronounce it
A-string, in my head without thinking about it, just like mid$ is mid-string when I see it. $ is synonymous with "string" and I can't remove
that association).
I should have just declared it above, but when I quickly test stuff, I
usually revert to using the $ on the name which is second nature to me.
I usually go back, and "repair" that if the code is going to become
permanent, but I often write little one time use stuff and usually don't
even bother saving it once used, so don't take the time. In this case, I
needed to head to bed, so missed modifying it.
It is best to have the Options Explicit turned on, and declare all
variables, rather than use a$ as I did.
Originally, I used d$ as well, but I did change that one, just missed the
a$ for some reason.
|