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!

Code just stops 3

Status
Not open for further replies.

arbytech

MIS
Feb 10, 2004
92
US
I am working on a little program to check drive space but my code just stops (see below). What am I doing wrong (I'm fairly new to VB6).

Thanks in advance!!!

Private Declare Function SHGetDiskFreeSpace Lib "shell32" Alias "SHGetDiskFreeSpaceA" (ByVal pszVolume As String, pqwFreeCaller As Currency, pqwTot As Currency, pqwFree As Currency) As Long
Private Sub Form_Load()
Form1.Caption = "Disk Space Check"
Call spcchk
End Sub
Private Sub spcchk()
SHGetDiskFreeSpace "C:\", FreeCaller, Tot, Free
Label2.Caption = Format$(Free * 10000, "###,###,###,##0")
If Free >= 320000 Then Label2.BackColor = &H80FF80 Else
Label2.BackColor = &HFF&
DoEvents
End Sub

Private Sub mnuExit_Click()
Unload Me
End
End Sub

Private Sub mnuStart_Click()
If mnuStart.Checked = True Then
mnuStart.Checked = False
Form1.Caption = "Disk Space Check Is Stopped"
Else
mnuStart.Checked = True
Form1.Caption = "Disk Space Check Is Running"
End If
-----End Sub-----It stops right here when I toggle through using Step Into and never goes down to the next sub

Private Sub spcchk2()
SHGetDiskFreeSpace "C:\", FreeCaller, Tot, Free
Label2.Caption = Format$(Free * 10000, "###,###,###,##0")
If Free >= 20000 Then Label2.BackColor = &H80FF80 Else
Label2.BackColor = &HFF&
DoEvents
End Sub
 
You don't seem to call the spcchk2() sub anywhere in the code. You would have to call the sub for it to run.

Hope this helps

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
To elaborate:

When you step through your code and reach the line
Code:
Call spcchk
It will jump to the sub spcchk. You will have call spcchk2 in the same way in the appropriate point in your code that you want it to run.

Hope this helps

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
This might be easier ...
Code:
[blue]Debug.Print CreateObject("scripting.filesystemobject").GetDrive("c:").FreeSpace[/blue]
 
Good call strongm [smile]

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Thanks for your help!

HayleyQuinn - Duh I should have seen that there wasn't a call for the sub!? Is it possible to just have the program go down to a sub without calling it?

strongm - How would I use the debug.print line to put that data into a variable I could use?

Thanks again!!!
 
The only way to have a event called without calling it is by a timer or DoEvents. Debug.print does not do anything else other than display the variable - so you can't asign using it. Just use his CreateObject("scripting.filesystemobject").GetDrive("c:").FreeSpace and get the value from it

Code:
dim lng as long
lng = CreateObject("scripting.filesystemobject").GetDrive("c:").FreeSpace
 
Instead of [blue][tt]debug.print[/tt][/blue] have [blue][tt]Free =[/tt][/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top