Updating table fields with functions is a much faster techique than
stepping through a table record by record to change a field. I was curious
to see how far the technique could be stretched and discovered that using
a function in a select doesn't seem to work, but in an update, it works
fine. Why is this? Anyone know?
Here's a test program illustrating the problem:
Declare Sub Main
Declare Function Reverse (ByVal sName As String) As String
Sub Main
Dim sFile As String
' Open the States table and build a new table using STATES.State_Name
' passed to a function that returns a string. The string returned from
' that function will be used to populate a temporary table and a
' permanent one. Why does the temporary table not get filled, while
' rows are created?
' Set up and open the source table
Close All
sFile = FileOpenDlg ("", "States.Tab", "TAB",
"Please open the STATES table")
If sFile = "" Then
Exit Sub
End If
Open Table sFile As STATES
' This works only rarely (but sometimes it does!)
' Usually all rows are blank.
Select Reverse (State_Name) "emaN_etatS"
From STATES Into TEMP NoSelect
' This does work
Create Table PERM (
emaN Char(20)
)
Insert Into PERM Select Reverse (State_Name) From STATES
Commit Table PERM
' View the results
Browse * From PERM
Browse * From TEMP
End Sub
Function Reverse (
ByVal sName As String) ' Input string
As String ' Returned word spelled backwards
'Reverses letters in a string
Dim sRevWord As String
Dim i, j As Integer
j = Len(sName)
For i = j To 1 Step -1
sRevWord = sRevWord + Mid$(sName, i, 1)
Next
Reverse = sRevWord
End Function
---
- Bill Thoen
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 12542