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

Need help understanding a piece of code 1

Status
Not open for further replies.

Luiz Eduh

Technical User
Jan 10, 2012
51
US
Hello,

I came across this piece of code in a program but I cant seem to fully understand its purpose or what it does. Can someone if possible explain me what would be the purpose of this? Here's the code;

Code:
     if m->item # '        ' .and. ;
         !(subs(m->item,3,1)>=chr(48).and.subs(m->item,3,1)<=chr(57))
         set order to 2
         seek trim(m->item)
         if found()
            save screen to tempscrn
            do dbrowse with 'xapha_br'
 
That looks a lot like Clipper code, maybe Fox2X or dBase, to me (the -> notation indicates that)

The code looks for an item which is not blank, and for which the third character along falls outside the ASCII range 48 to 57 (0-9 essentially).
If so, the currently open table is set to a matching order and whatever the item is searched for, if it is found the screen is saved and a browse window opened.


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Thank you!!!
One more question, how can I modify this part of the code to accept the following input on the item field;
Lets say I want to input this on that item field; MBT1006 or vise versa 1006MBT or 12345 or simply a 2 letter input TE (any combination of 2 letters)
 
Remove the restrictions on item:

Code:
if m->item # '        ' [highlight #EF6969][s].and. ;
         !(subs(m->item,3,1)>=chr(48).and.subs(m->item,3,1)<=chr(57))[/s][/highlight]

Bye, Olaf.

Olaf Doschke Software Engineering
 
That's a bit harder, I would need to see more of the existing code, but in essence you would need to follow up the checks for empty and the third character with a 'fall back situation' where instead of SEEKing a value, you might LOCATE one where alltrim(M->ITEM) $ ITEMCODE - where ITEMCODE is the field from the current work area that matches the item number.

Without seeing more of the code, the data structure, the index expressions and, perhaps, examples of the contents of your ITEMCODE field it is all guesswork though.

Jolly good luck to you.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
By the way, also VFP can understand ->, it's just more convenient to write dots. I don't know if Clipper also has the m Memory object, so this indeed is VFP code.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Olaf makes a good start, removing the restrictions goes part the way, but you need some way to 'handle' the users (presumably) input depending on what they are looking for.

If it's anything beginning MTB then the above code (without the restrictions) will probably go some way if most of your data begins with a three character code...

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
I think the -> notation is valid in Clipper - I compiled it in a Sum87 test and there were no errors - I have never used it in VFP, but hey it works!

Not sure that one counts as learning something 'new' for today though, B-)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
The next function can give you some ideas:
Code:
CLEAR 
?[MBT1006],GoodString([MBT1006])
?[1006MBT],GoodString([1006MBT])
?[12345],GoodString([12345])
?[TE],GoodString([TE])

?[Only alpha but too many (not exactly 2)],[TEA],GoodString([TEA])
?[Two few alpha], [TE3210],GoodString([TE3210])
?[Two few digits],[TEA321],GoodString([TEA321])
?[Two few alpha],[0123TE],GoodString([0123TE])
?[Two few digits],[123TEA],GoodString([123TEA])
?[Two many alpha], [TEME3210],GoodString([TEME3210])
?[Two many alpha], [TEM321R],GoodString([TEM321R])
?[Scrambled], [012ABC3],GoodString([012ABC3])
?[Scrambled], [AB0123C],GoodString([AB0123C])

FUNCTION GoodString
LPARAMETERS tcString
LOCAL lnAlphaLen,lnDigitLen,lnOnlyAlphaMax,llGood,llFirstAlpha,lnChar
* string containing only digits
* or
* string containing exactly 2 alphabetic characters
* or
* strings composed exactly by 3 alphabetic characters folowed by 4 digits
* or
* strings composed exactly by 4 digits folowed by 3 alphabetic characters 
lnAlphaLen = 3 
lnDigitLen = 4
lnOnlyAlphaMax = 2
llGood = LEN(CHRTRAN(m.tcString,[0123456789],[])) = 0 && only digits
IF !m.llGood 
	llGood = LEN(CHRTRAN(m.tcString,[ABCDEFGHIJKLMNOPQRSTUVWXYZ],[])) = 0 and LEN(m.tcString) = m.lnOnlyAlphaMax && exactly 2 alphabic characters
	IF !m.llGood
		llGood = LEN(CHRTRAN(m.tcString,[ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789],[])) = 0 and m.lnAlphaLen + m.lnDigitLen = LEN(m.tcString)
		IF m.llGood && only digits and alphabetic characters
			llFirstAlpha = ISALPHA(m.tcString)
			IF m.llFirstAlpha && first char is alphabetic
				FOR lnChar = 2 TO m.lnAlphaLen &&LEN(m.tcString)
					llGood = ISALPHA(SUBSTR(m.tcString, m.lnChar, 1))
					IF !m.llGood
						EXIT 
					ENDIF
				NEXT
				IF m.llGood
					FOR lnChar = m.lnAlphaLen + 1 TO LEN(m.tcString)
						llGood = ISDIGIT(SUBSTR(m.tcString, m.lnChar, 1))
						IF !m.llGood
							EXIT 
						ENDIF
					NEXT
				ENDIF
			ELSE && first char is digit
				FOR lnChar = 2 TO m.lnDigitLen &&LEN(m.tcString)
					llGood = ISDIGIT(SUBSTR(m.tcString, m.lnChar, 1))
					IF !m.llGood
						EXIT 
					ENDIF
				NEXT
				IF m.llGood
					FOR lnChar = m.lnDigitLen + 1 TO LEN(m.tcString)
						llGood = ISALPHA(SUBSTR(m.tcString, m.lnChar, 1))
						IF !m.llGood
							EXIT 
						ENDIF
					NEXT
				ENDIF
			ENDIF
		ENDIF
	ENDIF
ENDIF
RETURN m.llGood

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
To me it seems you only want to be able to search items with any name or whatever field is indexed in tag #2 in your table, so you only check, whether the user input is empty or not before you seek, you could even remove the if overall, you will just more often find nothing.

Bye, Olaf.

Olaf Doschke Software Engineering
 
I think the -> notation is valid in Clipper - I compiled it in a Sum87 test and there were no errors - I have never used it in VFP, but hey it works!

It started in dBase so of course it's valid. You can even use it for object references:

Code:
WAIT WINDOW THISFORM->CAPTION

It's just SO much harder to type than . [pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top