Solved

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

Posted on 2004-09-06
5
190 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
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
BTW, clear the USERS object when you finish :

Set USERS = NOTHING
0
 

Author Comment

by:Johnny
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now