Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 27th, 2007, 03:12 PM
Registered User
 
Join Date: Aug 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default basic program

I am trying to create a simple program to run some code on a lecroy oscilloscope. I have never used visual basic, so this is all new to me. I have read through a couple of intro tutorials, but the oscilloscope does not have visual studio and all I want is a super simple program. I have been editing the visual basic script file (.vbs) that the scope provides and then to run I just double click on that file in windows explorer. I have been using MsgBox() and InputBox() but what I would like is just two buttons Start and Stop. That could start my code and stop it gracefully. I was hoping to make the buttons into a flag and just check at the beginning of each loop for whether the flag was set to start or stop . Is there a simple way to do this?

Thanks,
Jordan

 
Old August 27th, 2007, 05:10 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I don't believe Visual Basic Script supports such things as forms, right?

You could use Word, Access, Excel, or any other application with VBA. Use that app to show a UserForm, then use the code in the VBA to issue the .VBS command.
If Visual Basic Script supports command-line arguments, you could build a string with the settings held in the command line.

Maybe the easiest thing to do is to buy an old version of VB (VB4, VB5, maybe even VB6), which you probably could get pretty cheap. Then you could use it to create a really nice little user interface to take the actions with this ’scope that you want to take.
 
Old August 28th, 2007, 12:36 PM
Registered User
 
Join Date: Aug 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply. Unfortunately I do not have a lot of time for this as the test that I need this for is next week. If I had more time I would, do just as you say and get vb6. Is there any way to gracefully exit a visual basic script that is set to run on a continuous loop?

Thanks,
Jordan

 
Old August 28th, 2007, 02:11 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Exit Do will get you out of a Do loop.
Exit Sub will get you out of the subroutine altogether.

When you say “...set to run,” do you mean containing an unending loop, or being called again and again by some other process?
 
Old August 29th, 2007, 10:22 AM
Registered User
 
Join Date: Aug 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am planning on running in an unending loop until the user decides to end the program. I am logging data for a test that is of variable length that will not be possible to determine before the test begins. If I use excel and enter the loop is there a way to check for button click inside the loop?

Thanks,
Jordan

 
Old August 29th, 2007, 02:25 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

The problem that you face in an endless loop is that under various circumstances the computer gets so busy that it stops “listening.” Then it will not respond to any changes, will not update the screen, etc.

The way to prevent this is to be sure to include the statement, “DoEvents” inside your loop.

So, if your loop and the button are both in/on the same form, at the top of the form's code module, create a Private Boolean variable that can be tested in the loop, and set by the button. (Being near the top of the module, outside any routines it will be visible/accessible to all code of the form (which is stated as having “Module-scope”).

In the button click event set the boolean variable to True.

In the loop, on each iteration, test the value of the Boolean. If True, exit the loop. (I'll use elipses to indicate the routine that the loop is in, in the following):
Code:
Option Explicit

Private TimeToLeave As Boolean

Private Sub TheButton_Click()
    TimeToLeave = True
End Sub

  . . .

    Do While True
        DoEvents
        ' Do your loop stuff...
        ' ...
        ' ...
        If TimeToLeave Then Exit Do
    Loop

  . . .
 
Old August 29th, 2007, 03:18 PM
Registered User
 
Join Date: Aug 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your help Brian that is exactly what I have been trying to do. Now all I have to do is figure out how to call a visual basic script file inside the loop. Maybe I need to make it into a sub or function and call that?

 
Old August 30th, 2007, 05:08 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You could try Shell... If you shell to a document, Word starts (I'm pretty sure). the same sort of thing hould happen with a .VBS.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a basic program to play online game glcn74 Pro Visual Basic 2005 1 June 10th, 2007 07:25 PM
Lottery Program Help...I'm using 2005 Visual Basic psycoblaster VB.NET 2002/2003 Basics 13 May 23rd, 2007 09:13 PM
Setup Project: Program not added in Start>Program arif_1947 VS.NET 2002/2003 2 March 31st, 2005 06:40 AM
Start a program inside another program Silje Classic ASP Professional 1 November 16th, 2004 02:08 AM
Visual basic.net (Lottery program) Brettvan1 VB.NET 2002/2003 Basics 10 October 1st, 2004 08:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.