|
-
Jul 10th, 2007, 08:54 AM
#1
Thread Starter
Junior Member
[RESOLVED] from DOS, set test=hello and pass to VB6
Hi,
Hoping someone can explain to a learner how to read a variable set in a dos batch file from vb script:
My VB script runs a batch file which sets a variable. when the batch file finishes and control is passed back to VB i then need to be able to determine what that variable has been set to.
-
Jul 11th, 2007, 05:57 AM
#2
Re: from DOS, set test=hello and pass to VB6
environ(envoiromentalvariable) will return permanent envoiromental variables, but ones set in a dos session are only available within that session, when i open a second dos session that vairable does not exist in it
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 12th, 2007, 02:36 AM
#3
Thread Starter
Junior Member
Re: from DOS, set test=hello and pass to VB6
Thanks for the reply,
I understand what you say but wanted to know if there was a way to access non permanant variable, ie those i set in DOS if i keep the dos session alive?
-
Jul 12th, 2007, 04:04 AM
#4
Re: from DOS, set test=hello and pass to VB6
not that i know of, but i have seen post here about console sessions, that may or may not be of some value, a simple solution would be to put the variable into a temp text file, that your program can then read
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 14th, 2007, 04:38 AM
#5
Thread Starter
Junior Member
Re: from DOS, set test=hello and pass to VB6
Again thanks for the reply.
I cannot use a txt file (one of my first thoughts) as i cannot write to the hard drive also I need to keep the solution as simple as possible, i still have 'L' plates .
Whilst i didnt want to write to the registry, i haven't understood this yet, seems to be a lot of code!, this is what i have resorted to.
In case this thread may be viewed by others trying to learn (like me) and wanting to do something similar, Below i outline my solution.
- Synchronously shell to dos and run batch file
- use reg add in batch file to set a registry string under HKEY_CURRENT_USER\Software\VB and VBA Program Settings\yourkey\yourkey
- when batch file terminates and control is returned to vb use GetSetting (<ApplicationName>, <Section>, <Key>[, Default]), to get value set in batch file.
If you dont shell synchronously then the value returned by GetSetting may not reflect correctly the value set from DOS.
As i have a solution that works, even though not a definative answer to my question i consider this resolved.
Any comment appreciated.
-
Jul 14th, 2007, 06:00 AM
#6
Re: [RESOLVED] from DOS, set test=hello and pass to VB6
funny as it may seem writing to the registry still means writing to the hard disk, but if the solution works for you then that is good enough
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|