Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Understanding REPLACE command - why I don't get the erro
Message
 
 
To
09/03/2002 21:43:18
Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00630443
Message ID:
00630939
Views:
23
Mike,

In your program the error was in UDF itself, not in the Speed table. That's the difference...

Here is a modified version of your program, which should produce an error, but it doesn't:
create table SPEED.dbf free ;
	(Spd_ID I, ;
	Spd_Char C(10), ;
	Spd_Num N(2), ;
	Spd_Date D, ;
	Spd_DT t)
local lnI, lnX, Spd_ID, Spd_Char, Spd_Date, Spd_DateTime
for lnI = 1 to 100
	Spd_ID = m.lnI
	Spd_Char = str(m.lnI)
*This will give me a set of records
*with the same date / date time.
	lnX = m.lnI/100
	Spd_Date = {^2000-01-01}+m.lnX
	Spd_DT = {^2000-01-01 00:00:00}+m.lnX
	insert into SPEED from memvar
	if mod(m.lnI,1000) = 0
		wait window str(m.lnI) nowait
	endif
endfor
index on Spd_ID tag Spd_ID
index on Spd_Char tag Spd_Char
index on Spd_Date tag Spd_Date
index on Spd_DT tag Spd_DT
close all


use SPEED in 0
select speed
replace Spd_Num with 10000, Spd_Char with myudf(1000) all

return

function myudf
lparameters tiID
local lnSelect
lnSelect = select()
select 0
if !used("mylog")
	create cursor mylog (log_id n(10))
endif
append blank in mylog
replace log_id with m.tiID in mylog
select (lnSelect)
return str(m.tiID)
----------

BTW, I've added few comments about MatXTab. The problem is, I'm not that familiar with this utility. I tried it on few particular samples and got some errors. I reported them to Val and sent him a data file to reproduce. I was able to make another file in Downloads section (FastXTab) to work for my particular need, I made few enhancements in this program and sent them to the author, I also created a list of requests for this utility and Alexander is working on it, though he is very limited in time...


>Nadya
>
>Instead of trying to work with your piece of code and your guesses at what's wrong, why not see if the code I've provided produces the same results for you. I always start with a simpler example before moving to the more complex. If I want people to replicate my findings, I provide a complete example that they can run.
>
>I think we have to dismiss some of your guesses, so we can better understand what you're seeing.
>
>First, here's the code to create speed.dbf.
>
>CREATE TABLE SPEED.DBF FREE ;
> (Spd_ID I, ;
> Spd_Char C(10), ;
> Spd_Date D, ;
> Spd_DT T)
>LOCAL lnI, lnX, Spd_ID, Spd_Char, Spd_Date, Spd_DateTime
>FOR lnI = 1 TO 1000000
> SPD_ID = m.lnI
> SPD_CHAR = STR(m.lnI)
> *This will give me a set of records
> *with the same date / date time.
> LNX = m.lnI/100
> SPD_DATE = {^2000-01-01}+m.lnX
> SPD_DT = {^2000-01-01 00:00:00}+m.lnX
> INSERT INTO SPEED FROM MEMVAR
> IF MOD(m.lnI,1000) = 0
> WAIT WINDOW STR(m.lnI) NOWAIT
> ENDIF
>ENDFOR
>INDEX ON SPD_ID TAG SPD_ID
>INDEX ON SPD_CHAR TAG SPD_CHAR
>INDEX ON SPD_DATE TAG SPD_DATE
>INDEX ON SPD_DT TAG SPD_DT
>
>
>Here's what I just tried...
>
>USE speed
>replace ALL spd_char WITH myudf(spd_id)
>RETURN
>
>FUNCTION myudf
>LPARAMETERS tiID
>LOCAL lnSelect
>lnSelect = SELECT()
>SELECT 0
>IF !used("mylog")
> CREATE CURSOR mylog (log_id n(2))
>ENDIF
>APPEND BLANK IN mylog
>replace log_id WITH m.tiID IN mylog
>SELECT (lnSelect)
>RETURN STR(m.tiID)
>
>The program errored at 100 with a numeric overflow. I setup an error trap and that also fired and the code stopped at 100.
>
>>Hi Mike,
>>
>>What if you include replacement of numerical field with bigger number? My problem is, what I didn't get a Numerical overflow error, as I should get. Did you get this error correctly, when you ran your test program?
>>
>>Thanks in advance.
>>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform