Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Recommended Posts

I have 2 VBS's that Mick George helped me with. 1 is

a read text file:

code:

 '///////////////// My Constants /////////////////

 

' -- Edit path to suit

Const CUSTOMER_INFO = "C:mcamxvbCustomerlist.txt"

 

' Text file has a simple list of customers

'Acme Industries

'CNC Software

'Joe Blow Inc.

 

 

' -- Start Script

Call Main

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub Main()

 

Dim CustomerList

Dim response

Dim selectedCustomer

 

' -- Build the list

CustomerList = GetCustomerList()

 

' -- Prompt for a #

If askNumber("Select a customer #", 1, 100, response) Then

 

' -- Get the customer

selectedCustomer = GetCustomerName(response, CustomerList)

 

If selectedCustomer = "" Then

' -- You could add this customer to your textfile

ShowString "New Customer!"

Else

' -- We have our customer name

ShowString selectedCustomer

End If

 

End If

 

End Sub

 

' -- Pass in the array of customers and the index and return

' -- the customers name at that index

Function GetCustomerName(idx, theList)

 

Dim i

 

For i = 1 To Ubound(theList)

If i = idx Then

GetCustomerName = theList(i)

Exit Function

End If

Next

 

' -- Not found so return null

GetCustomerName = ""

 

End Function

 

 

' -- Open text file and fill an array

' -- with the list of our customers

Function GetCustomerList()

 

Dim FSO, fsoStream

Dim CustomerList()

Dim i

Dim customer

 

Set FSO = CreateObject("Scripting.FileSystemObject")

 

Set fsoStream = FSO.OpenTextFile(CUSTOMER_INFO)

 

' -- Start at 1

i = 1

 

Do While fsoStream.AtEndOfStream <> True

 

customer = fsoStream.ReadLine

 

If Len(customer) > 0 Then

Redim Preserve CustomerList(i)

CustomerList(i) = customer

i = i + 1

End If

 

Loop

 

fsoStream.Close

 

' -- Return

GetCustomerList = CustomerList

 

 

End Function

This works great I just put in a number and it brings up a name of a customer.

 

What I am trying to do now is insert it into some other VBS's. The easiest is my create a folder vbs

code:

'///////////////// My Constants /////////////////

 

 

'///////////////// My Global Variables //////////

 

 

 

' -- Start Script

Call Main()

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub Main()

 

On Error Resume Next

 

 

Dim companyname

Dim Program

<======starting right here

Do 'ask until a real company name is entered

companyname=Trim(AskString("Company Name?"))

Loop While companyname="Company Name?" Or companyname="((ESC))" Or companyname=""

 

<===============to right here I am trying to put in the answer from the 1st vbs.

 

Do 'ask until a real program number is used

Program=Trim(AskString("Part number?"))

Loop While Program="Part number?" Or Program="" Or Program="((ESC))"

 

 

If Not MakeFolders(companyname, Program) Then

ShowString "Failed to create folders, aborting script"

Exit Sub

End If

 

 

End Sub

 

' ////////////////////

' Function Declaration

' ////////////////////

 

Public Function MakeFolders(companyname, Program)

 

On Error Resume Next

 

' -- Check to see if folders exist

Dim FSO

 

Set FSO = CreateObject("Scripting.FileSystemObject")

 

'

' -- This is kinda long winded but does the job

' -- NOTE: If you use an invalid character for a part number you'll have a problem!

 

If Not FSO.FolderExists("WAIKIKIMSPrograms"&companyname) Then

Call FSO.CreateFolder("WAIKIKIMSPrograms"&companyname)

End If

 

If Not FSO.FolderExists("WAIKIKIMSPrograms"&companyname & "" & Program) Then

Call FSO.CreateFolder("WAIKIKIMSPrograms"&companyname & "" & Program)

End If

 

If Not FSO.FolderExists("WAIKIKIMSPrograms"&companyname & "" & Program & "Source") Then

Call FSO.CreateFolder("WAIKIKIMSPrograms"&companyname & "" & Program & "Source")

End If

 

If Not FSO.FolderExists("WAIKIKIMSPrograms"&companyname & "" & Program & "Model Files") Then

Call FSO.CreateFolder("WAIKIKIMSPrograms"&companyname & "" & Program & "Model Files")

End If

 

If Not FSO.FolderExists("WAIKIKIMSPrograms"&companyname & "" & Program & "Docs") Then

Call FSO.CreateFolder("WAIKIKIMSPrograms"&companyname & "" & Program & "Docs")

End If

 

If Not FSO.FolderExists("WAIKIKIMSPrograms"&companyname & "" & Program & "NC Code") Then

Call FSO.CreateFolder("WAIKIKIMSPrograms"&companyname & "" & Program & "NC Code")

End If

 

If Not FSO.FolderExists("WAIKIKIMSPrograms" & companyname & "" & Program & "NC Code1000") Then

Call FSO.CreateFolder("WAIKIKIMSPrograms" & companyname & "" & Program & "NC Code1000")

End if

 

If Not FSO.FolderExists("WAIKIKIMSPrograms" & companyname & "" & Program & "NC CodeOP") Then

Call FSO.CreateFolder("WAIKIKIMSPrograms" & companyname & "" & Program & "NC CodeOP")

End if

 

If Err Then

MakeFolders = False

Else

MakeFolders = True

End If

 

 

End Function


At the place I have shown in the second one I need to be able to use the answer from the first VBS.

 

Thanks for looking.

Link to comment
Share on other sites

You can add this function to the script the user runs:

 

code:

Sub Include(sNameScript)

 

On Error Resume Next

 

Dim FSO

Dim fsoInclude

Dim strMsg, strPath, strMC9

 

Set FSO = CreateObject("Scripting.FileSystemObject")

 

strPath = AddBackSlash(GetPathOfThisScript) & DEF_SCRIPT_FOLDER & "" & sNameScript

strMC9 = AddBackSlash(GetPath) & "VB"

 

 

Set fsoInclude = FSO.OpenTextFile(strPath)

 

If Err Then

strMsg = "The script '" & sNameScript & "' might be missing from your " & strMC9 & "" & DEF_SCRIPT_FOLDER & " folder"

strMsg = strMsg & vbCrLf

strMsg = strMsg & "This link will not function without this file. Make sure this file has not been moved or deleted."

strMsg = strMsg & vbCrLf

strMsg = strMsg & "Contact your reseller for help or re-install the link to resolve this problem."

 

Call ShowString(strMsg)

Err.Clear

Else

With fsoInclude

ExecuteGlobal .ReadAll()

.Close

End With

End If

 

' -- Clean up

Set fsoInclude = Nothing

Set FSO = Nothing

 

End Sub


Then at the top of the main script add the line(s):

 

code:

 

 

' -- Begin list of helper scripts

Include "KCDwATPGlobals.vbs"

Include "KCDwATPStringTable.vbs"

Include "KCDwATPFunctions.vbs"

Include "KCDwATPDatabase.vbs"


You can list as many scripts as you want here, what happens is that when the main script executes it will load all of the specified scripts at the same time and make the functions in them available to the main script. Make sure the scripts are in the same folder as the main script.

 

You will need to rename any Sub Main() calls in the included scripts to avoid unwanted behaviour.

Link to comment
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...