Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-06
5
Medium Priority
?
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
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…
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…
Suggested Courses

688 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