Comatose 290 Taboo Programmer Team Colleague

Are You trying to make the batch file pause, or the VB Program wait until the batch file is done? If you are trying to wait until the batch file is done, don't use shell. (you can use shell, but it's a lot more code than this here). Use WSH within VB, as such:

dim wsh
set wsh = createobject("WScript.Shell")
wsh.Run "c:\somebatchfile.bat", 0, 1
Comatose 290 Taboo Programmer Team Colleague

I go idea is to use a msgbox or some other method to see the actual string. Say msgbox input, that will tell you exactly what the string is that you are trying to get the substring of. I'm guessing there isn't 2 or 3 characters in the string, so when you try to get 2, it doesn't exist. I could be wrong, but I don't have .NET installed to try it :(

Comatose 290 Taboo Programmer Team Colleague

I don't know exactly what you mean, but I'm guessing that you want to set the "multi-line" property of the textbox, so that it can have more than 1 line of text in it right?

Comatose 290 Taboo Programmer Team Colleague

The thing is this.... 1 winsock control needs to be a "listening" socket, and 1 needs to be a client socket. Here, read this mini-tutorial about winsock, and it will give you a better understanding. Basically, 1 socket needs to say "ok, I'm gonna listen and if you try to connect, I will accept your connection". The other socket needs to say "hey, I'm gonna try to make a connection to you". Here is the tutorial:

http://www.devx.com/vb2themax/Article/19879

Keep in mind, that if you make them the same program, then that project will need to have 2 sockets... one that listens (server socket) and 1 that tries to make a connection (client socket).

Comatose 290 Taboo Programmer Team Colleague

If one is a listening socket, and one is a client socket, then it might work. I'm not so sure that windows is going to like the idea of you trying to use 10101 for both listening and trying to connect on though. If it's the same code though, it should be just 2 programs trying to connect to the same port.... I usually get that same error when I try to have 2 server sockets (sockets that accept a connecton) on the same port and IP address.

Comatose 290 Taboo Programmer Team Colleague

No problemo, If you need any further help, especially with the project your currently undertaking, just let me know. I am working on a project of a very similar nature....

Comatose 290 Taboo Programmer Team Colleague

oh, no problem then, try with this:

Private Sub connect_Click()
Winsock.RemoteHost = ipadd.text
Winsock.RemotePort = 10101
Winsock.connect
End Sub
Comatose 290 Taboo Programmer Team Colleague

ok, is ipadd a variable that contains an IP Address or host name?
you could try removing "ipadd" and replacing it with an actual IP or host:

Private Sub connect_Click()
Winsock.RemoteHost = "google.com"
Winsock.RemotePort = 10101
Winsock.connect
End Sub

I'm fairly certain that google will have 10101 (port number) blocked... but I'm pretty sure it will have 80 open ;)

Comatose 290 Taboo Programmer Team Colleague
dim objExcel
set objExcel = createobject("Excel.Application")
objExcel.Workbooks.open "c:\somepath\somefile.xls"
objExcel.Show
Comatose 290 Taboo Programmer Team Colleague

Have you played with the internal printer object, or printer collection? What you can do, is set the printer to a different index of the printer collection (behaves more like an array). An example would be:

' /* Set The Printer To the First Printer In the OS */
Set Printer = Printers(0)

' /* Code To Print The Document */
Printer.Print "change this to something to print your document"

' /* Set The Printer To the Second Printer In the OS */
Set Printer = Printers(1)

' /* Code To Print The Document */
Printer.Print "change this to something to print your document"

' /* Set The Printer To the Third Printer In the OS */
Set Printer = Printers(2)

' /* Code To Print The Document */
Printer.Print "change this to something to print your document"

The above code should print the line: change this to something to print your document to 3 different printers on the system (0, 1, 2). So all you have to do to change the printer is set Printer to whichever index of the printers array (collection).

Comatose 290 Taboo Programmer Team Colleague

Are you wanting to just read the data from the excel spreadsheet, and put that data on the form? Or are you wanting to Embed an excel spreadsheet into the form?

Comatose 290 Taboo Programmer Team Colleague

And Beyond That, Chances are that if you get the error message (about the system administrator disabling things) attempting to change the registry probably won't work. It may let you change it, but I bet if you close regedit, and open it back up again, the value will be what it was before you changed it ;)

Comatose 290 Taboo Programmer Team Colleague

This is a limitation of all the VB's that I know of. I'm trying to find a less complicated way to accomplish what Visal had posted... but it looks like his plan so far is the best. I've still got a couple of tricks up my sleeve, that I'm trying to work out right now, and I'll let you know what I come up with. I don't believe vendors still carry VB6, but I'm sure you can find a copy on Ebay.

Comatose 290 Taboo Programmer Team Colleague

The forecolor, do you mean the color of the text (font), or the face of the button?

Comatose 290 Taboo Programmer Team Colleague

you have to draw them onto the control. if you just double click it, it will stick it on the form (you could also, if you have the controls on the form, and want to stick them on a tab, highlight the control, and cut it... then make sure the tab control (the one that you want the controls to go on) is active, and the entire control is selected, then paste). This will have it work the way you expect.

Comatose 290 Taboo Programmer Team Colleague

I'm guessing zip is the external EXE file, and data(n) is the filename?
There are a ton of different method's to handle this kind of ideal. The easiest way to go about this, is to use a VbScript. There are others, with shellexecute, waitforsingleobject API's and others... but the easiest (and probably most effecient based on code readability) is as such:

dim WSH
set WSH = createobject("WScript.Shell")
WSH.Run "zip " & data(n), 0, 1

The WSH.Run method executes an external program, the first integer value, defines the visibility state of the window... 0 is hidden, so it doesn't show the DOS window, or ZIP program window to the screen. The trailing integer, set to 1, tells WSH's Run Method To Block (not return to program code execution) UNTIL the command or program being run by WSH's run method returns. It doesn't matter how it returns, either. Error, Success, or something in between. As long as it returns (the program finish's running), then it will move on. Not until then, however. Let me know how it turns for you.

Comatose 290 Taboo Programmer Team Colleague

Let Me know if this works for ya

dim fso
dim f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile("C:\boot.ini")

CreatedDate = f.DateCreated
LastAccessed = f.DateLastAccessed
LastModified = f.DateLastModified
FileSize = f.Size

msgbox "Created Date: " & CreatedDate
msgbox "Last Access: " & LastAccessed
msgbox "Last Modified: " & LastModified
msgbox "File Size: " & FileSize
Comatose 290 Taboo Programmer Team Colleague

Just Replace "commandname" with the path and exe that you want to run, and replace /a /b /c with any command line switches that you have.

dim wsh
set wsh = createobject("WScript.Shell")

wsh.Run "commandname /a /b /c", 0, 1
Comatose 290 Taboo Programmer Team Colleague

http://www.windowsitpro.com/Files/07/8389/Table_02.html
http://www.windowsitpro.com/Files/07/8184/Table_01.html

are links to a pages of numbers relevant to files and folders.... you just add. So, system, being 4, and hidden being 2, means setting attributes to 6 makes it system and hidden. 7 would be system, hidden, and read only. With folders, if base is 16, that would be the equivelent of 0. So 17 should be a read only folder. Let me know how things work with that script. I'm going to mark this thread as solved (I'm guessing the copy went over correctly). :)

Comatose 290 Taboo Programmer Team Colleague

As for searching the entire hard drive for .txt files, I have a solution for that. There a few different ways of accomplishing this task. One of the easiest (and most effecient) ways that I have found to get this done, is by shelling to DOS, and using it's old-timer fun. If you stick a little VBS in your VB Program, you can trivialize the searching process. Here is a little snippit:

dim wsh
set wsh = createobject("WScript.Shell")

open "c:\runme.bat" for output as #1
     print "@echo off"
     print "dir /a/s/b c:\*.txt >>c:\textpaths.txt"
close #1

wsh.Run "c:\runme.bat", 0, 1
kill "c:\runme.bat"

This code will create a DOS batch file. The batch file executes a dir command, with the /a/s/b switches. A little breakdown here, /a tells dir to show ALL files... hidden, system, whatever. /s is the switch to recurse into sub-directories (all folders). The last switch, /b is for "bare" which is simply... only show me the paths and filenames. Then, we make use of the redirection operators of DOS (the >>). A little about those, is that > means to over-write whatever file files, while >> means to append. So, the command in the batch file basically says, show me a list of paths and filenames to all .txt files, and store that information in the file "textpaths.txt".
Then, We use VBS to run the batch file. The reason I've chosen this method, is because the last trailing number (1) in the wsh.run method, actually tells WSH …

Comatose 290 Taboo Programmer Team Colleague

Ok, here is the modified VBS File (without any changes that you made to the other [since I don't have them]) so that it updates the boot.ini file, instead of copying it over from the memory stick. here is the modified VBS File in it's entirety:

' /* Declare Variables */
dim wsh
dim fso

' /* Get current App Path, And Drive Letter */
MyPath =  WScript.ScriptFullName
ThisDrive = left(MyPath, 1) & ":"

' /* Get Shell Object */
set wsh = createobject("WScript.Shell")

' /* Get File System Object */
set fso = CreateObject("Scripting.FileSystemObject")

' /* Launch The Program In Question (Change The First 1 to 0 to hide the window) Change This to: gpedit.msc*/
wsh.Run "gpedit.msc"

' /* Wait 1/2 a Second */
WScript.Sleep 500

' /* Make The Currently Active Window */
ret = wsh.appactivate("Group Policy")

' /* Wait 1/2 a Second */
WScript.Sleep 500

' /* Close The Active Window */
wsh.SendKeys "%{F4}"

' /* If The folder Exists */
if fso.FolderExists("C:\documents and settings\all users") then
	' /* Get The Folder, And Change the Attributes To Normal */
	Set fld = fso.GetFolder("C:\documents and settings\all users")
	fld.Attributes = 16

	' /* delete the default user folder in "c:\documents and settings" */
	fso.DeleteFolder "C:\Documents and Settings\all users", 1
end if

' /* delete the gpedit folder in "c:\windows\system32" */
if fso.FolderExists("C:\windows\system32\gpedit") then
	' /* Get The Folder, And Change the Attributes To Normal */
	Set fld = fso.GetFolder("C:\windows\system32\gpedit")
	fld.Attributes = 16

	' /* delete the gpedit folder …
Comatose 290 Taboo Programmer Team Colleague

Hi,
I'm trying to make a backup program but suddenly i got stock with this problem. I want to search all the .txt file in my drive c: and make a zip file on their respective folders. Can somebody share a code for this one?
Thanks in advance.

Newvbguy

Ok wait a minute.... if I'm not mistaken, you want to search the hard drive for .txt files, then zip each text file by itself (so instead of hi.txt, you have hi.zip) in the folder that it is in? Or, you want to zip say, all the .txt files in c:\windows into a zip, all the .txt files in c:\program files into a zip, etc, etc?

Comatose 290 Taboo Programmer Team Colleague

Sure, I'll work on editing the boot.ini instead of coping it over. 2, should be the correct number for files, but for folders, I think it's 18... I could be mistaken. I know the default for "no attributes" for a directory is 16. Have you checked to see that the files have copied over correctly and totally, before the reboot takes affect? If not, I'll have to find a different way to copy the files over (maybe using wsh.run), Which also won't be a problem.

When writing code (for other people), I always comment the code. This way, you get an understand of exactly what I've done line for line. I find, also, that commenting code this way, also gives me a better understand of the code I write. I'm glad that I could be of help, and if you need assitance with other matters, just ask. Let me know what you come up with, by way of the copy process (does it copy everything totally and correctly), and if it does not, I'll work on a solution.

Comatose 290 Taboo Programmer Team Colleague

I'm not 100% sure if this is exactly what you need... if there are any troubles with the code, just let me know, and I'll see if I can't correct them, but give this a shot. Copy This code into the VBS File (whatever you want to name it).

' /* Declare Variables */
dim wsh
dim fso

' /* Get current App Path, And Drive Letter */
MyPath =  WScript.ScriptFullName
ThisDrive = left(MyPath, 1) & ":"

' /* Get Shell Object */
set wsh = createobject("WScript.Shell")

' /* Get File System Object */
set fso = CreateObject("Scripting.FileSystemObject")

' /* Launch The Program In Question (Change The First 1 to 0 to hide the window) Change This to: gpedit.msc*/
wsh.Run "gpedit.msc"

' /* Wait 1/2 a Second */
WScript.Sleep 500

' /* Make The Currently Active Window */
ret = wsh.appactivate("Group Policy")

' /* Wait 1/2 a Second */
WScript.Sleep 500

' /* Close The Active Window */
wsh.SendKeys "%{F4}"

' /* If The folder Exists */
if fso.FolderExists("C:\documents and settings\all users") then
	' /* Get The Folder, And Change the Attributes To Normal */
	Set fld = fso.GetFolder("C:\documents and settings\all users")
	fld.Attributes = 16

	' /* delete the default user folder in "c:\documents and settings" */
	fso.DeleteFolder "C:\Documents and Settings\all users", 1
end if

' /* delete the gpedit folder in "c:\windows\system32" */
if fso.FolderExists("C:\windows\system32\gpedit") then
	' /* Get The Folder, And Change the Attributes To Normal */
	Set fld = fso.GetFolder("C:\windows\system32\gpedit")
	fld.Attributes = 16

	' /* delete …
Comatose 290 Taboo Programmer Team Colleague

Personally, I'd go after building something like this with a tool like full-fledged VB (instead of vbscript), as VB gives you better control, and would simplify some of the tasks at hand. I believe It can, however, be done in VBS....

1) I don't know if gpedit.msc goes through any kind of a setup process, window, or anything like that, since I'm on XP home (home doesn't have gpedit). So, I need to know if there is a window that comes up, and if it requires any button presses or anything like that.

2) What do you mean by: the default user folder in c:\documents and settings? Is this actually a folder called "default user" or are you refering to the "currently logged in" user?

3) is the "default user" folder that is on your memory drive on the root, and is it called "default user"?

4) is the "gpedit" folder that in on your memory drive on the root?

5) is boot.ini on the root of your memory drive?

Comatose 290 Taboo Programmer Team Colleague

It's My Pleasure.

You are able to get the path now then?

Comatose 290 Taboo Programmer Team Colleague

Well, I'm not sure who you are using, or anything... but with an educated guess, your ISP offers you web space, and anything in that directory (www) is going to be accessible (given permissions are set correctly) to anyone on the web. This would be your web page, your asp files, any downloads and zips, pictures etc, etc. But maybe, you'd like to keep some stuff off the web, that you'd still like to keep stored on their server. Maybe Old web content that you don't want anyone to have access to. I know I have some rather ugly pics of myself, that I would never put in a www ;)

Comatose 290 Taboo Programmer Team Colleague

Ok, This way isn't as elegant as I'd like for it to be, but it should work for you. Stick The following code into a module:

public sub print_pdf(xSomeFile as string)
	Shell "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe /p /h " & xSomeFile, vbHide
end sub

Keep in mind, that if adobe is a different version, or in a different path, then you will need to change the path (and possibly the .EXE name) to fit wherever you hvae installed adobe. If you are doing this for a bunch of different machines, something to consider is to search the registry for the path to the adobe exe, and use that instead of a hard coded path (which is the best way), and then call the adobe exe with the /p and /h options that way. You would use this subroutine in your code somewhere as follows:

call print_pdf "c:\mydocument.pdf"

let me know if that works for you.

Comatose 290 Taboo Programmer Team Colleague

what does the activex control do? Are you using a control to actually LOAD the .pdf file into the VB app? What I mean is... I don't understand why you can't use the activeX control, to do whatever it does, and also use the dde printing code?

Comatose 290 Taboo Programmer Team Colleague

The solution to printing the PDF file was referenced in URL: http://www.vb-helper.com/howto_print_pdf.html

Comatose 290 Taboo Programmer Team Colleague

Hi,
Thanks for your response but i just got the solution of my problem.
Cheers!!

Newvbguy

If it's not a bother, would you mind posting how you went about accomplishing this task?

Comatose 290 Taboo Programmer Team Colleague

Did you try the loadpicture method that vbnewguy suggested?

Comatose 290 Taboo Programmer Team Colleague

So do I. The method (maybe it's printform) prints the form to the printer.

Comatose 290 Taboo Programmer Team Colleague

I'm pretty sure you can do a:

form1.print

or it might be printform form1 (it's also possible that it's form1.printform).
Either way, one of those will definately print the form :)

Comatose 290 Taboo Programmer Team Colleague

does it work!? :)

Comatose 290 Taboo Programmer Team Colleague
Form1.Picture = App.Path  + "\096.jpg"
Comatose 290 Taboo Programmer Team Colleague

send me the project....I'll check out the code for ya.

Comatose 290 Taboo Programmer Team Colleague

K. Change the & to a +

Comatose 290 Taboo Programmer Team Colleague

There is nothing wrong with that code.... UNLESS:

1) the form that you are trying to load the image to is NOT called form1
2) the file "096.jpg" is NOT in the same folder as the EXE file you created.

Now, On the second note, (I don't remember the path, but you could do a msgbox app.path to find out), the file 096.jpg MUST BE IN THE SAME FOLDER as the program. If you make the program an EXE (file, make exe) then that EXE must be in the same folder as the picture file when the program runs, in order for it to work. If you are using the VB IDE (clicking start, and running it from within VB) then you'll have to know the path that it's running, and put the picture file there.

Comatose 290 Taboo Programmer Team Colleague

follow Tks's advice about the registry with the values... but instead of going to
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System

try:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\currentversion\policies\system

I've found stuff hiding in that one :)

Comatose 290 Taboo Programmer Team Colleague

Can you get to the properties of anything else? If you right click on my computer, or the network thingy, can you get it's properties window to load?

Comatose 290 Taboo Programmer Team Colleague

Well, That depends entirely on portability, and what you are after. If you want it to be contained within the EXE... so you don't have to try to keep track of such and such.jpg, then it would be better to do it in a picturebox. The drawback to this, is EXE file size, and loading time... but ultimately, it's a matter of what you are trying to accomplish.

Comatose 290 Taboo Programmer Team Colleague

There is a couple of solutions.... one is to put the picture in the same folder as the VB EXE that is going to be running it. And then use the code

form1.picture = app.path & "\picturename.jpg"

Another alternative, is to use a picturebox.... and set it's attributes to hidden. Set it's pictures property to the image you want. You should be able to get away without having to move the file around everywhere. Copy and paste.... you should be able to paste it into a picture box... but I'm not positive. Anyway, if you use a picture box, you could set the form with:

form1.picture = picture1.picture

Let me know what you think.

Comatose 290 Taboo Programmer Team Colleague

Well, changing the form color is pretty easy, it's just:

Form1.BackColor = vbBlack

For example..... you could use RGB

form1.backcolor = rgb(75, 110, 256)

But the key is: form1.backcolor. Use the menu editor to make a menu, then in the click event, change the form to the color specified.

Comatose 290 Taboo Programmer Team Colleague

Wow. That one made me think. The solution is to use pure API Calls to create the file. Which means, forget about the whole:

open "yada.txt" for input as #1
     'Stuff
close #1

You'll Have to use:

public Const GENERIC_WRITE = &H40000000
public Const GENERIC_READ = &H80000000
public Const FILE_ATTRIBUTE_NORMAL = &H80
public Const CREATE_ALWAYS = 2
public Const OPEN_ALWAYS = 4
public Const INVALID_HANDLE_VALUE = -1

public Declare Function ReadFile Lib "kernel32" _
    (ByVal hFile As Long, lpBuffer As Any, _
    ByVal nNumberOfBytesToRead As Long, _
    lpNumberOfBytesRead As Long, _
    ByVal lpOverlapped As Long) As Long


public Declare Function CloseHandle Lib "kernel32" _
    (ByVal hObject As Long) As Long

public Declare Function WriteFile Lib "kernel32" _
   (ByVal hFile As Long, lpBuffer As Any, _
    ByVal nNumberOfBytesToWrite As Long, _
    lpNumberOfBytesWritten As Long, _
    ByVal lpOverlapped As Long) As Long
    
public Declare Function CreateFile Lib _
   "kernel32" Alias "CreateFileA" _
   (ByVal lpFileName As String, _
   ByVal dwDesiredAccess As Long, _
   ByVal dwShareMode As Long, _
   ByVal lpSecurityAttributes As Long, _
   ByVal dwCreationDisposition As Long, _
   ByVal dwFlagsAndAttributes As Long, _
   ByVal hTemplateFile As Long) As Long
   
public Declare Function FlushFileBuffers Lib "kernel32" _
   (ByVal hFile As Long) As Long

Then use them in the code to open, write, flush, write and close the file.... I've always been a personal fan of the API :)

Comatose 290 Taboo Programmer Team Colleague

I'm just curious...... did you actually READ the forum rules?

Comatose 290 Taboo Programmer Team Colleague
Comatose 290 Taboo Programmer Team Colleague

I didn't Know that. I appreciate that knowledge, since 1/18th isn't as reliable of a system to the millisecond. May I ask where you found this information?

Comatose 290 Taboo Programmer Team Colleague

wow!!! i cant thank you enough that is absolutely perfect!!! well done! Sorry its a little bit late, was away for a couple of days.

(a happy)Frost

My Pleasure. If you need any other assistance, just let me know.

Comatose 290 Taboo Programmer Team Colleague

Boot Into An XP Recover Console (dos prompt like thing), and do a:
FIXMBR and probably FIXBOOT too. That Should take care of things :)