Results 1 to 21 of 21

Thread: Script development

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    433

    Script development

    In VB6, what does Script Development/Scripting mean?
    Is this a Web-programming?

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,429

    Re: Script development

    There is no scripting involved in VB6.

    That doesn't mean external script can't make use of DLLs created in VB6, or that VB6 cannot host a script engine to run scripts internally.

    So without more information your question is difficult to answer. There are a lot of non-programmers who try to describe VB6 source code as "script" but they just don't know what they are talking about.

  3. #3
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    557

    Re: Script development

    Script/Scripting is an all encompassing computer buzzword that describes an activity where you will type in words, commands, (whatever) in any kind of ascii word processor, under a given syntax and rules, to be interpreted by a matched script processor. Javascript is a script interpreter. XML is also a form of script.

    Related to VB6, we are probably talking of VBA (Visual Basic for applications). VB6 and VBA have a lot in common, you write VBA scripts (programs really) pretty much the same way you write VB6 codes : same data type, procedure, functions. What VB6 has that VBA does not is an IDE to control multiple modules, debugging, and compiling, creation of Activex, DLL's etc.

    There are also scripting references and component tools and services that you can add directly to VB6 or VBA (Windows Script Host Object Model) and that you call to perform their intended tasks though creating classes objects with methods and properties. Wscript.shell for example is an object that lets you get the names of Windows Special Folders. This can be done easily in VB6 with API calls, but VBA does not. With the Script shell, Special folders are accessible in VBA, Word, Excel, etc.

    Anything particular in mind for asking this?

  4. #4
    Fanatic Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    964

    Re: Script development

    ...Or he can get some code from m2000 Interpreter and use a mini interpreter...
    It easy...
    You need this functions in module1:
    Execute, Identifier (there is a I2 as an extended Identifier), and IsStrExp and IsExp to get to read string and arithmetic expressions (these use the IsString and IsNumber). You can hold some read only variables that you wish to give to the user and you can make your own functions and commands. Also the variables define and use can be stay.
    The code is in the signature..under...

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,442

    Re: Script development

    Quote Originally Posted by georgekar View Post
    ...Or he can get some code from m2000 Interpreter and use a mini interpreter...
    It easy...
    You need this functions in module1:
    Execute, Identifier (there is a I2 as an extended Identifier), and IsStrExp and IsExp to get to read string and arithmetic expressions (these use the IsString and IsNumber). You can hold some read only variables that you wish to give to the user and you can make your own functions and commands. Also the variables define and use can be stay.
    The code is in the signature..under...

    ????

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,953

    Re: Script development

    typical hallmarks of scripty languages:
    * they are typeless ... everything is a a var/variant/object/something non-specific.
    * typically (but not always) lack an interactive interface
    * non-compiled. They just run. They're usually just stored as text files, even when they have an extension such as .js or .vbs, they're still just plain old text.
    * they are often simple. That's not to say they can't be complex, just that it doesn't happen a lot. They also tend to be very linear running from start to finish. With some exceptions, they don't respond to events either --- this is where I think AJAX gets a bit tricky, because you do have items that are responding to events, but they are events that happen in the browser container and not necessarily tied to the language itself.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,429

    Re: Script development

    XML is just a convention imposed on text to represent hierarchical data. XML is not a scripting language.

    Scripts do not "just run." They need to be processed by a script interpreter. In Windows the .js, and .vbs file extensions normally have the Shell open verb set to run either cscript.exe or wscript.exe. By adding ActivePerl you set the open verb for .pl files to run the same script host (either cscript or wscript) which just loads the Perl script engine instead of the VBScript or JScript engine.

    There is also the mshta.exe script host included in Windows.

    Then you have cmd.exe's .bat/.cmd files, and most machines even have PowerShell installed these days which interprets .ps1 files.
    Last edited by dilettante; Dec 11th, 2014 at 04:40 PM.

  8. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,685

    Re: Script development

    I tend to consider scripts as programs that only make sense within a specific context, usually a sandbox of some kind like a web browser or a game engine. VB6 can interact with the OS itself in an almost unlimited capacity therefore its not a scripting language. Scripts on the other hand usually have very limited ability to interact with the OS. Some only allow access to the file system and even then their power is curtailed. They primarily interact the the sandbox for which they were made. Javascript can control a lot within your browser and not much more. Scripting languages like UnrealScript have extensive control over the gaming environment of games built with the unreal engine but don't expect to be able to write a word processor with it. In other words, scripting languages by and large cannot effectively write apps like a real programming language can. They are made only to control and manipulate a specific environment.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  9. #9
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Script development

    Here is an example, start new project and add this to form1 (do not add any controls!)

    Code:
    Private Script As Object
    Private Text1 As Object
    Private WithEvents Command1 As CommandButton
    
    Private Sub Form_Load()
      Set Command1 = Controls.Add("VB.CommandButton", "Command1")
        With Command1
          .Move 500, 500, 3000, 1800
          .Caption = "Click Me"
          .Visible = True
        End With
        
      Set Text1 = Controls.Add("VB.TextBox", "Text1")
        With Text1
          .Move 2500, 2500, 3000, 3000
          .Visible = True
        End With
        
      Set Script = CreateObject("MSScriptControl.ScriptControl")
        With Script
          .Language = "VBScript"
          .AddObject "Form1", Form1
          .AddObject "Text1", Text1
          .AddObject "Command1", Command1
          'The code below (Command1_Click) could be written in a textbox, just like a script and then executed
          .AddCode "Sub Command1_Click" & vbNewLine & _
                   "Text1.Text = Text1.Text & " & """Mouse Was Clicked""" & vbNewLine & _
                   "MsgBox " & """Script Button Was Clicked!""" & "," & """0""" & "," & """Title""" & vbNewLine & _
                   "End Sub"
        End With
        
        Form1.Width = 7000
        Form1.Height = 7000
    End Sub
    
    Private Sub Command1_Click()
      Script.Run "Command1_Click"
    End Sub
    Run project and try the commandbutton.

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,953

    Re: Script development

    Quote Originally Posted by dilettante View Post
    Scripts do not "just run." They need to be processed by a script interpreter. In Windows the .js, and .vbs file extensions normally have the Shell open verb set to run either cscript.exe or wscript.exe. By adding ActivePerl you set the open verb for .pl files to run the same script host (either cscript or wscript) which just loads the Perl script engine instead of the VBScript or JScript engine.
    It's debatable... I see your point, and perhaps I should have been a little clearer, by "they just run" I meant that I can double click a vbs file and it will do its thing. typically I don't need to do anything else. There isn't a special IDE that I run or to compile the script files themselves ahead of time.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    Fanatic Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    964

    Re: Script development

    @Max187Boucher
    How we can make the textbox (in your example) as a multiline textbox? (I think that can be done at design time)

    The only way, for now is to place a textbox as Text1 and remove the Text1 as object
    So we do in design time a textbox as multiline..and the we can use it

    Code:
    Private Script As Object
    
    Private WithEvents Command1 As CommandButton
    
    Private Sub Form_Load()
      Set Command1 = Controls.Add("VB.CommandButton", "Command1")
        With Command1
          .Move 500, 500, 3000, 1800
          .Caption = "Click Me"
          .Visible = True
        End With
        
         With Text1
            .Move 2500, 2500, 3000, 3000
          .Visible = True
        End With
        
      Set Script = CreateObject("MSScriptControl.ScriptControl")
        With Script
          .Language = "VBScript"
          .AddObject "Form1", Form1
          .AddObject "Text1", Text1
          .AddObject "Command1", Command1
          'The code below (Command1_Click) could be written in a textbox, just like a script and then executed
          .AddCode "Sub Command1_Click" & vbNewLine & _
                   "Text1.Text = Text1.Text & " & """Mouse Was Clicked""" & vbNewLine & _
                   "MsgBox " & """Script Button Was Clicked!""" & "," & """0""" & "," & """Title""" & vbNewLine & _
                   "End Sub"
        End With
        
        Form1.Width = 7000
        Form1.Height = 7000
    End Sub
    
    Private Sub Command1_Click()
      Script.Run "Command1_Click"
    End Sub
    Last edited by georgekar; Dec 12th, 2014 at 12:41 PM.

  12. #12
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Script development

    Yes the best way is to add all controls at design and set their index property to 0 and visible = false.
    Then you can play around a bit more with their "design" properties.

  13. #13
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    557

    Re: Script development

    Interesting example Max, but it has as much to do with OOP adding controls at run time as it has to do with the scripting control. Besides, script code is actually not related to Command1_Click, it is just using Command1_Click as a tag to call this piece of code.

    Here's an example of the Scripting Control alone, interacting with one of the form's control. When the program runs, it is a script interpreter and you can change and save the script file externally and the program will reflect the changes when command button is clicked.

    Start a new project with a form, a command button and a text box. If you click often enough, you may win the lottery

    Code :
    Code:
    Dim a
    
    Private Sub Form_Load()
    a = Array("Lottery", "Invoice", "Speed")
    End Sub
    
    
    Private Sub Command1_Click()
      
    Set Script = CreateObject("MSScriptControl.ScriptControl")
    Script.Language = "VBScript"
    Script.AddObject "Text1", Text1
    
    'scripts with Script control can be very unforgiving for syntax.
    On Error Resume Next
    Script.AddCode readtextfile("C:\users\presario\desktop\c1.txt")
    If Err Then
        MsgBox "Script Error"
    Else
        Randomize
        Script.Run a(Int(Rnd * 3))
        If Err Then MsgBox "Program Error"
    End If
    Set Script = Nothing
    
    End Sub
    
    Function readtextfile(filename1$)
    filenum = FreeFile
    Open filename1$ For Binary As filenum
    readtextfile = Input$(LOF(filenum), #filenum)
    Close filenum
    End Function

    Content of File : c1.txt (on your desktop)
    Code:
    Sub Lottery()
        ' You can change the code in this file
        ' While the program is running
        ' save it, and the changes will show
        Randomize
        a = Rnd * 9
        If a < 7 Then
            Text1.Text = "Mouse was clicked (" & Int(a) & ")"
            MsgBox "Script Button Was Clicked!", vbExclamation, "Title"
        Else
            Text1.Text = "You just won the lottery!"
            MsgBox "You just won the Lottery !" & vbCrLf & vbCrLf & "Sign your ticket and claim your Prize!", vbInformation, "Big Winner!"
        End If
    End Sub
    
    Sub Invoice()
        Text1.Text = "Your invoice amount to $45"
        MsgBox "Please pay to the cashier", vbExclamation, "Invoice"
    End Sub
    
    Sub Speed()
        Text1.Text = "Watch your speed"
        MsgBox "Slow Down Buddy!", vbCritical, "Speed Watcher"
    End Sub
    Last edited by Navion; Dec 12th, 2014 at 06:42 PM. Reason: Typos

  14. #14
    Fanatic Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    964

    Re: Script development

    Can you take arrays or other variables from this script? Or you should use an object where the script can use for output??

  15. #15
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Script development

    Quote Originally Posted by georgekar View Post
    @Max187Boucher
    How we can make the textbox (in your example) as a multiline textbox? (I think that can be done at design time)

    The only way, for now is to place a textbox as Text1 and remove the Text1 as object
    So we do in design time a textbox as multiline..and the we can use it

    Code:
    Private Script As Object
    
    Private WithEvents Command1 As CommandButton
    
    Private Sub Form_Load()
      Set Command1 = Controls.Add("VB.CommandButton", "Command1")
        With Command1
          .Move 500, 500, 3000, 1800
          .Caption = "Click Me"
          .Visible = True
        End With
        
         With Text1
            .Move 2500, 2500, 3000, 3000
          .Visible = True
        End With
        
      Set Script = CreateObject("MSScriptControl.ScriptControl")
        With Script
          .Language = "VBScript"
          .AddObject "Form1", Form1
          .AddObject "Text1", Text1
          .AddObject "Command1", Command1
          'The code below (Command1_Click) could be written in a textbox, just like a script and then executed
          .AddCode "Sub Command1_Click" & vbNewLine & _
                   "Text1.Text = Text1.Text & " & """Mouse Was Clicked""" & vbNewLine & _
                   "MsgBox " & """Script Button Was Clicked!""" & "," & """0""" & "," & """Title""" & vbNewLine & _
                   "End Sub"
        End With
        
        Form1.Width = 7000
        Form1.Height = 7000
    End Sub
    
    Private Sub Command1_Click()
      Script.Run "Command1_Click"
    End Sub
    You could use a richtextbox instead of textbox, as long as you add it's license you can use it.

    Code:
      Dim Text1 As Object
        Licenses.Add "RichText.RichTextCtrl"
          Set Text1 = Controls.Add("RichText.RichTextCtrl", "Text1")
            With Text1
              .Move 2500, 2500, 4000, 3000
              .Visible = True
              .object.Text = "Write your text in here"
            End With

  16. #16
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Script development

    Quote Originally Posted by georgekar View Post
    Can you take arrays or other variables from this script? Or you should use an object where the script can use for output??

    like this? Add this to the script control and run it

    Code:
    Sub Test
    dim arr(2)
    arr(0) = "Hi"
    arr(1) = "Bye"
    arr(2) = "It's working!"
    msgbox arr(0) & vbnewline & arr(1) & vbnewline & arr(2)
    end sub

  17. #17
    Fanatic Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    964

    Re: Script development

    I think the use of a script is to do some user manipulation on data rather on ui. So my previous question is still there: Can we use script language to access data in vb and manipulate them? So maybe a user can make own functions and use any to prepare export data, without the programmer has done anything else for that stage except providing the script capability and some info on how to access and manipulate data.

  18. #18
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Script development

    Yes george I had made a program that was like VB6 IDE but very light, you could add objects, and manipulate them with a script. Also it saved all the controls and their properties to files, so I could load up those script again, or actually it was like a program saved to file.

    Now where I was at, was to add API to it, but my laptop broke so I lost that program. Anyways, the last thing I wanna be able to do with the scripts (since I know how to manipulate the object already) was to add API functionality, which LaVolpe has the answer in this thread...
    http://www.vbforums.com/showthread.p...all-DLL-Calls)

    We just need to add a (or many) special API calling functions that will work from the script, adding API support for VBScript (through vb6)

    With powerfull api at our fingertips and vbscript to write functions, now it will allow us to use api and write sub/functions at runtime.

  19. #19
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Script development

    Here is what I mean when you could add api to VBScript, sorry do not have time to add more to it, but have a look at this.
    Attached Files Attached Files
    Last edited by Max187Boucher; Dec 12th, 2014 at 09:14 PM.

  20. #20
    Fanatic Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    964

    Re: Script development

    For Api calls I make some work in M2000.
    This code work.
    Code:
    DECLARE MessageBox LIB "user32.MessageBoxW" {LONG HWND, LPTEXT$, LPCAPTION$, LONG TYPE}
    DECLARE timeGetTime LIB "winmm.timeGetTime" {}
    while MessageBox(HWND, "HELLO THERE "+str$(timeGetTime()),"GEORGE",2)=4 {
    print "one time again"
    }
    I use stdCallW from Olaf Schmidt (from #7 from the link you give too)

    I didn't check yet the by reference mechanism. But there is one. My script language can make new variables in a table and places that references...then in the end of the calling I place the new values back where they should be.

    So now I want to call methods and altering properties to objects...And I want to passing objects to objects.
    Until now I can make a variable A to hold a reference to an object and I can dereference it. I have to write METHOD and PROPERTY commands.

    As I said script is not for much low level calls, but can be used for manipulating data and programs like ms office. I have start to exclude M2000 script engine from the environment. My scope is to produce a script open language, that anyone can add specific commands. The only common would be the variables, arrays, groups, documents. Maybe I include declare command, but i believe now that is out of scope. So for an application there is no need for programmer to expose objects (that is another scope). He can expose commands only to run from his application. The problem with vbscript is that if you can using it for your program then anyone you can access your program, because vbscript use objects that expose from your program. So my scripting language can run only in the application environment, without need an external "engine".
    Last edited by georgekar; Dec 12th, 2014 at 09:09 PM.

  21. #21
    Fanatic Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    964

    Re: Script development

    I see your program...I am some step ahead.
    To run your program (the api call) you make some textboxes to store parameters....So you can run once the code...not second time...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width