Solved

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

Posted on 2004-09-06
5
197 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 500 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 54
bit defender blocks good applications 2 94
IF ELSE Statement in Excel Macro VBA 16 65
Copy a range from 1..n excel sheets to one destination sheet 2 33
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

803 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