Results 1 to 6 of 6

Thread: [RESOLVED] from DOS, set test=hello and pass to VB6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    30

    Resolved [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.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    30

    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?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    30

    Resolved 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.

    1. Synchronously shell to dos and run batch file
    2. use reg add in batch file to set a registry string under HKEY_CURRENT_USER\Software\VB and VBA Program Settings\yourkey\yourkey
    3. 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.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
  •  



Click Here to Expand Forum to Full Width