Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write/compile code without form? 2

Status
Not open for further replies.

gben

IS-IT--Management
Jun 11, 2001
28
CA
i am new to vb. i need it to create some simple tools that can run from the command line without forms such as this one i downloaded from the web.

i have installed vb6 and when i open it the first thing i get is a form. how can i just write/compile a simple windowless code like you do in c?

thanks for any help!

-----------------------------

Public Function delOldFiles(delDays as integer, scanDir as string)
'<CSCM>
'-----------------------------------------------------'
' Project : XMLSentinel
' Procedure : delOldFiles
' Description: DELETE OLD FILES
' Created by : Project Administrator
' Date-Time : 5/16/2002-4:26:37 PM
' Parameters : delDays -> number of days
' scanDir -> the directory
'-----------------------------------------------------'</CSCM>
Dim fs As Object

On Error GoTo errorHandler
Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)

' CHECK IF THE DIRECTORY EXISTS
If Dir$(scanDir, vbDirectory) <> &quot;&quot; Then
' DIRECTORY DOES EXIST, SO GO ON ...
Dim fileDate As Date ' Declare variables.
Dim f, f1, fc

Set f = fs.GetFolder(scanDir)
Set fc = f.Files
For Each f1 In fc
fileDate = f1.DateCreated
If DateDiff(&quot;d&quot;, fileDate, Now) > delDays Then
f1.Delete

End If

Next

End If
Set fs = Nothing
Exit Function

errorHandler:
Resume Next
End Function
 

Add module to your project and add a sub main to the module. In project>properties set your startup object to sub main. Then in sub main for a test you can...
[tt]
Sub Main()
Dim S As String
S = Command
MsgBox S
End Sub
[/tt]

Then say your app is in the root of c and called test.exe and you want to pass a command line to it. You could type in the command window or the run box...

C:\text.exe my param

you should get a msgbox with &quot;my param&quot;

Good Luck

 
add a Module to your project and then add a Sub Main

Sub Main()
'do something
end sub
'
Then in the menu Project -> Properties change the startup object to Sub Main.

 
DrJavaJoe don't feel bad. vb5prgrmr, strongm, johnwm, cllint, cajuncent, zemp....they are hardwired into the forums.....I'm going to start a support group for them to try to ralley some support to get them exposed to direct sunlight some time.
 

Hey! Hey! Hey! I resemble that remark! LOL

Hi my name is (insert vb5prgrmr/strongm/johnwm/cclint/cajuncenturion/zemp/etc.) and I am addicted to tek-tips...

naw, DrJavaJoe I think you were on another thread when I got here.

:) ;-)
 
Save it as vbs.... then double click it
(it's vbscript code)
 
thanks folks who replied.

dimsis, i tried what you suggested, i.e. saving it as vbs and double click on it. i got a message saying there is an error in this line:

Public Function delOldFiles(delDays as integer, scanDir as string)

can you try it and let me know if it runs successfully on your system?

thanks.
 
Yea don't do it in VBS.... 8P
VBS does not supported typed variables....all variables are variants. If you have to do somethint with external object (like automating word) and a method has a byref typed parameter then VBS is not an option because it will get an error with that method unless you cast the variable and then if you cast it it will not recieve the return value of the parameter.
 
open standard project
remove the form and add one standard module...then
add the below code to that module

-------------------------------------

Public Sub main()
Dim strAryParms() As String
'strAryParms() should of the form 2/C:\dire\subdir
strAryParms() = Split(Command$, &quot;/&quot;)

If LenB(Command$) > 0 Then
If UBound(strAryParms) > 0 Then '0 is for days and 1 for directory
Call delOldFiles(strAryParms(0), strAryParms(1))
End If
else
end'end the application
End If
End Sub

-------------------------------------
And set the projet's command line parms like
&quot;2/C:\dire\subdir&quot; --> [2 forward slash C:\dire\subdir]
for testing purpose, while compiling take out these command line parameters...so ur compiled exe will have DOS command like C:\yourexe.exe 2/C:\Direcyory\subDirectory



Cracky -= Developer/DBA =-
visti:
 
hi gvphubli! thanks a lot for the detailed help. i think i am getting there - soon.

however, there is one small issue about ByRef argument type mismatch because the original code declares delDays as Integer whereas your code declares Dim strAryParms() As String.

how should i go about to solve this problem? your help is greatly appreciated!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top