比较 4 列中的数据
Comparing Data in 4 Columns
我是新手 VB 我需要比较两列的地址。
如果两个地址匹配,则检查两个数据是否匹配,如果不匹配,则将源文件和转储文件地址和数据输出到文本文件。
如果A列的地址在C列中找不到,则将源文件地址和数据输出到文本文件中。
如果在A列中找不到C列中的地址,则将转储文件地址和数据输出到文本文件中。
希望有人能帮助我。谢谢!
Source File Dump File
a b c d
1 address data address data
2 s100 a s010 x
3 S010 x s020 b
4 S030 y S030 y
5 s040 z S040 d
一期
如果地址匹配,我认为它不会检查两个地址的数据是否相同。例如,源文件的地址为 's040',数据为 'z',但转储文件的地址为 's040',数据为 'd'
时间问题
有ard 900M次迭代,耗时很长。是否先删除重复项然后 运行 此搜索更好?我尝试使用 excel 的删除重复项功能,但它只适用于一列。整个周期需要25分钟。
如果连续地址在列表中是唯一的,则合并数据:
如果一列中有一大块唯一地址,我需要找到第一个唯一地址和最后一个唯一地址的起始地址以及
只输出那些不全是 FF 的行:
'If all the data are FF's output like this
File: dump.s19
0x006180 – 0x007E8F
[Result] OK
'Here certain lines are all FF's which are not displayed here, only Non FF's lines need to printed as follows.
File: dump.s19
0x007EB0 – 0x00FFFF
S224007FF0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4247494EFFFFFFFFFFFFFFFF0000FFFF66
S224008010FFFFFFFF01019D160825A100100201FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCA
S224008050302D4100E0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA8
S224008070FFFFFFFFFFFFFFFFFFFFA3BF454E442EFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9E
Result: NOK
我不确定如何将这个额外的逻辑集成到我的代码中。
'Set the address you're trying to find
fa = Range(sf & cr).Value
fa_data = Range(Chr(Asc(sf) + 1) & cr).Value
Debug.Print "fa" & fa
'Find it
Set targetcell = Range(si & 3 & ":" & si & lr_2).Find(What:=fa, LookIn:=xlValues, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True)
'If Nothing is returned it is not found
If targetcell Is Nothing Then
'Write your search cell and it's ajacent to your file.
If l = 1 Then
startadd = Range(sf & cr).Value
If startadd <> "FFFFFF" Then
Dec_startadd = Val("&H" & startadd & "&H")
lgth = Len(Range(Chr(Asc(sf) + 1) & cr)) - 2
lgth = lgth / 2 - 1
endadd = Hex(Dec_startadd + lgth)
endadd = Right("000000" & endadd, 6)
Print #fn, "File:" & orig_filename
Print #fn, "0x" & startadd & " - 0x" & endadd
Print #fn, Range(Chr(Asc(sf) - 1) & cr).Value & Range(sf & cr).Value & Range(Chr(Asc(sf) + 1) & cr).Value
Print #fn, "Result: NOK"
Print #fn,
Print #fn,
我只是为了好玩才搞出来的:
'Get a the next available file number
fn = FreeFile
'Open your file ready for writing.
Open "your full path and file name" For Output As #fn
'Set the First row to search from.
fr = 2
'Find the last row.
lr = ActiveCell.SpecialCells(xlLastCell).Row
'Set the column for the value that you are searching for.
sf = "A"
'Set the column for that you are searching in.
si = "C"
'You want to search two columns
For l = 1 To 2
'Loop from first row to the last row.
For cr = fr To lr
'Set the address you're trying to find
fa = Range(sf & cr).Value
'Find it
Set targetcell = Range(si & fr & ":" & si & lr).Find(What:=fa, LookIn:=xlValues, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
'If Nothing is returned it is not found
If targetcell Is Nothing Then
'Write your search cell and it's ajacent to your file.
Write #fn, Range(sf & cr).Value & "," & Range(Chr(Asc(sf) + 1) & cr).Value
End If
'I always put a DoEvents in a loop; just in case you need to break out of it.
DoEvents
Next
'Now you've done one column swap them over and do it again.
sf = "C"
si = "A"
Next
'It's done.
Close #fn
我是新手 VB 我需要比较两列的地址。
如果两个地址匹配,则检查两个数据是否匹配,如果不匹配,则将源文件和转储文件地址和数据输出到文本文件。
如果A列的地址在C列中找不到,则将源文件地址和数据输出到文本文件中。
如果在A列中找不到C列中的地址,则将转储文件地址和数据输出到文本文件中。
希望有人能帮助我。谢谢!
Source File Dump File
a b c d
1 address data address data
2 s100 a s010 x
3 S010 x s020 b
4 S030 y S030 y
5 s040 z S040 d
一期
如果地址匹配,我认为它不会检查两个地址的数据是否相同。例如,源文件的地址为 's040',数据为 'z',但转储文件的地址为 's040',数据为 'd'
时间问题
有ard 900M次迭代,耗时很长。是否先删除重复项然后 运行 此搜索更好?我尝试使用 excel 的删除重复项功能,但它只适用于一列。整个周期需要25分钟。
如果连续地址在列表中是唯一的,则合并数据:
如果一列中有一大块唯一地址,我需要找到第一个唯一地址和最后一个唯一地址的起始地址以及 只输出那些不全是 FF 的行:
'If all the data are FF's output like this
File: dump.s19
0x006180 – 0x007E8F
[Result] OK
'Here certain lines are all FF's which are not displayed here, only Non FF's lines need to printed as follows.
File: dump.s19
0x007EB0 – 0x00FFFF
S224007FF0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4247494EFFFFFFFFFFFFFFFF0000FFFF66
S224008010FFFFFFFF01019D160825A100100201FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCA
S224008050302D4100E0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA8
S224008070FFFFFFFFFFFFFFFFFFFFA3BF454E442EFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9E
Result: NOK
我不确定如何将这个额外的逻辑集成到我的代码中。
'Set the address you're trying to find
fa = Range(sf & cr).Value
fa_data = Range(Chr(Asc(sf) + 1) & cr).Value
Debug.Print "fa" & fa
'Find it
Set targetcell = Range(si & 3 & ":" & si & lr_2).Find(What:=fa, LookIn:=xlValues, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True)
'If Nothing is returned it is not found
If targetcell Is Nothing Then
'Write your search cell and it's ajacent to your file.
If l = 1 Then
startadd = Range(sf & cr).Value
If startadd <> "FFFFFF" Then
Dec_startadd = Val("&H" & startadd & "&H")
lgth = Len(Range(Chr(Asc(sf) + 1) & cr)) - 2
lgth = lgth / 2 - 1
endadd = Hex(Dec_startadd + lgth)
endadd = Right("000000" & endadd, 6)
Print #fn, "File:" & orig_filename
Print #fn, "0x" & startadd & " - 0x" & endadd
Print #fn, Range(Chr(Asc(sf) - 1) & cr).Value & Range(sf & cr).Value & Range(Chr(Asc(sf) + 1) & cr).Value
Print #fn, "Result: NOK"
Print #fn,
Print #fn,
我只是为了好玩才搞出来的:
'Get a the next available file number
fn = FreeFile
'Open your file ready for writing.
Open "your full path and file name" For Output As #fn
'Set the First row to search from.
fr = 2
'Find the last row.
lr = ActiveCell.SpecialCells(xlLastCell).Row
'Set the column for the value that you are searching for.
sf = "A"
'Set the column for that you are searching in.
si = "C"
'You want to search two columns
For l = 1 To 2
'Loop from first row to the last row.
For cr = fr To lr
'Set the address you're trying to find
fa = Range(sf & cr).Value
'Find it
Set targetcell = Range(si & fr & ":" & si & lr).Find(What:=fa, LookIn:=xlValues, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
'If Nothing is returned it is not found
If targetcell Is Nothing Then
'Write your search cell and it's ajacent to your file.
Write #fn, Range(sf & cr).Value & "," & Range(Chr(Asc(sf) + 1) & cr).Value
End If
'I always put a DoEvents in a loop; just in case you need to break out of it.
DoEvents
Next
'Now you've done one column swap them over and do it again.
sf = "C"
si = "A"
Next
'It's done.
Close #fn