0
votes

I'm still working on this VBScript script that types things for you for a video game I play. The reason why I'm still working on it is because I can't find a user-friendly way to stop the loop on the very bottom (Ctrl+F and type Do While). Every single thing works except for this stupid loop.

I've tried making a batch script that is just pause and to check for cmd.exe's process, but that didn't work for some reason. If you could figure it out, I'd prefer for that to be the way to end the loop. However, I don't really care which way you do it, as long as it's somewhat user-friendly (manually ending the wscript.exe process in Task Manager would obviously not be user-friendly).

Set objC = WScript.CreateObject ("WScript.Shell")

Sub sleep(Timesec)
  objC.Run "Timeout /T " & Timesec & " /nobreak", 0, True
End Sub

sleep(1)
objA = False
objH = False

objF = MsgBox("The Sell All Script that is a meme. By Vncz. Start?", 68, "Hello!")

Function chatsMessageBox()
  Do
    MsgBox "No."
  Loop
End Function

If objF = vbYes Then
  objB = InputBox("What is the username for your alt to pay? ALL LOWERCASE PLEASE, and '+(-)' for underscores.", "Username to pay")
Else
End If

If objB = "" Then
  objH = True
Else
  xdddddddddddddd = MsgBox("Press OK to check the username.", 64, "Check Username")
End If

If objF = vbNo Then
  objH = True
  MsgBox "Canceled."
Else
End If

If objH = True Then
  objA = False
ElseIf objB = "chatshitgetsplit" Then
  objD = MsgBox("No.", "16", "No.")
Else
  objE = MsgBox("Press OK to start the loop; run stop.bat to stop the loop.", 64, "You're in!")
End If

If objD = vbOK Then
  chatsMessageBox()
Else
End If

If objE = vbOK Then
  objA = True
Else
End If

'[]
'In place of this comment, stop the loop somehow (If something, objA = False)
'[]

Do While objA = True
  sleep(5)
  objC.SendKeys "t"
  sleep(1)
  objC.SendKeys "/sell all"
  sleep(1)
  objC.SendKeys "~"
  sleep(5)
  objC.SendKeys "t"
  sleep(1)
  objC.SendKeys "/pay " & objB & " 10000"
  sleep(1)
  objC.SendKeys "~" 
Loop
2
I hope to $deity that the chatsMessageBox function is never called...Martha

2 Answers

1
votes

Inside your Do While loop, place code like the following:

If <your condition> Then Exit Do
1
votes

The best solution is definitely editing that loop to end by default after a certain condition is met. At a quick glance, I see no exit for that loop no matter what the case. It will just continue sleeping and sending keys. Is that truly what you wanted?

1) Are you just supposed to iterate through that loop once? If that's the case, no reason for a loop.

2) If you know the number of times you want to iterate through those steps, you can use a counter. Example:

Dim i as Integer
i = 0

Do Until i = 5
    'rest of code'

    i = i + 1
Loop

This will allow you to loop through a set number of times.

By having it loop while objA = True and never looking at objA or calling another function/sub during your loop, it won't chnage.

3) If you are just trying to exit your loop once something is done and you know what that is, you can also do an if statement inside of the loop.

Do While objA = True
    'rest of code'
    If <condition> = True Then Exit Do
Loop