Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Looking for a VB script example Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
veropierre
Groupie
Groupie
Avatar

Joined: May 06 2009
Location: United States
Online Status: Offline
Posts: 47
Posted: May 27 2009 at 10:53 | IP Logged Quote veropierre

I wish to try my hand with VB scripting, I'm looking for a script example so I can play around a bit :)

Any lead?

Thank you.
Back to Top View veropierre's Profile Search for other posts by veropierre Visit veropierre's Homepage
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: May 27 2009 at 13:39 | IP Logged Quote grif091

This is about as simple an example as you can get. The Macro Formula invokes the VB script file which displays a Powerhome user message in the Event Log.

Macro formula statement

ph_runscript_0(0, "c:\temp\avbscript1.vbs", "sub1")


File c:\temp\avbscript1.vbs

@language="vbscript"
Sub sub1()
     ph.usermessage("user message from vb script")
End Sub



__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
device
Newbie
Newbie


Joined: May 26 2009
Online Status: Offline
Posts: 33
Posted: May 27 2009 at 17:57 | IP Logged Quote device

Well, I am a triple newbie (new to VBScript, SQL and powerhome over the past couple weeks). Here is the first VBScript I ever wrote (back in the days of yore - a couple weeks ago). It enumerates all the tables and all the columns of all the tables in powerhome into a text file (tables.txt) so I can use an editor to search for names when I am writing in another new language SQL and need table and/or column names.

Have fun,

D


Function enumtables()
     On Error Resume Next
    enumtables = "failed"
     Set fso = CreateObject("Scripting.FileSystemObject")
     Set tableinfo = fso.CreateTextFile("c:\Program Files\powerhome\tables.txt", True)
     Set fso = Nothing
     sysstatus = ph.sqlselect(1, "SELECT * FROM sys.syscatalog")
     If (sysstatus = 0) Then
           enumtables = "success"
           tablecount = ph.getsqlrows(1)
           For tableindex = 1 To tablecount
                tablename = ph.getdata_cn(1, CLng(tableindex), "tname")
                If tablename <> "SYSUSERPERM" Then
                      tablestatus = ph.sqlselect(2, "SELECT * FROM " & tablename)
                      tableinfo.WriteLine("Table : " & tablename)
                      If (tablestatus = 0 Or tablestatus = 2) Then
                           colcount = ph.getcolcount(2)
                           For colindex = 1 To colcount
                                 colname = ph.getcolname(2, CLng(colindex))
                                 coltype = ph.getcoltype(2, Clng(colindex))
                                 tableinfo.WriteLine("      " & CStr(colindex) & " : " & colname & " : " & coltype)
                           Next
                      Else
                           enumtables = "success with errors"
                           tableinfo.WriteLine(" &nb sp;    Error " & CStr(tablestatus) & " opening " & tablename)
                      End If
                      tableinfo.WriteBlankLines(3)     &n bsp;         &n bsp;    
                      ph.sqldestroy(2)
                End If
           Next
           ph.sqldestroy(1)       &n bsp;  
     End If
     tableinfo.Close
     Set tableinfo = Nothing
End Function
Back to Top View device's Profile Search for other posts by device
 
device
Newbie
Newbie


Joined: May 26 2009
Online Status: Offline
Posts: 33
Posted: May 27 2009 at 18:02 | IP Logged Quote device

Some formatting got mangled so you will have to de-HTMLize the example to use it.

D
Back to Top View device's Profile Search for other posts by device
 
veropierre
Groupie
Groupie
Avatar

Joined: May 06 2009
Location: United States
Online Status: Offline
Posts: 47
Posted: May 28 2009 at 09:21 | IP Logged Quote veropierre

Nice, thank you!
Back to Top View veropierre's Profile Search for other posts by veropierre Visit veropierre's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: May 28 2009 at 11:19 | IP Logged Quote dhoward

D,

Are you sure you're a newbie ?

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
device
Newbie
Newbie


Joined: May 26 2009
Online Status: Offline
Posts: 33
Posted: May 28 2009 at 14:30 | IP Logged Quote device

Only claimed to be a newbie to VBScript, SQL, and Powerhome. I suppose I should have had full disclosure and confessed to having done a few other things in my life.

,

D

Back to Top View device's Profile Search for other posts by device
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum