|
-
Nov 7th, 2002, 04:18 AM
#1
Thread Starter
Lively Member
Need ur advise
Need your advise badly. Below code doesn't work. Any idea where I can resolve this??Any help is greatly appreciated
Private Sub cmdValidate_Click()
Const ForReading = 1, ForWriting = 2
Dim RawdataStr As String
Dim RawStream
Dim i
Dim CAT(1 To 10) As Integer
Dim AllTotal As Integer
Open "a:\text.txt" For Input As #1
Do Until EOF(1)
DoEvents
Line Input #1, RawdataStr
If InStr(RawdataStr, " 774 ") = 0 Then
'If 774 found on a line
'''''''''''How to make the below part simpler???''''''''''''''''''''''
CAT1 = Mid(RawdataStr, 25, 4) 'eg output = 0101
CAT2 = Mid(RawdataStr, 29, 4) '0000
CAT3 = Mid(RawdataStr, 33, 4) '1516
CAT4 = Mid(RawdataStr, 37, 4) '1771
CAT5 = Mid(RawdataStr, 41, 4) '9009
CAT6 = Mid(RawdataStr, 45, 4) '1111
CAT7 = Mid(RawdataStr, 49, 4) '1122
CAT8 = Mid(RawdataStr, 53, 4) '0000
CAT9 = Mid(RawdataStr, 57, 4) '0000
CAT10 = Mid(RawdataStr, 61, 4) '7878
''''''''''How to add all value from CAT1 to CAT 10??''''''''''''''''''
For i = 1 To 10
AllTotal = AllTotal + CAT(i)
Next i
MsgBox AllTotal & ": is the total amount"
End
End If
Loop
Close #1
End Sub
-
Nov 7th, 2002, 04:21 AM
#2
Junior Member
What doesn't work, do you receive an error, what error ?
in the line If InStr(RawdataStr, " 774 ") = 0 Then is a space in front of 774, is this correct ?
Nobody is perfect. Hi !! My name is nobody...
-
Nov 7th, 2002, 04:23 AM
#3
Retired VBF Adm1nistrator
Re: Need ur advise
Originally posted by skyseh
If InStr(RawdataStr, " 774 ") = 0 Then
'If 774 found on a line
Haven't tested your code or anything, but the above line isn't true.
If InStr(...) = 0, that means that "774" was not found on a line.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 7th, 2002, 04:27 AM
#4
Re: Need ur advise
Originally posted by skyseh
Dim intStart As Integer, intIndex As Integer
'''''''''''Here's how to make the below part simpler''''''''''''''''''''''
' First, change CATx to an array i.e. Dim Cat(1 To 10) As String
intIndex = 1
For intStart = 25 To 61 Step 4
Cat(intIndex) = Mid$(RawdataStr, intStart, 4)
AllTotal = AllTotal + Cat(intIndex)
intIndex = intIndex + 1
Next
MsgBox AllTotal & ": is the total amount"
'Etc etc
-
Nov 7th, 2002, 04:34 AM
#5
Frenzied Member
You could make your own type and fill it with a line of the text file
Like plenderj mentioned it isn't found when result is 0
You should change it to
VB Code:
If InStr(RawdataStr, " 774 ") <> 0 Then
'then it is found
But your ending your program to wiht the End statement
If you want only to count the total of all the lines where 774 is included then you can rewrite it to
VB Code:
Private Sub cmdValidate_Click()
Const ForReading = 1, ForWriting = 2
Dim RawdataStr As String
Dim RawStream
Dim AllTotal As Integer
'initialize all total
AllTotal = 0
' SURE IT WILL NOT EXCEED AN INTEGER VALUE ???
Open "a:\text.txt" For Input As #1
Do Until EOF(1)
DoEvents
Line Input #1, RawdataStr
If InStr(RawdataStr, " 774 ") = 0 Then
'If 774 found on a line
'add to all total the values
AllTotal = AllTotal + Mid(RawdataStr, 25, 4) 'eg output = 0101
AllTotal = AllTotal + Mid(RawdataStr, 29, 4) '0000
AllTotal = AllTotal + Mid(RawdataStr, 33, 4) '1516
AllTotal = AllTotal + Mid(RawdataStr, 37, 4) '1771
AllTotal = AllTotal + Mid(RawdataStr, 41, 4) '9009
AllTotal = AllTotal + Mid(RawdataStr, 45, 4) '1111
AllTotal = AllTotal + Mid(RawdataStr, 49, 4) '1122
AllTotal = AllTotal + Mid(RawdataStr, 53, 4) '0000
AllTotal = AllTotal + Mid(RawdataStr, 57, 4) '0000
AllTotal = AllTotal + Mid(RawdataStr, 61, 4) '7878
MsgBox AllTotal & ": is the total amount"
' commented the End part , this stops your program
' End
'or use action_sa his method, replying same time
'For intStart = 25 To 61 Step 4
' AllTotal = AllTotal + Mid$(RawdataStr, intStart, 4)
'Next
End If
Loop
Close #1
End Sub
Last edited by swatty; Nov 7th, 2002 at 04:38 AM.
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 7th, 2002, 04:43 AM
#6
Thread Starter
Lively Member
statement
Well I knew
If InStr(RawdataStr, " 774 ") = 0 Then
..
is a mistake. Surprisingly, it only execute the if statement when I omit the Not which is in front of InStr(as mentioned by plenderj or put an else...
I wonder why too...
-
Nov 7th, 2002, 04:47 AM
#7
Frenzied Member
Did you read all reply's, and have you still got problems ??
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 7th, 2002, 04:49 AM
#8
Junior Member
Nobody is perfect. Hi !! My name is nobody...
-
Nov 7th, 2002, 07:05 PM
#9
Thread Starter
Lively Member
Yea I have read and tried axion_sa's...thanks so much axion_sa for sharing and giving me such a valuable tip. Next i shall try on swatty's. thanks thanks for all helps
-
Nov 8th, 2002, 04:11 AM
#10
Thread Starter
Lively Member
Close to end
I am close to completing my program....btw I would appreciate if any of you can solve my last problem..
The loop will continue to search for the keyword "774".
For the first found "774" my program will perform some calculations.
What if the textfile contain more than one "774" which exist in some other line in the same file? I want my program to execute the same thing as the first.
Thanks!...I am using axion_sa algo
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
|