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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do.....Loop Not working with changing constant

Status
Not open for further replies.

llamositopia

Programmer
Joined
Apr 11, 2012
Messages
1
Location
CA
I need some help with a Do......Loop that isn't calling a function that I've requested and yet, that function is what would keep the program in a loop. The lines I have indented are not running whatsoever, let alone letting the loop make it's progress. I'm still new to Do....Loops so if someone could help me out that would be great.

start = msgbox ("Would you like to use our stocks program?", vbYesNo)
Do While start = vbYes
name = inputbox ("Enter stock name here. e.g. ""Apple Inc.""")
bprice = inputbox ("Enter price per share when bought here.")
shares = inputbox ("Enter number of shares.")
sprice = inputbox ("Enter sold price here. Enter 0 for not sold.")
bvalue = bprice*shares
svalue = sprice*shares
profit = svalue-bvalue
msgbox("Please open your spreadsheet and click the co-ordinate where you want the data to be entered.")
set a = createobject ("wscript.shell")
wscript.sleep (5000)
a.sendkeys (name)
wscript.sleep (10)
a.sendkeys ("{Tab}")
wscript.sleep (10)
a.sendkeys (bprice)
wscript.sleep (10)
a.sendkeys ("{Tab}")
wscript.sleep (10)
a.sendkeys (shares)
bvalue = bprice*shares
wscript.sleep (10)
a.sendkeys ("{Tab}")
wscript.sleep (10)
a.sendkeys (bvalue)
wscript.sleep (10)
a.sendkeys ("{Tab}")
if sprice = 0 then
a.sendkeys ("{Enter}")
wscript.quit
start = msgbox ("Would you like to continue?", vbYesNo)
else
a.sendkeys (sprice)
wscript.sleep (10)
a.sendkeys ("{Tab}")
wscript.sleep (10)
a.sendkeys (svalue)
wscript.sleep (10)
a.sendkeys ("{Tab}")
wscript.sleep (10)
a.sendkeys (profit)
wscript.sleep (10)
a.sendkeys ("{Enter}")
wscript.quit
start = msgbox ("Would you like to continue?", vbYesNo)
end if
Exit Do
msgbox ("Goodbye.")
Loop
 
Once your code hits a wscript.quit statement, the script is terminated.
 
Furthermore, why Exit Do ?
Try something like this:
Code:
Set a = CreateObject("wscript.shell")
Start = MsgBox("Would you like to use our stocks program?", vbYesNo)
Do While Start = vbYes
    Name = InputBox("Enter stock name here. e.g. ""Apple Inc.""")
    bprice = InputBox("Enter price per share when bought here.")
    shares = InputBox("Enter number of shares.")
    sprice = InputBox("Enter sold price here. Enter 0 for not sold.")
    bvalue = bprice * shares
    svalue = sprice * shares
    profit = svalue - bvalue
    MsgBox ("Please open your spreadsheet and click the co-ordinate where you want the data to be entered.")
    wscript.sleep (5000)
    a.SendKeys (Name)
    wscript.sleep (10)
    a.SendKeys ("{Tab}")
    wscript.sleep (10)
    a.SendKeys (bprice)
    wscript.sleep (10)
    a.SendKeys ("{Tab}")
    wscript.sleep (10)
    a.SendKeys (shares)
    bvalue = bprice * shares
    wscript.sleep (10)
    a.SendKeys ("{Tab}")
    wscript.sleep (10)
    a.SendKeys (bvalue)
    wscript.sleep (10)
    a.SendKeys ("{Tab}")
    If sprice <> 0 Then
        a.SendKeys (sprice)
        wscript.sleep (10)
        a.SendKeys ("{Tab}")
        wscript.sleep (10)
        a.SendKeys (svalue)
        wscript.sleep (10)
        a.SendKeys ("{Tab}")
        wscript.sleep (10)
        a.SendKeys (profit)
        wscript.sleep (10)
    End If
    a.SendKeys ("{Enter}")
    Start = MsgBox("Would you like to continue?", vbYesNo)
Loop
MsgBox ("Goodbye.")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top