Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading data from file... problems 1

Status
Not open for further replies.

QTip

Programmer
Mar 7, 2001
66
BE
Hello,

I have written this program in VB6. It read certain html files. The files have some standard text that is the same in each of this html files. Behind this standard text are variables.
I have to read these variables in a database (can't use asp or stuff because the html-files are coming from a third person.)
Everything goes well and all data is being written in the database, UNTIL I reach a comma in the variables...

When there is a comma, my program keeps looping a certain part and I can't stop it.

Here is a part of the code:

If InStr(RawData, &quot;Title:&quot;) <> 0 Then //searches the word
title (standard text)
in the html file
place = InStr(RawData, &quot;Title:&quot;)
length = Len(&quot;Title:&quot;)
length2 = length + place
character = Mid(RawData, length2, 1)
counter = 0
Do While character <> &quot;<&quot; // it keeps looping here when
the character is a comma
str10 = str10 + character
counter = counter + 1
place2 = length2 + counter
character = Mid(RawData, place2, 1) //when character
should be a comma,
it displays as an
empty string in
the debugger and
keeps giving an
empty string.
Loop
MsgBox (str10)
End If

for example:
If I have to read the variable 40,5 ... it goes well until the 0, but after that I keep getting a blank space in stead of a comma. This is when I use the debugger. When I use the program normally, it's in a unlimited loop and I can't get out of the program.

What am I doing wrong!!!! Can somebody help me? Thanks!
 
I'm not sure your problem is with a comma so much as it is that the string doesn't have a &quot;<&quot; in it.

The way you use the loop:
Do While character <> &quot;<&quot;

will continue forever if your string doesn't have a &quot;<&quot; in it character.
 
The comma problem doesn't make sense to me either but this little code fragment works OK and it provides some protection against an infinite loop.

Private Sub Command4_Click()
MsgBox ParseStuff(&quot;Title: 1,2,3<,This should be ignored&quot;)
End Sub

Private Function ParseStuff(RawData As String) As String
Dim str10 As String
Dim length2 As Integer
Dim character As String
Dim n As Integer

If InStr(RawData, &quot;Title:&quot;) <> 0 Then

length2 = InStr(RawData, &quot;Title:&quot;) + Len(&quot;Title:&quot;)

For n = length2 To Len(RawData)
character = Mid(RawData, n, 1)
If character = &quot;<&quot; Then Exit For
str10 = str10 & character
Next n

ParseStuff = str10
Else
ParseStuff = &quot;&quot;
End If

End Function

 
I already tested it without a comma and then it works perfectly.
The string rawdata contains the data from the external file and there are many &quot;<&quot;. The external file is a html file and I collect everything in the string rawdata. Then I search for the word &quot;title:&quot;. After that we have the title (variable) that I need and after that the html code starts again with &quot;<&quot;. So I need everything behind &quot;title&quot; until the &quot;<&quot;. Everything goes well until I have comma in the variable.

I really don't see what my problem can be.
I hope I made the situation a little clearer for you guys.

Greetz!
 
the thing with the comma is really strange.
When I do something like this Mid(RawData, 1, 20) where there is no comma in the RawData string, I get without any problems the 20 characters I need. When I do the same where the RawData string contains something like 40,654563218, I get 40 . Everything before the comma displays correcty, but after that I get blank lines...

... Just to let you know what the output was.
Hope somebody can help.

Thnx!
 
How are you actually getting the RawData variable? If you use some of the file reading functions a comma may be interpreted as an end of data marker. You could prove this with a Debug.Print RawData before you do your Instr

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I get the RawData variable with next code:

Open &quot;C:\test.html&quot; For Input As #1
Input #1, RawData
...


I'm not familiar with the Debug.Print RawData
How and where should I use it?

Thnx!
 
Input #1, RawData is intended to read data from a file which has been formatted in a specific way (normally with a Write # statement). It sees commas as data delimiters.

Try changing to:
Dim f as Long
Dim FLen as Long
f = FreeFile 'gets first available filenumber
open &quot;c:\ht.htm&quot; For Input As #f
FLen = Filelen(&quot;c:\ht.htm&quot;)
RawData = Input(FLen, #1)


This will get the whole file into your Rawdata variable.

The Debug.Print statement prints the value to the Immediate window (CTRL G)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
ok, I used the Debug.Print function and I think my problem is in the RawData string.
It doens't display all the characters right.

So now I really don't know how to do it.
Can somebody tell me how he would do it?
So, read data from html file and get specific data from it (searching on some keywords that are the same in each html file I recieve).

Anybody?

Thanks!
 
Did you try the first part of my answer? (Hint: I have actually tried it [smile])

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Whoohoow!! Thanks man, it's working!!
 
You're welcome!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top