'GridInterpolate.bas returns the Z values from the grid at the ' XY locations specified in the data file. TB - 21 Apr 04 'Changed ColumnCount to LastColumn. TB - 06 May 04 'Added date and time to the Z Interpolated column. ' Changed to use GRD file path for DAT file. TB - 22 Nov 04. Sub Main Debug.Print "----- ";Time;" -----" On Error Resume Next Set surf = GetObject(,"surfer.application") If Err.Number<>0 Then Set surf = CreateObject("Surfer.Application") surf.Documents.Add(srfDocPlot) End If On Error GoTo 0 'Turn on error reporting. path1 = surf.Path+"\samples\" 'path1 = "c:\incoming\" grdfile1 = GetFilePath("demogrid.grd","grd;ddf;dem",path1,"Open GRD File") If grdfile1 = "" Then End path1 = Left(grdfile1,InStrRev(grdfile1,"\")) Debug.Print path1 datfile1 = GetFilePath("demogrid.dat","dat;xls",path1,"Open Data File") If datfile1 = "" Then End surf.Visible = True Set wksdoc1 = surf.Documents.Open (datfile1) 'Specify XYZ columns. Dim wkscols$() ReDim wkscols$(1 To wksdoc1.UsedRange.LastColumn) Debug.Print "ColCount = ";wksdoc1.UsedRange.LastColumn For i = 1 To wksdoc1.UsedRange.LastColumn wkscols$(i)=Chr(i+64)+": "+Trim(Str(wksdoc1.Cells(1,i))) Debug.Print i;": ";wkscols(i) Next i AppActivate surf.Caption Begin Dialog UserDialog 350,147,"XYZ Columns" ' %GRID:10,7,1,1 GroupBox 20,14,310,91,"Worksheet Columns",.GroupBox1 Text 30,36,70,14,"X Column:",.xCol Text 30,58,70,14,"Y Column:",.yCol DropListBox 100,35,220,70,wkscols(),.DropListBox1 DropListBox 100,56,220,77,wkscols(),.DropListBox2 Text 30,84,170,14,"Save Z values in column: ",.zCol OKButton 140,119,90,21 CancelButton 250,119,90,21 TextBox 210,84,100,14,.TextBox1 End Dialog Dim dlg As UserDialog dlg.droplistbox1 = 0 'default value = wkscols(index) = col A dlg.droplistbox2 = 1 ' col B dlg.textbox1 = Chr(Asc(wkscols$(wksdoc1.UsedRange.LastColumn)) + 1) 'Debug.Print wksdoc1.UsedRange.LastColumn 'dlg.textbox1 = Chr(Asc(wksdoc1.UsedRange.LastColumn) + 1) If Dialog (dlg) = 0 Then End xcolumn = dlg.droplistbox1 + 1 ycolumn = dlg.droplistbox2 + 1 zcolumn = Asc(UCase(dlg.textbox1)) - 64 Debug.Print xcolumn;ycolumn;zcolumn With wksdoc1 'find first numeric row. For rownum = 1 To .UsedRange.LastRow If IsNumeric(.Cells(rownum,xcolumn)) And _ .Cells(rownum,xcolumn) <> "" And _ IsNumeric(.Cells(rownum,ycolumn)) And _ .Cells(rownum,ycolumn) <> "" Then Exit For Next rownum firstrow = rownum Debug.Print "firstrow = ";firstrow If Not IsNumeric(.Cells(firstrow,xcolumn)) Or _ .Cells(firstrow,xcolumn) = "" Or _ Not IsNumeric(.Cells(firstrow,ycolumn)) Or _ .Cells(firstrow,ycolumn) = "" Then MsgBox("No numeric data found in specified columns.", _ vbOkOnly,"Data Not Found") End End If If firstrow = 1 Then .Cells(1,1).Insert(wksInsertRows) .Cells(1,xcolumn) = "X" .Cells(1,ycolumn) = "Y" End If .Cells(1,zcolumn) = "Z Interpolated from " & grdfile1 & _ " on " & Date & " " & Time Set grid1 = surf.NewGrid grid1.LoadFile(grdfile1,headeronly:=False) For j = 2 To .UsedRange.LastRow zinterp = grid1.Interpolate( _ .Cells(row:=j,col:=xcolumn) , _ .Cells(row:=j,col:=ycolumn) ) 'Debug.Print "Z val:";zinterp .Cells(row:=j,col:=zcolumn).Value = zinterp Next j End With MsgBox("View and save Z values in the Surfer worksheet.",vbOkOnly, _ "Interpolation Complete") AppActivate surf.Caption End Sub