I like many of you have done very little with VB. As for me; I had no idea where or how to start. I could not see how typing those hundreds of lines of script could ever save me any kind of time and as far as finding a way to learn it or someone to get me started that just got to be a joke, unless I went and took a full blown course (that I didn't even know if I'd get anything out of or if I would ever use”. I had given up.
Well the other day I happened across something I think might actually be of help and makes doing something in VB practical. I don’t need to write every one of those hundreds of lines of script, and I can start learning from myself.
What I did was I took a program I already have “A regular PC DMIS Program I built and run often” and did an EXPORT as BASIC. When I opened it up all those hundreds of lines of script were already in there and though in a different “form or language” what ever you want to call it I found that I could walk thru most if not all of it as it was the same program I have in PC DMIS also. Now rather than typing all that out I need only “ADD, SUBTRACT and CHANGE things to make it work for me.
Now I think I have a starting place to try some VB.
I don’t know maybe I’m the only one that did not know this? Maybe I’m not yet on the right track, But I think I have a starting place now and I know before this I was lost.
Here is some code that I've used to extract data from a scan and write to a file -
***************************
Dim mode As Integer
Private Sub Form_Load()
Command1.Caption = "Process"
mode = 0
End Sub
Private Sub Command1_Click()
MsgBox "The mode is " & Str(mode)
Select Case mode
Case 0
process_file
Case 1
End
Case 2
End
End Select
End Sub
Private Sub process_file()
'Public Sub main(ScanID As String)
Dim app As PCDLRN.Application
Dim cmds As PCDLRN.Commands
Dim cmd As PCDLRN.Command
Dim ScanCmd As PCDLRN.Command
Dim part As PCDLRN.PartProgram, ScanHits As PCDLRN.FeatCmd
Dim hit As PCDLRN.PointData, vec As PCDLRN.PointData
Dim NoScanYet As Boolean
Dim nh As String
Dim HitX As Double, HitY As Double, HitZ As Double
Dim HitI As Double, HitJ As Double, HitK As Double
Dim i As Integer, TotalCmds As Integer, CurrentCmd As Integer
Command1.Caption = "Cancel"
mode = 1
NoScanYet = True
ScanID = "SCN1"
' Get the App, Partprogram and Commands
Set app = CreateObject("PCDLRN.Application")
Set part = app.ActivePartProgram
Set cmds = part.Commands
' Get the Scan from the part program
TotalCmds = cmds.Count
CurrentCmd = 0
BaseText = "Processing Command # "
EndText = "/" & Str(TotalCmds)
For Each cmd In cmds
CurrentCmd = CurrentCmd + 1
If cmd.ID = ScanID And NoScanYet = True Then
NoScanYet = False
cmd.Next
Set ScanCmd = cmd
Set ScanHits = cmd.FeatureCommand
Label1.Caption = "Found " & ScanID & " as command # " & Str(CurrentCmd)
Exit For
Else
Label1.Caption = BaseText & Str(CurrentCmd) & EndText
Label1.Refresh
End If
Next cmd
If NoScanYet = True Then
MsgBox "The Scan Feature was not found - " + ScanID
End
End If
' Some setup, establish point data objects
Set hit = CreateObject("PCDLRN.PointData")
Set vec = CreateObject("PCDLRN.PointData")
' Get the number of hits in the scan
nh = ScanCmd.GetText(N_HITS, 0)
cnt = CInt(nh)
' set startnum to 1 and endnum to the # of hits (nh)
It was taken from ane xisting VB project. Note that it has two Sub name lines, but the 2nd is commented out ('Public Sub main(ScanID As String)). This would be that syntax if it were a script. I sometimes develop in VB (or Excel as in your case) and then convert it to a script for use with PC-DMIS.
There is also some extra code in there to do some displays, messaging, etc. I suspec you'll be able to extract what you need.
One other thing to keep in mind is this. The area of code that latches onto the Scan object -
If cmd.ID = ScanID And NoScanYet = True Then
NoScanYet = False
cmd.Next
Set ScanCmd = cmd
Set ScanHits = cmd.FeatureCommand
has syntax which is dependedn on which type of scan you have. Linear open scans are different than Basic Circle scans, as an example.
Anyway, I hope this helps. I'll try to answer any question you might have on it, but I wrote it quite a while ago.
Here is some code that I've used to extract data from a scan and write to a file -
***************************
Dim mode As Integer
Private Sub Form_Load()
Command1.Caption = "Process"
mode = 0
End Sub
Private Sub Command1_Click()
MsgBox "The mode is " & Str(mode)
Select Case mode
Case 0
process_file
Case 1
End
Case 2
End
End Select
End Sub
Private Sub process_file()
'Public Sub main(ScanID As String)
Dim app As PCDLRN.Application
Dim cmds As PCDLRN.Commands
Dim cmd As PCDLRN.Command
Dim ScanCmd As PCDLRN.Command
Dim part As PCDLRN.PartProgram, ScanHits As PCDLRN.FeatCmd
Dim hit As PCDLRN.PointData, vec As PCDLRN.PointData
Dim NoScanYet As Boolean
Dim nh As String
Dim HitX As Double, HitY As Double, HitZ As Double
Dim HitI As Double, HitJ As Double, HitK As Double
Dim i As Integer, TotalCmds As Integer, CurrentCmd As Integer
Command1.Caption = "Cancel"
mode = 1
NoScanYet = True
ScanID = "SCN1"
' Get the App, Partprogram and Commands
Set app = CreateObject("PCDLRN.Application")
Set part = app.ActivePartProgram
Set cmds = part.Commands
' Get the Scan from the part program
TotalCmds = cmds.Count
CurrentCmd = 0
BaseText = "Processing Command # "
EndText = "/" & Str(TotalCmds)
For Each cmd In cmds
CurrentCmd = CurrentCmd + 1
If cmd.ID = ScanID And NoScanYet = True Then
NoScanYet = False
cmd.Next
Set ScanCmd = cmd
Set ScanHits = cmd.FeatureCommand
Label1.Caption = "Found " & ScanID & " as command # " & Str(CurrentCmd)
Exit For
Else
Label1.Caption = BaseText & Str(CurrentCmd) & EndText
Label1.Refresh
End If
Next cmd
If NoScanYet = True Then
MsgBox "The Scan Feature was not found - " + ScanID
End
End If
' Some setup, establish point data objects
Set hit = CreateObject("PCDLRN.PointData")
Set vec = CreateObject("PCDLRN.PointData")
' Get the number of hits in the scan
nh = ScanCmd.GetText(N_HITS, 0)
cnt = CInt(nh)
' set startnum to 1 and endnum to the # of hits (nh)
It was taken from ane xisting VB project. Note that it has two Sub name lines, but the 2nd is commented out ('Public Sub main(ScanID As String)). This would be that syntax if it were a script. I sometimes develop in VB (or Excel as in your case) and then convert it to a script for use with PC-DMIS.
There is also some extra code in there to do some displays, messaging, etc. I suspec you'll be able to extract what you need.
One other thing to keep in mind is this. The area of code that latches onto the Scan object -
If cmd.ID = ScanID And NoScanYet = True Then
NoScanYet = False
cmd.Next
Set ScanCmd = cmd
Set ScanHits = cmd.FeatureCommand
has syntax which is dependedn on which type of scan you have. Linear open scans are different than Basic Circle scans, as an example.
Anyway, I hope this helps. I'll try to answer any question you might have on it, but I wrote it quite a while ago.