質問

I am creating a program that will generate a report using VB6. To do this I want to parse the raw data from a CSV file, adding it to arrays.

I have 3 arrays: for Array1 contains the field names; Array2 is for the first value and Array3 is for the second value. How can I find the value that I need inside the Array?

**The following is sample data**
*This is the first line*

Sent Messages ULR SDC-Talisay
Sent Messages AIR MMEVAL2.globe.com.ph
Sent Messages AIA Sybase-IPX-1
Received Messages NOR Sybase-IPX-2
Peer Average Roundtrip Time DEATALISAY1.globe.com.ph
Received Messages AIR MMEVAL1.globe.com.ph
Sent Messages PUA HHSSTLC-1
Received Messages ULR MMELHG1.globe.com.ph
Received Messages NOR Syniverse-CHI
Pending Requests ULR Sybase-IPX-1
Received Messages ULR MMESJN2.globe.com.ph
Sent Messages CLR fep-Sybase-sctp
Sent Messages AIA MMETB.globe.com.ph
Pending Requests IDR MMESJN2.globe.com.ph
Roundtrip Time PUR Globe-Telstra-Telecom
Received Messages CLA fep-Local-sctp
Parsed Messages ULR
Received Messages DSA MMESJN3.globe.com.ph
Received Messages NOR Syniverse-DAL
Received Messages AIA HHSSVLO-2
Timeout Events NOR HHSSTLC-1
Received Bytes HHSSVLO-2
Received Messages AIA HHSSTSY-3
Sent Messages AIR Syniverse-CHI
Received Messages NOA Citic-MEG
Received Messages AIA HHSSTLC-4
Sent Messages AIR MMELHG1.globe.com.ph'

*Second line*

0
0
0
0
0
84.8
0
1836.6
0
0
14681.13
118.97
0
0
0
1909.6
23791.67
0
0
0
0
0
0
0
0
0
0

The third line is like the first line, and the fourth line is like the second line, and so on.

And this is the data that has a computation.

All the field names that contain Parsed Messages, Received Messages, Received Bytes, Sent Bytes and Sent Messages should have a computation and the should not be computed

役に立ちましたか?

解決

loop through the array and check each item wether it fullfills the condition you are looking for

for example:

'1 form with:
'  1 command button: name=Command1
Option Explicit

Private mstrArray() As String

Private Sub Command1_Click()
  Dim lngFoundIndex As Long
  Dim strFind As String
  strFind = "hre"
  lngFoundIndex = FindValIndex(strFind)
  MsgBox strFind & " found at index " & CStr(lngFoundIndex), vbInformation, "Result"
End Sub

Private Function FindValIndex(strVal As String) As Long
  Dim lngIndex As Long
  'set return value in case nothing is found
  FindValIndex = -1
  'loop through all items of the array
  For lngIndex = 0 To UBound(mstrArray)
    If InStr(mstrArray(lngIndex), strVal) > 0 Then
      'set return value to found index
      FindValIndex = lngIndex
      Exit For
    End If
  Next lngIndex
End Function

Private Sub Form_Load()
  'fill the array with some example data
  mstrArray = Split("one,two,three,four", ",")
End Sub

The above code looks for items which are exactly the same as the string you are looking for. If you are looking for items containing the string you are looking for then you should have a look at the Instr() function

[EDIT]

I changed the above code to use Instr()

他のヒント

The raw data does not seem CSV formatted. Assuming it is as given above, you can use the Split() to convert the CHR(13) to a string array and then iterate through that array removing/selecting only valid items.

PS: You will still have CHR(10) at the end of each line, so strip them as well before processing the array

For more help on VB6 http://www.thevbprogrammer.com/classic_vbtutorials.asp

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top