Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how do i make this vbs(vb script) into vb6 please

Posted on 2004-09-06
5
Medium Priority
?
225 Views
Last Modified: 2010-05-02
id like to make the fallowing code from vbscript to vb6

id like to have a command buton fire it please

the below code works perfectly.

Thank you
Pern

---------cut-------------cut-----------cut---------------

  Option Explicit
  Dim i, Users, Fso,fn
 
  Const ForReading = 1, ForWriting = 2, ForAppending = 8
  Set Users=WScript.CreateObject("MailServerX.Users")
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set fn = fso.OpenTextFile("USERLIST.TXT", ForWriting, True)

  For i=0 To Users.Count-1

   fn.Writeline "Is User Active: " & Users.Items(i).Active
   fn.Writeline "Last Login Time: " & Users.Items(i).LastLoginTime
   fn.Writeline "UserName: " & Users.Items(i).UserName
   fn.Writeline "Password: " & Users.Items(i).Password
   fn.Writeline "**-----------------------------------**"
Next
  fn.close
MsgBox "Operation Complete"
0
Comment
Question by:Johnny
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:JR2003
ID: 11987800
You actually need minimal changes.
1) Add a button to a form
2) Add the following code


Option Explicit

Private Sub Command1_Click()
   
    Dim i, Users, Fso, fn
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Set Users = CreateObject("MailServerX.Users")
    Set Fso = CreateObject("Scripting.FileSystemObject")
    Set fn = Fso.OpenTextFile("USERLIST.TXT", ForWriting, True)
   
    For i = 0 To Users.Count - 1
        fn.Writeline "Is User Active: " & Users.Items(i).Active
        fn.Writeline "Last Login Time: " & Users.Items(i).LastLoginTime
        fn.Writeline "UserName: " & Users.Items(i).UserName
        fn.Writeline "Password: " & Users.Items(i).Password
        fn.Writeline "**-----------------------------------**"
    Next
    fn.Close
    MsgBox "Operation Complete"

End Sub
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11987895
I'm not sure what the difference is btween WScript.CreateObject and CreateObject.
You may want to add references to the "Microsoft Scripting Runtime" and "MailServerX Library" components in the Project/References option and call the code in a more "typed" way:

Option Explicit

Private Sub Command1_Click()
   
    Dim i As Long
    Dim Users As MailServerX.User
    Dim fso As Scripting.Dictionary
    Dim fn As Scripting.TextStream
   
    Set Users = New MailServerX.User
    Set fso = New Scripting.FileSystemObject
    Set fn = fso.OpenTextFile("USERLIST.TXT", ForWriting, True)
   
    For i = 0 To Users.Count - 1
        fn.Writeline "Is User Active: " & Users.Items(i).Active
        fn.Writeline "Last Login Time: " & Users.Items(i).LastLoginTime
        fn.Writeline "UserName: " & Users.Items(i).UserName
        fn.Writeline "Password: " & Users.Items(i).Password
        fn.Writeline "**-----------------------------------**"
    Next
    fn.Close
    MsgBox "Operation Complete"

End Sub
0
 
LVL 14

Accepted Solution

by:
aelatik earned 1500 total points
ID: 11988047
Since you're doing it in VB you can use the native FILE I/O functions.

Option Explicit

Private Sub Form_Load()
 
  Dim I As Long
  Dim USERS As Object
   
    Set USERS = CreateObject("MailServerX.Users")
    Open "USERLIST.TXT" For Output As #1
        For I = 0 To USERS.Count - 1
            Print #1, "Is User Active: " & USERS.Items(I).Active
            Print #1, "Last Login Time: " & USERS.Items(I).LastLoginTime
            Print #1, "UserName: " & USERS.Items(I).UserName
            Print #1, "Password: " & USERS.Items(I).Password
            Print #1, "**-----------------------------------**"
        Next I
    Close #1
    MsgBox "Operation Complete"
   
End Sub
0
 
LVL 14

Expert Comment

by:aelatik
ID: 11988104
BTW, clear the USERS object when you finish :

Set USERS = NOTHING
0
 

Author Comment

by:Johnny
ID: 11992096
I gave you a B aelatik as you did not make it a command button as asked and did it on form load..easy to remidy tho.

i am old school basic so i used your example as i was familer with it..

thanks for all your help.

Johnny
aka Pern
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question