Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now