May 29, 2024, 04:42:40 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


INSTR problem?

Started by billhsln, January 05, 2018, 11:22:35 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

When I do:

DEF ifilename,ufilename:STRING
DEF i:INT

ifilename = "I20 Items Sold 2017-12-25 to 2017-12-31 I20.xls"
ufilename = UCASE$(ifilename)

i = INSTR(ufilename,"ITEMS SOLD")
PRINT i


I prints the correct value of 5. when I pull this as a filename using:

fpath = "C:\\Users\\Bill\\OneDrive\\Files\\"

dir = FINDOPEN(fpath + "*.*")
IF (dir)
DO
ifilename = FINDNEXT(dir,attrib)
IF ifilename <> "" AND MID$(ifilename,1,1) <> "."
ufilename = UCASE$(ifilename)
ofilename = ifilename
tpath = ""
SELECT TRUE
CASE INSTR(ufilename,"ITEMS SOLD")
tpath = "C:\\Users\\Bill\\Documents\\CSB\\"
....
ENDSELECT
ENDIF
ENDWHILE
ENDIF


This does not find the value.  Is there some kind of difference in what is returned if it is a filename?

Bill
When all else fails, get a bigger hammer.

Egil

January 05, 2018, 12:00:52 PM #1 Last Edit: January 05, 2018, 12:04:18 PM by Egil
Bill,
I can't remember that I have ever used CASE the way you do in your example. But I think you have to find  the position first, and then use CASE [position].
Or maybe if the string searched for always is in the same position, use:
CASE INSTR(ufilename,"ITEMS SOLD") = [position]

With [position] assigned the value you expect to find it when using INSTR


Good Luck!
Support Amateur Radio  -  Have a ham  for dinner!

billhsln

I know it looks weird, but it does work, at least for any that the string I am searching for starts in column 1:

SELECT TRUE
CASE INSTR(ufilename,"OLDDELETEDLOT")
tpath = "C:\\Users\\Bill\\Documents\\Minimax\\MiniMaxB\\"
CASE INSTR(ufilename,"HALFSHEET_")
tpath = "C:\\Users\\Bill\\Documents\\Minimax\\MiniMaxB\\HalfSheets\\"
CASE INSTR(ufilename,"LOT 18")
tpath = "C:\\Users\\Bill\\Documents\\Minimax\\MiniMaxB\\SS\\"
CASE INSTR(ufilename,"LOT18")
tpath = "C:\\Users\\Bill\\Documents\\Minimax\\Install\\"
CASE INSTR(ufilename,"YES_DS100")
tpath = "C:\\Users\\Bill\\Documents\\Minimax\\MiniMaxB\\DS Data\\"
CASE MID$(ufilename,5,5) = "ITEMS"
CASE& MID$(ufilename,9,5) = "ITEMS"
'CASE INSTR(ufilename,"ITEMS SOLD")
tpath = "C:\\Users\\Bill\\Documents\\CSB\\Cindy\\"


All of these work except for "ITEMS SOLD", so I used MID$ instead of INSTR, which does work.  The main difference between all of these and the ITEMS SOLD is that ITEMS SOLD does not start as the first char.

Bill
When all else fails, get a bigger hammer.

billhsln

Just reread what you said and you are right, I need the condition to be TRUE and the INSTR's return a value, not TRUE, which I think TRUE = 1, so it works for those that have the string starting in column 1, but not for those that do not.  I need to change to INSTR(a$,"Text") > 0, which would return true.

Thanks,
Bill
When all else fails, get a bigger hammer.

LarryMc

I was fixin' to tell you that you had answered your own question with
QuoteThe main difference between all of these and the ITEMS SOLD is that ITEMS SOLD does not start as the first char.
the key is the definition of INSTR
it returns the char position of the start of the searched for string in the searched in string and if it isn't found it returns 0.so where it worked for you it was returning 1 (the start of the string) which also equates to TRUE
and on the one that failed it returned a number greater than 1 because it was there but just not at the beginning.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library