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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyone like a challenge?

Status
Not open for further replies.

Newbie311

Programmer
Oct 6, 2003
30
GB
Hi There,
I just need to modify the following code to display the first value it finds.I.E there are 2 bios dates in a text file however i just need the first instance.P.S currently the statement below returns me 2 instances of bios date and i only require the first 1 found!
Much Appreciated if you can help!
Thanks

If InStr(1, GetLine, "BIOS Date") > 0 Then 'Search for Bios Date

ActiveCell.Offset(b, 2).Value = GetLine
ActiveCell.Offset(b, 2).Value = Trim(Mid(ActiveCell.Offset(b, 2).Value, Len("BIOS Date: "), 15))
b = b + 1



End If
 
Could you post the exact value that is being returned, or say waht format the dates are returned in.

A.C.
 
An Example of the exact value would be any date,i.e. 08/10/2002. In the text file however there are two different bios dates and i only require the first one.
 
Why don't you simply define a boolean variable:
Dim FoundIt as Boolean

FoundIt=False
'...

If InStr(1, GetLine, "BIOS Date") > 0 And Not FoundIt Then 'Search for Bios Date
ActiveCell.Offset(b, 2).Value = GetLine
ActiveCell.Offset(b, 2).Value = Trim(Mid(ActiveCell.Offset(b, 2).Value, Len("BIOS Date: "), 15))
b = b + 1
FoundIt=True
End If
[wavey3]
MakeItSo!
 
Hi there I tried defining a boolean variable however it still displays both bios dates. :-( I need the code to stop searching for the next bios date as soon as it finds the first 1.
 
Could you let us know what value is returned by :

[tab]ActiveCell.Offset(b, 2).Value = GetLine

To esatblish that just type Stop as the next line of code.

A.C.
 
The GetLine variable holds a string,in the above case it is holding the date and therefore returning the BIOS date.The line after the "GetLine" Is used to extract the string from the right position..Its then displayed on an excel spreadsheet."B" is used to increment rows i.e. display bios dates one after the other from top to bottom.I just need the first instance of BIOS Date to be extracted from the file whereas i am currently getting two BIOS dates.
 
it seems, your code is within a Find loop. Then you could either say
If FoundIt then Exit Do or whatever your loop is, or
something like
If FoundIt then Goto Skipper
whereas Skipper is a Jump mark outside your Find block:

Skipper:

End Sub

I'm quite certain, the solution is simply too easy to be seen... :cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top