-
Aug 18th, 2017, 10:40 AM
#1
Thread Starter
Member
Select some data of a text file and save it in a table
Hi! Anybody knows how to select some data in a text?.
I have this text saved in a txt file called data.txt:
O /interface/wireless/registration-table/print
O <<EOS>>
I !done
I =ret=10d70e14c3ab58dffddfbe534af5cfa0
I <<EOS>>
I !done
I <<EOS>>
I !re
I =.id=*2
I =interface=wlan1
I =mac-address=B8:64:91:68:1C:50
I =ap=false
I =wds=false
I =bridge=false
I =rx-rate=65Mbps-20MHz/1S
I =tx-rate=11Mbps
I =packets=122,172
I =bytes=13265,14518
I =frames=122,172
I =frame-bytes=12533,13486
I =hw-frames=123,206
I =hw-frame-bytes=15584,18430
I =tx-frames-timed-out=0
I =uptime=46s
I =last-activity=190ms
I =signal-strength=-38@HT20-7
I =signal-to-noise=49
I =signal-strength-ch0=-38
I =evm-ch0=29
I =strength-at-rates=-33@1Mbps
I 2s910ms,-38@6Mbps
I 2s520ms,-36@HT20-1
I 20s160ms,-38@HT20-6
I 7s330ms,-38@HT20-7
I 190ms
These files are generated by an API and they have always the same format: Name of the variable, separator (=) and value.
I need a function to select the next data of the text and to show them in a datagrid:
mac-address B8:64:91:68:1C:50
rx-rate 65Mbps-20MHz/1S
tx-rate 11Mbps
packets 122,172
uptime 46s
last-activity 190ms
Isignal-strength -38@HT20-7
signal-to-noise 49
Isignal-strength-ch0 -38
Thank you so much!
-
Aug 18th, 2017, 12:09 PM
#2
Re: Select some data of a text file and save it in a table
Well you could simply read it line by line and parse the lines as you go. Not elegant but would do the job
-
Aug 18th, 2017, 12:57 PM
#3
Re: Select some data of a text file and save it in a table
You really don't need to save it in a table in a database. You have all the data in the text file...like DM says, parse it and display it. Instead of a datagrid, you could use a flexgrid. Especially if it is just for display purposes.
You really need to explain WHY you want to do this. What do you intend to do with the information after it is displayed? Will the data.txt file keep changing, or is it static?
-
Aug 18th, 2017, 01:18 PM
#4
Thread Starter
Member
Re: Select some data of a text file and save it in a table
I want to show the data in a table without the (=) symbol. The values of these variables in txt file will change so it is not static.
Can you send me a code with how to parse some of these data and how to show it in a flexgrid? I am new in vb6
-
Aug 19th, 2017, 07:09 AM
#5
Re: Select some data of a text file and save it in a table
Here is a small example of loading your text file to both an MSHFlexGrid and a ListBox.
-
Aug 19th, 2017, 09:57 AM
#6
Re: Select some data of a text file and save it in a table
ams
Here is a variation of Sammi's solution.
Concept
1. I saved your text file data.txt as ams1.txt
2. I saved your variables list as ams2.txt, (I called them fields)
mac-address B8:64:91:68:1C:50
rx-rate 65Mbps-20MHz/1S
tx-rate 11Mbps
packets 122,172
uptime 46s
last-activity 190ms
Isignal-strength -38@HT20-7
signal-to-noise 49
Isignal-strength-ch0 -38
3. I then read ams2.txt, and "kept" only the field name (ie, up to the 1st "space")
4. I then read ams1.txt, used Split function, and if a "match", extracted data after the 2nd "=" sign.
Here is a code snippet
Code:
Private Sub Command1_Click()
'
' set FG col widths
Dim amsCC(3)
amsCC(1) = 300
amsCC(2) = 2000
amsCC(3) = 2500
For ii = 1 To 3
amsCC(0) = amsCC(0) + amsCC(ii)
Next ii
' 1. open file2 .. desired fields .. copy to array amsFields
Dim amsFields()
fpath = "D:\VBForums\ams2.txt"
Open fpath For Input As #1
rr = 0
Do While Not EOF(1)
rr = rr + 1
ReDim Preserve amsFields(rr)
Line Input #1, xtr
ss = InStr(xtr, " ") ' find location of "space"
amsFields(rr) = Left(xtr, ss - 1) ' extract up to the "space"
Loop
Close #1
' 2. populate FlexGrid
With FG1
' a. populate col 1 with Field names
For ii = 1 To rr
.Row = ii
.Col = 0
.Text = ii
'
.Col = 1
.Text = amsFields(ii)
Next ii
' b. populate col 2 .. read "data" file
fpath = "D:\VBForums\ams1.txt"
Open fpath For Input As #1
Do While Not EOF(1)
Line Input #1, xtr
ss = Split(xtr, "=")
uu = UBound(ss)
' if xtr has 2 "=" .. Value will be element 2
If uu = 2 Then ' has 2 "="
' match with list of Fields
ff = ss(1) ' Field name is element 1
For jj = 1 To rr
If InStr(amsFields(jj), ff) > 0 Then
vv = ss(2)
.Row = jj
.Col = 2
.CellAlignment = 6 ' right align
.Text = vv
End If
Next jj
End If
Loop
Close #1
End With
'
End Sub
Here is an image
HTH
Spoo
Last edited by Spooman; Aug 19th, 2017 at 10:12 AM.
-
Aug 19th, 2017, 11:07 AM
#7
Re: Select some data of a text file and save it in a table
Taking the formatting suggestion from the good spooman, I changed my example. Take a gander:
Option Explicit
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdGetData_Click()
Grid1.Rows = 10
Grid1.Clear
Grid1.TextMatrix(0, 0) = "FIELD"
Grid1.TextMatrix(0, 1) = "VALUE"
Dim sString As String
Dim fileNum As Integer
fileNum = FreeFile
Open App.Path & "\data.txt" For Input As #fileNum
Dim y As Integer
Do While Not EOF(fileNum)
Line Input #fileNum, sString
If Mid(sString, 4, 4) = "mac-" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(1, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(1, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "rx-r" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(2, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(2, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "tx-r" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(3, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(3, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "pack" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(4, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(4, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "upti" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(5, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(5, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "last" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(6, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(6, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 16) = "signal-strength=" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(7, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(7, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 8) = "signal-t" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(8, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(8, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 16) = "signal-strength-" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(9, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(9, 1) = Mid(sString, y + 1)
End If
Loop
Grid1.ColAlignment(1) = 2
Close fileNum
End Sub
Private Sub Form_Load()
Grid1.Cols = 2
Grid1.ColWidth(0) = 3000
Grid1.ColWidth(1) = 3000
End Sub
-
Sep 5th, 2017, 05:52 AM
#8
Thread Starter
Member
Re: Select some data of a text file and save it in a table
Thank you so much, all of them works fine!! But I think that #7 is the best!
The last question: how would you change that code if the text is in a textbox called TextBox1 rather than in the .txt file?
Thank you for your help!!
-
Sep 5th, 2017, 06:25 AM
#9
Re: Select some data of a text file and save it in a table
If you have that data in a textbox (I'm assuming you mean a multi-line one), then simply divide it by line (using the SPLIT() function), and then putting each element of the resulting array into your flexgrid. YOU give it a try and see what you can come up with based upon that suggestion.
-
Sep 10th, 2017, 09:43 AM
#10
Thread Starter
Member
Re: Select some data of a text file and save it in a table
I have done these changes in the original code to read the text from a textbox called TextBox1 instead of a .txt file:
Code:
Private Sub GetData_Click()
Grid1.Visible = True
Grid1.Rows = 10
Grid1.Clear
Grid1.TextMatrix(0, 0) = "FIELD"
Grid1.TextMatrix(0, 1) = "VALUE"
Dim i As Integer 'Counter
Dim sString As String
Dim fileNum As Integer
fileNum = FreeFile
'Open App.Path & "\mensajeAPI.txt" For Input As #fileNum
sString = TextBox1.text
Dim y As Integer
For i = 1 To Len(txtOut.text) 'EOF(fileNum)
'Line Input #fileNum, sString
If Mid(sString, 4, 4) = "mac-" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(1, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(1, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "rx-r" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(2, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(2, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "tx-r" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(3, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(3, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "pack" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(4, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(4, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "upti" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(5, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(5, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "last" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(6, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(6, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 16) = "signal-strength=" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(7, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(7, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 8) = "signal-t" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(8, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(8, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 16) = "signal-strength-" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(9, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(9, 1) = Mid(sString, y + 1)
End If
'Loop
Next
Grid1.ColAlignment(1) = 2
'Close fileNum
End Sub
I don't know why but I don´t obtain any result in the table (The text in the TextBox is the same as the text in the .txt file)
I have also probed with your suggestion of the Split() function but it doesn't work. Maybe it is because I don't know how to use that function correctly. Can anybody help me?
-
Sep 10th, 2017, 10:40 AM
#11
Re: Select some data of a text file and save it in a table
ams
Let's focus on this segment of your code ..
Code:
sString = TextBox1.text
For i = 1 To Len(txtOut.text)
If Mid(sString, 4, 4) = "mac-" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(1, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(1, 1) = Mid(sString, y + 1)
ElseIf Mid(sString, 4, 4) = "rx-r" Then
y = InStrRev(sString, "=")
Grid1.TextMatrix(2, 0) = Mid(sString, 4, y - 4)
Grid1.TextMatrix(2, 1) = Mid(sString, y + 1)
ElseIf Mid(sString, 4, 4) = "tx-r" Then
ElseIf Mid(sString, 4, 4) = "pack" Then
ElseIf Mid(sString, 4, 4) = "upti" Then
ElseIf Mid(sString, 4, 4) = "last" Then
ElseIf Mid(sString, 4, 16) = "signal-strength=" Then
ElseIf Mid(sString, 4, 8) = "signal-t" Then
ElseIf Mid(sString, 4, 16) = "signal-strength-" Then
End If
Next
I've added "ElseIf" and stripped out the branch contents beginning at the 3rd one for
display purposes .. that is, so we can see "at a glance" the beginning and end of your loop.
Couple of observations/questions.
- sString is now what?
- an extremely long single line string?
- multiple strings (ie, is TextBox1 a multi-line textbox?
- Your loop is based on txtOut
- where is that set in advance?
- where do you use the i in the loop?
Spoo
-
Sep 10th, 2017, 11:40 AM
#12
Thread Starter
Member
Re: Select some data of a text file and save it in a table
Hi Spoo! First of all thank you for your help.
sString is now mltiple strings. The TextBox1 is a multi-line textbox (sorry for the mistake: TextBox1 is the same as txtOut) you can call it as you want.
You are right. I don't use the variable i in the loop. I am a little lost with this code Can you provide me any solution?
Thanks in advanced!
-
Sep 10th, 2017, 05:20 PM
#13
Re: Select some data of a text file and save it in a table
ams
sString is now mltiple strings.
Could you show, say, 2 or 3 examples?
Spoo
-
Sep 10th, 2017, 05:30 PM
#14
Re: Select some data of a text file and save it in a table
1. How did the data get in the multi-line textbox in the first place? You should have put it into your grid THEN if you wanted in a grid...just like I showed you. If the textbox is filled from a textfile, and you want the grid to display the data somehow differently than displayed in the textbox, just do it when you populate the textbox.
2. Nothing....
-
Sep 10th, 2017, 09:12 PM
#15
Re: Select some data of a text file and save it in a table
If you have the data from the file in a multiline listbox (like text1), then this code will populate an MSFlexgrid (like Grid2), with the same information I showed in post #7 in Grid 1 from loading it directly from a text file:
Code:
Private Sub Command1_Click() 'load from textbox Dim mArray() As String
mArray = Split(Text1.Text, vbCrLf)
Dim x As Integer
Dim y As Integer
Dim sString As String
For x = 0 To UBound(mArray)
sString = mArray(x)
If Mid(sString, 4, 4) = "mac-" Then
y = InStrRev(sString, "=")
Grid2.TextMatrix(1, 0) = Mid(sString, 4, y - 4)
Grid2.TextMatrix(1, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "rx-r" Then
y = InStrRev(sString, "=")
Grid2.TextMatrix(2, 0) = Mid(sString, 4, y - 4)
Grid2.TextMatrix(2, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "tx-r" Then
y = InStrRev(sString, "=")
Grid2.TextMatrix(3, 0) = Mid(sString, 4, y - 4)
Grid2.TextMatrix(3, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "pack" Then
y = InStrRev(sString, "=")
Grid2.TextMatrix(4, 0) = Mid(sString, 4, y - 4)
Grid2.TextMatrix(4, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "upti" Then
y = InStrRev(sString, "=")
Grid2.TextMatrix(5, 0) = Mid(sString, 4, y - 4)
Grid2.TextMatrix(5, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 4) = "last" Then
y = InStrRev(sString, "=")
Grid2.TextMatrix(6, 0) = Mid(sString, 4, y - 4)
Grid2.TextMatrix(6, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 16) = "signal-strength=" Then
y = InStrRev(sString, "=")
Grid2.TextMatrix(7, 0) = Mid(sString, 4, y - 4)
Grid2.TextMatrix(7, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 8) = "signal-t" Then
y = InStrRev(sString, "=")
Grid2.TextMatrix(8, 0) = Mid(sString, 4, y - 4)
Grid2.TextMatrix(8, 1) = Mid(sString, y + 1)
End If
If Mid(sString, 4, 16) = "signal-strength-" Then
y = InStrRev(sString, "=")
Grid2.TextMatrix(9, 0) = Mid(sString, 4, y - 4)
Grid2.TextMatrix(9, 1) = Mid(sString, y + 1)
End If
Next x
Grid2.ColAlignment(1) = 2
-
Sep 17th, 2017, 04:33 PM
#16
Thread Starter
Member
Re: Select some data of a text file and save it in a table
Thank you! It works fine!,
And one last question...
The data in the TextBox is obtained of an API that is monitoring an access point all the time.
For know we have been working with the data of one device which is connected to the access point.
However, the size of that text is not constant. For instance, If we have two devices connected to the access point, the text of the textbox would be sometihg like:
Code:
O /interface/wireless/registration-table/print
O <<EOS>>
I !done
I =ret=d15ff96c7fdeff72115c92061f311726
I <<EOS>>
I !done
I <<EOS>>
I !re
I =.id=*2
I =interface=wlan1
I =mac-address=B8:64:91:68:1C:50
I =ap=false
I =wds=false
I =bridge=false
I =rx-rate=39Mbps-20MHz/1S
I =tx-rate=52Mbps-20MHz/1S
I =packets=404,459
I =bytes=41812,35732
I =frames=404,463
I =frame-bytes=42646,33428
I =hw-frames=878,1040
I =hw-frame-bytes=113641,67550
I =tx-frames-timed-out=0
I =uptime=9m3s
I =last-activity=60ms
I =signal-strength=-67@6Mbps
I =signal-to-noise=21
I =signal-strength-ch0=-67
I =evm-ch0=20
I =strength-at-rates=-66@1Mbps
I 15s580ms,-67@6Mbps
I 60ms,-69@HT20-1
I 1m7s410ms,-66@HT20-3
I 4m25s120ms,-69@HT20-4
I 570ms,-69@HT20-5
I 15s590ms,-68@HT20-6
I 5s580ms,-68@HT20-7
I 1m11s200ms
I =tx-ccq=87
I =p-throughput=47517
I =distance=1
I =last-ip=192.168.100.253
I =802.1x-port-enabled=true
I =authentication-type=wpa2-psk
I =encryption=aes-ccm
I =group-encryption=aes-ccm
I =management-protection=false
I =wmm-enabled=true
I =tx-rate-set=CCK:1-11
I OFDM:6-54
I BW:1x
I HT:0-7
I <<EOS>>
I !re
I =.id=*3
I =interface=wlan1
I =mac-address=14:7D:C5:A0:A0:93
I =ap=false
I =wds=false
I =bridge=false
I =rx-rate=26Mbps-20MHz/1S
I =tx-rate=24Mbps
I =packets=311,627
I =bytes=33353,50459
I =frames=311,630
I =frame-bytes=33977,47040
I =hw-frames=666,1654
I =hw-frame-bytes=90320,97614
I =tx-frames-timed-out=0
I =uptime=4m54s
I =last-activity=520ms
I =signal-strength=-80@HT20-3
I =signal-to-noise=8
I =signal-strength-ch0=-80
I =evm-ch0=13
I =strength-at-rates=-81@1Mbps
I 1s770ms,-83@2Mbps
I 2m29s140ms,-78@5.5Mbps
I 35s690ms,-79@HT20-0
I 3s650ms,-79@HT20-1
I 1s120ms,-79@HT20-2
I 3s480ms,-80@HT20-3
I 520ms,-78@HT20-4
I 1m5s390ms,-78@HT20-5
I 1m16s70ms,-72@HT20-6
I 3m32s30ms,-72@HT20-7
I 3m32s440ms
I =tx-ccq=76
I =p-throughput=14119
I =distance=1
I =last-ip=192.168.100.243
I =802.1x-port-enabled=true
I =authentication-type=wpa2-psk
I =encryption=aes-ccm
I =group-encryption=aes-ccm
I =management-protection=false
I =wmm-enabled=true
I =tx-rate-set=CCK:1-11
I OFDM:6-54
I BW:1x
I HT:0-7
I <<EOS>>
I !done
I <<EOS>>
How would be the code in this case? I would like to show in the table the data of the two devices. If they were more devices I would like to show their information to. So now the size of the table is variable and I don`t know how to program it
Thank you for your help another time!!
-
Sep 17th, 2017, 06:00 PM
#17
Re: Select some data of a text file and save it in a table
That info is Greek to me...how would I know which (what) device was capturing the data, and when? I'd suggest you use multiple textboxes and multiple girds (or listviews), one for each device...then you could use similar code for EACH textbox to the the information you want.
-
Sep 18th, 2017, 04:03 AM
#18
Thread Starter
Member
Re: Select some data of a text file and save it in a table
It is not important what device was capturing the data and when. My application do it each two minutes and them it shows that text in the textbox. My problem is that yoyr code is valid if there is only one device connected. But If I have two devices connected, the same text (with different values for the parameters of each device) appears two times sepparated with an EOS line. Do you know how to program that?
I want to show in the table the data of all the devices. I know that is more complicated and I don`t know if it is possible...
-
Sep 18th, 2017, 04:36 AM
#19
Re: Select some data of a text file and save it in a table
Absolutely (now that I know that the EOS line separates each device's inputs). What you do first is use the split() function to 'divide' the text of the textbox into an array of strings, splitting on the EOS line. That will give you an array of strings with an upper bound of the number of devices sending the data. Then, for each of THOSE array entries, use my code to split once again each entry into other arrays and then use my code to separate those lines you desired.
I hope you understand. IOW, if you have two devices, you will have two arrays initially. For each array, use my code to find the information you want to display.
-
Sep 19th, 2017, 04:37 AM
#20
Thread Starter
Member
-
Sep 19th, 2017, 05:43 AM
#21
Re: Select some data of a text file and save it in a table
I don't think I will 'pass you the code'. What I suggest is you look up in MSDN the Split() function. What parameters does it take, and what does it produce. Here's an example of Split()
Code:
Private Sub Command1_Click()
Dim myTextString As String
myTextString = "This is a string.<<EOS>>This is another string.<<EOS>>This is a third string."
Dim myTextArray() As String
myTextArray = Split(myTextString, "<<EOS>>")
Dim i As Integer
For i = 0 To UBound(myTextArray)
Debug.Print myTextArray(i)
Next i
End Sub
It will show:
This is a string.
This is another string.
This is a third string.
That's because it SPLITS the long string into three strings (in this example) using the string <<EOS>> to 'divide' it. These three strings are put into an array...i iterated through that array to show you HOW it is done. In your problem, first use SPLIT to divide your textbox lines into an array. Then you can use similar code to mine earlier to search for just those lines you want in each set of data per device.
Need YOU to do this (at least try), and then MAYBE I'll assist more if you need it.
Last edited by SamOscarBrown; Sep 19th, 2017 at 05:51 AM.
-
Sep 19th, 2017, 11:42 AM
#22
Thread Starter
Member
Re: Select some data of a text file and save it in a table
I pass you my solution. I think that it is well thought out but it doesn't work fine. My solution is:
First of all I split the text with "<<EOS>> separator in mArray
Then, in sString is saved each 'block' of text separated with "<<EOS>>. With the loop i I will do the next operations for each block of text.
The next operations for each block of text are:
First I divide the block of text line by line. Then, I select the data of my interest with your original code.
Finally I put the selected data in the grid. Previusly I have created a Rowcounter because depending of the numbrer of devices, the number of rows increases.
I don´t know what is the problem.
Code:
Private Sub GetData_Click()
Grid1.Visible = True
Grid1.Rows = 300
Grid1.Clear
Grid1.TextMatrix(0, 0) = "Field"
Grid1.TextMatrix(0, 1) = "Actual Valuel"
Dim i As Integer
Dim j, k As Integer
Dim mArray() As String
mArray = Split(txtOut.text, "<<EOS>>")
Dim sString, sString2 As String
Dim mArray2() As String
Dim Rowcounter As Integer
Rowcounter = 0
For i = 0 To UBound(mArray)
sString = mArray(i)
mArray2 = Split(mArray(i), vbCrLf)
For k = 0 To UBound(mArray2)
sString2 = mArray2(k)
If Mid(sString2, 4, 4) = "mac-" Then
Rowcounter = Rowcounter + 1
j = InStrRev(sString, "=")
Grid1.TextMatrix(Rowcounter, 0) = "MAC"
Grid1.TextMatrix(1, 1) = Mid(sString, j + 1)
End If
If Mid(sString2, 4, 4) = "rx-r" Then
Rowcounter = Rowcounter + 1
j = InStrRev(sString, "=")
Grid1.TextMatrix(Rowcounter, 0) = Mid(sString, 4, j - 4)
Grid1.TextMatrix(Rowcounter, 1) = Mid(sString, j + 1)
End If
If Mid(sString2, 4, 4) = "tx-r" Then
Rowcounter = Rowcounter + 1
j = InStrRev(sString, "=")
Grid1.TextMatrix(Rowcounter, 0) = Mid(sString, 4, j - 4)
Grid1.TextMatrix(Rowcounter, 1) = Mid(sString, j + 1)
End If
If Mid(sString2, 4, 4) = "pack" Then
Rowcounter = Rowcounter + 1
j = InStrRev(sString, "=")
Grid1.TextMatrix(Rowcounter, 0) = Mid(sString, 4, j - 4)
Grid1.TextMatrix(Rowcounter, 1) = Mid(sString, j + 1)
End If
If Mid(sString2, 4, 4) = "upti" Then
Rowcounter = Rowcounter + 1
j = InStrRev(sString, "=")
Grid1.TextMatrix(Rowcounter, 0) = Mid(sString, 4, j - 4)
Grid1.TextMatrix(Rowcounter, 1) = Mid(sString, j + 1)
End If
If Mid(sString2, 4, 4) = "last" Then
Rowcounter = Rowcounter + 1
j = InStrRev(sString, "=")
Grid1.TextMatrix(Rowcounter, 0) = Mid(sString, 4, j - 4)
Grid1.TextMatrix(Rowcounter, 1) = Mid(sString, j + 1)
End If
If Mid(sString2, 4, 16) = "signal-strength=" Then
Rowcounter = Rowcounter + 1
j = InStrRev(sString, "=")
Grid1.TextMatrix(Rowcounter, 0) = Mid(sString, 4, j - 4)
Grid1.TextMatrix(Rowcounter, 1) = Mid(sString, j + 1)
End If
If Mid(sString2, 4, 8) = "signal-t" Then
Rowcounter = Rowcounter + 1
j = InStrRev(sString, "=")
Grid1.TextMatrix(Rowcounter, 0) = Mid(sString, 4, j - 4)
Grid1.TextMatrix(Rowcounter, 1) = Mid(sString, j + 1)
End If
If Mid(sString2, 4, 16) = "signal-strength-" Then
Rowcounter = Rowcounter + 1
j = InStrRev(sString, "=")
Grid1.TextMatrix(Rowcounter, 0) = Mid(sString, 4, j - 4)
Grid1.TextMatrix(Rowcounter, 1) = Mid(sString, j + 1)
End If
Next k
Next i
Grid1.ColAlignment(1) = 2
End Sub
-
Sep 20th, 2017, 11:02 AM
#23
Thread Starter
Member
Re: Select some data of a text file and save it in a table
Anybody can help me?
-
Sep 21st, 2017, 12:24 AM
#24
Re: Select some data of a text file and save it in a table
Originally Posted by ams16
Anybody can help me?
Since you redefine your requirements, the reponses become sparse.
I can only guess, that you might want your multiple text-responses in multiple separate Grids?
If yes, place a TextBox (Text1) and an Array of two (or more) MSHFlexGrids (MSHFlexGrid1(0) and MSHFlexGrid1(1)) on a Form and check this out:
Code:
Option Explicit
Private Sub Form_Load()
Dim SArr() As String, i
SArr = Split(Replace(Replace(Text1.Text, "I =", ""), "O ", ""), "I !re")
For i = 1 To UBound(SArr)
FillGrid MSHFlexGrid1(i - 1), Filter(Split(SArr(i), vbCrLf), "=")
Next
End Sub
Private Sub FillGrid(FG As MSHFlexGrid, Lines)
FG.FormatString = "Properties|Values"
FG.Rows = FG.FixedRows + UBound(Lines) + 1
FG.Col = 0: FG.Row = 1
FG.ColSel = 1: FG.RowSel = UBound(Lines) + 1
FG.Clip = Replace(Join(Lines, vbCr), "=", vbTab)
FG.ColAlignmentFixed(0) = flexAlignLeftCenter
FG.ColAlignment(1) = flexAlignRightCenter
FG.ColWidth(-1) = 1800
FG.Col = 1
End Sub
Olaf
-
Sep 27th, 2017, 11:39 AM
#25
Thread Starter
Member
Re: Select some data of a text file and save it in a table
Thank you! Finally I solved it
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|