VBS in HTA Do and Loop - vbscript

I have the below VB which works but I would like it to work in a HTA.
I cant seem to get it to carry out the loop section any ideas would be appreciated.
The script is used to write labels in ZPL with a StartNumber and EndNumber and the range between will print out on labels.
'Wscript.Echo ZPLText
ObjZebra.Write(ZPLText)
'Loop Counter
StartNumber = StartNumber + 1
'Loop Condition
Loop Until StartNumber > 0 + EndNumber
Wscript.sleep 500
objZebra.Close
Set objZebra = Nothing
End If
End If
Loop
End Function

Your code is still ill formatted. And it doesn't use proper syntax either.
I suggest you get a copy of script56.chm contained in scrdocen.exe (as long it is possible). and look at the do .. loop :
Repeats a block of statements while a condition is True or until a condition becomes True.
Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop
Or, you can use this syntax:
Do
[statements]
[Exit Do]
[statements]
Loop [{While | Until} condition]

Related

vbscript won't read file after 8Mb

I have a file written in vbs that wont read a file after about 8MB. I am currently using "Scripting.FileSystemObject". When I test the code, I notice that it runs fine until line ~79500, thats when the "AtEndOfStream" just results in True. I was looking for documentation, but it seems not to exist.
The code is supposed to show duplicate file information and put it in a separate file, which works well enough till around that line.
This is the section of code giving me the problem (it is the second reading function I have in the code):
Set first = fso.OpenTextFile(filePath + firstFileName)
Set secondFile = fso.OpenTextFile(filePath + secondFileName)
count = 0
countInLine = 0
Do Until secondFile.AtEndOfStream
lineMatches = false
lineOfSecond=secondFile.ReadLine
If count > 79440 Then
MsgBox("first line" & first.AtEndOfStream)
End If
Do Until first.AtEndOfStream
lineOfFirst =first.ReadLine
if lineOfSecond = lineOfFirst Then
lineMatches = True
Exit Do
End If
Loop
If Not lineMatches Then
writeFl.Write(count & "second" & lineOfSecond & vbCrLf)
End If
count = count + 1
Loop

Stopping Vbscript After Completion

Im making a game called cube, when I noticed a problem. I looked at Task Manager Fr Any Extra Programs, when I noticed tons of vbsscript running. I tried searching around, but no scripts worked for me. Heres my code (It plays A Sound)
Set Sound = CreateObject("WMPlayer.OCX.7")
Sound.URL = "Sounds\Hurt.mp3"
Sound.Controls.play
do while Sound.currentmedia.duration = 0
wscript.sleep 100
loop
wscript.sleep (int(Sound.currentmedia.duration)+1)*1000
WScript.Quit 1
It still doesn't want to stop. Please Help.
Try the below example
With CreateObject("WMPlayer.OCX.7")
.URL = "C:\Users\DELL\Desktop\tmp\hit.wav"
.controls.play
Do
WScript.Sleep 100
Loop Until .playState = 1 Or .playState = 10
' .PlayState https://msdn.microsoft.com/en-us/library/windows/desktop/dd564085(v=vs.85).aspx
' "Stopped" (completed) or "Ready" (file not found)
End With

Reading and writing an INI file

I have been toying with the below script to be able to read settings for use with my HTA (creating a game launcher).
Here is my current HTA:
http://pastebin.com/skTgqs5X
It doesn't quite work, it complains of the WScript object being required. While I understand Echo will not work like that in a HTA I am having trouble modifying the code so it will work. Even just removing all Echo references it still has an issue with objOrgIni on line 200 of the below code (with the WScript references removed):
http://pastebin.com/pGjv4Gh1
I don't even need that level of error checking as the INI will exist etc, I just need a simple way to read from and write to an INI in my scripting. Any help you guys can give me in achieving that would be great, it's a little advanced for me just yet, but I'd love an explanation as to why it fails.
There is no easy way to use INI files with VBScript. You'd have to write the functionality yourself or find some existing code that does it.
But do you really need an INI specifically or just a way to save settings? You could just keep all of your settings in a Dictionary object and serialize it as needed.
For example, here are two functions -- LoadSettings and SaveSettings -- that do just that.
Public Function LoadSettings(strFile)
Set LoadSettings = CreateObject("Scripting.Dictionary")
Dim strLine, a
With CreateObject("Scripting.FileSystemObject")
If Not .FileExists(strFile) Then Exit Function
With .OpenTextFile(strFile)
Do Until .AtEndOfStream
strLine = Trim(.ReadLine())
If InStr(strLine, "=") > 0 Then
a = Split(strLine, "=")
LoadSettings.Add a(0), a(1)
End If
Loop
End With
End With
End Function
Sub SaveSettings(d, strFile)
With CreateObject("Scripting.FileSystemObject").CreateTextFile(strFile, True)
Dim k
For Each k In d
.WriteLine k & "=" & d(k)
Next
End With
End Sub
Imagine you had the following settings file saved at c:\settings.txt:
Count=2
Name=Obama
You'd use the functions above like this:
Const SETTINGS_FILE = "c:\settings.txt"
Dim Settings
Set Settings = LoadSettings(SETTINGS_FILE)
' Show all settings...
WScript.Echo Join(Settings.Keys, ", ") ' => Count, Name
' Query a setting...
WScript.Echo Settings("Count") ' => 2
' Update a setting...
Settings("Count") = Settings("Count") + 1
' Add a setting...
Settings("New") = 1
' Save settings...
SaveSettings Settings, SETTINGS_FILE

VBScript Readline method ignoring 3rd IF statement

My script doesn't seem to check the "secLine" again for the 3rd if statement. It should remember what's stored in "secLine"....hmmmm
This is the text:
PHL DEPARTURES OVER TUSKY PLEASE FILE:
PHL..DITCH.V312.JIMEE..WAVEY..SHLEP..ACK..DIRECT
SCRIPT:
If InStr(firLine, "PHL DEPARTURES OVER TUSKY PLEASE") Then
secLine = objFile.ReadLine
If InStr(secLine, "JFK..PUT..BOS..DIRECT") or InStr(secLine, "PHL..DITCH.J225.JFK..PUT..BOS..DIRECT") Then
trans507="TUSKY"
ind507="1"
bunch of code
If Instr(secLine, "WAVEY..SHLEP..ACK..DIRECT") Then
ind507="2"
bunch of code
End If
End If
End If
Make sure that the first IF succeeds (right now your published data don't match the literal).
Don't use the shortened version(s) of the IF statement. Always use
If ... Then
...
End If
Make sure your indentation truly reflects the script's structure.
In code:
If InStr(firLine, "PHL DEPARTURES OVER TUSKY PLEASE") Then
secLine = objFile.ReadLine
If InStr(secLine, "JFK..PUT..BOS..DIRECT") or InStr(secLine, "PHL..DITCH.J225.JFK..PUT..BOS..DIRECT") Then
trans507="TUSKY"
ind507="1"
End If
If Instr(secLine, "WAVEY..SHLEP..ACK..DIRECT") Then
ind507="2"
End If
End If

loop autoit script until end of doc

I have an autoit script that basicly copies the first line of text, and then pastes it again in the same line. I would like to do this over and over until the end of the document. Any suggestions?
Run("notepad.exe filename.txt")
WinWaitActive("Untitled - Notepad")
Send("+{END}")
Send("^C")
Sleep (1000)
Send("{END}")
Sleep (1000)
Send(" ")
Send("^V")
Send("{HOME}")
Send("{DOWN}")
You can use this code:
$filename = "filename.txt"
Run("notepad.exe " & $filename)
WinWaitActive($filename & " - Notepad")
$lines= StringRegExp(FileRead($filename), #CR, 3)
$count = UBound($lines)
For $i = 0 To $count
Send("+{END}")
Send("^C")
Sleep (1000)
Send("{END}")
Sleep (1000)
Send(" ")
Send("^V")
Send("{HOME}")
Send("{DOWN}")
Next
You have to wait for the Window with the filename in it's title. If the filename has spaces inside, you need to put quotes around the parameter after notepad.exe.
Somehow you need to get the count of line numbers. I just read the whole file with AutoIt and search for a "carriage return". The resulting Array has the size of the line numbers. That number is then used in a For-...-To-...-Loop.
You can decrease the sleep-times to 100ms. And it would be much easier to use FileReadLine and probably FileWriteLine to do your task, as FileReadLine can be used until the end of file is reached. It will set #error to -1. See the documentation for more info.

Resources