| Author | 
         | 
         
      
        
         
         veropierre Groupie 
          
  
  Joined: May 06 2009 Location: United States
 Online Status: Offline Posts: 47
          | 
        
         
          
           | Posted: May 27 2009 at 10:53 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
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 | 
         
          
          
         | 
       
       
       
        |   | 
      
        
         
         grif091 Super User 
          
 
  Joined: March 26 2008 Location: United States
 Online Status: Offline Posts: 1357
          | 
        
         
          
           | Posted: May 27 2009 at 13:39 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
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 | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         device Newbie 
          
 
  Joined: May 26 2009
 Online Status: Offline Posts: 33
          | 
        
         
          
           | Posted: May 27 2009 at 17:57 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
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 | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         device Newbie 
          
 
  Joined: May 26 2009
 Online Status: Offline Posts: 33
          | 
        
         
          
           | Posted: May 27 2009 at 18:02 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Some formatting got mangled so you will have to de-HTMLize the example to use it.
 
 D
         | 
       
       
        | Back to Top | 
         
          
         | 
       
       
       
        |   | 
      
        
         
         veropierre Groupie 
          
  
  Joined: May 06 2009 Location: United States
 Online Status: Offline Posts: 47
          | 
        
         
          
           | Posted: May 28 2009 at 09:21 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
Nice, thank you!
         | 
       
       
        | Back to Top | 
         
          
          
         | 
       
       
       
        |   | 
      
        
         
         dhoward Admin Group 
          
  
  Joined: June 29 2001 Location: United States
 Online Status: Offline Posts: 4447
          | 
        
         
          
           | Posted: May 28 2009 at 11:19 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
D,
 
 Are you sure you're a newbie  ?
 
 Dave.
 
         | 
       
       
        | Back to Top | 
         
          
          
         | 
       
       
       
        |   | 
      
        
         
         device Newbie 
          
 
  Joined: May 26 2009
 Online Status: Offline Posts: 33
          | 
        
         
          
           | Posted: May 28 2009 at 14:30 | IP Logged
		     | 
                    
            		  
           | 
           
          
           
  | 
           
          
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 | 
         
          
         | 
       
       
       
        |   |