Start CMD Window Minimized? - vb.net

I use the following code to start a process and then wait for it to exit. It works, but the CMD window is full size. I'd rather have it start at least minimized or possibly hidden. Thanks in advance!
Edit: If I am doing this in a method does not allow me to change the method in which to specify either hidden or minimized, how do I go about this?
mProcessParameters = New StringBuilder
mProcessParameters.Append(" -input:" & Chr(34) & "\\server\waybill\Waybill files\")
mProcessParameters.Append(txt_Year.Text & " Data\Interim Data Processing\")
mProcessParameters.Append(mBPGM_FileNames(mLooper2) & mInFileNameSuffix & Chr(34) & " ")
mProcessParameters.Append(" -config:" & Chr(34) & "\\server\waybill\Waybill files\")
mProcessParameters.Append(txt_Year.Text & " Data\Interim Data Processing\")
mProcessParameters.Append(mBPGM_FileTypes(mLooper2) & mCfgFileNameSuffix & Chr(34))
mProcess.Start(My.Settings.BatchProg, mProcessParameters.ToString).WaitForExit()

Related

Microsoft.Office.Interop - ReplaceText (with) *NewLine* in Word.Table

I am having an application that uses Microsoft Word 2016 / the Interop interface to call the replace function. This way the application replaces some texts like 'Customername' to the actual name of the customer. Surely this is not the best way to do so, but thats how the application was build back in the days. Now I have to do some adjustments to the formatting facing a problem with the named function.
One of the Texts getting replaced is "[TELNR]" , beeing replaced with all known numbers of the customer, one number per line. Inserting New Lines as vbCr works great on a blank page as you can see top of the screenshot. The same called function will not put a new lines into a table (second page on the left) and won't even touch a textbox (second page on the right).
I have tried passing Line breaks as ^p, \n\r, \n, vbClRf / vbNewLine, vbCr. None of these will work.
I haven't found anything usefull on google or SO. Do you have ideas or a reason what might cause or even solve the problem?
#Region "Sample Strings"
Dim sample1 As String = "t:022220000000" & vbNewLine & "h:022221111111" & vbNewLine & ":0222222222222" & vbNewLine & "f:022223333333"
Dim sample2 As String = "t:022220000000" & vbCr & "h:022221111111" & vbCr & ":0222222222222" & vbCr & "f:022223333333"
Dim sample3 As String = "t:022220000000" & "^p" & "h:022221111111" & "^p" & ":0222222222222" & "^p" & "f:022223333333"
Dim sample4 As String = "t:022220000000" & "\n" & "h:022221111111" & "\n" & ":0222222222222" & "\n" & "f:022223333333"
Dim sample5 As String = "t:022220000000" & "\n\r" & "h:022221111111" & "\n\r" & ":0222222222222" & "\n\r" & "f:022223333333"
Dim sample6 As String = "t:022220000000" & vbCrLf & "h:022221111111" & vbCrLf & ":0222222222222" & vbCrLf & "f:022223333333"
#End Region
Private Sub replaceText(file As Microsoft.Office.Interop.Word.Document, find As String, replaceWith As String)
// First line was commented out for the ^p try
If replaceWith.Contains("^") Then replaceWith = replaceWith.Replace("^", "")
file.Content.Find.Execute(FindText:=find, ReplaceWith:=replaceWith, Replace:=Word.WdReplace.wdReplaceAll)
End Sub
The following was function was used to insert the textbox.

String sets its Value to "False"

So, I'm currently working on a program that should create Lua-Scripts for the Unitale-Engine. I added a "New Project" button which should create a new project file when you click it. I want this file to contain the default project-file-text. So i did this:
Dim File1 As String = "monster{" & vbNewLine & "COMMENTS=Ribbit, ribbit.;Croak, croak.;Hop, hop.;Meow." & vbNewLine & "COMMANDS=Compliment;Threaten" & vbNewLine & "DEFAULT_SPRITE=None" & vbNewLine & "NAME=Froggit" & vbNewLine & "HP=10" & vbNewLine & "ATK=1" & vbNewLine = "DEF=0" & vbNewLine & "CHECK_MESSAGE=Life is difficult for this enemy." & vbNewLine & "HandleAttack=" & vbNewLine & "OnDeath=" & vbNewLine & "HandleCustomCommand=" & vbNewLine & "}"
Dim File2 As String = vbNewLine & "encounter{" & vbNewLine & "DEFAULT_MUSIC=Fight" & vbNewLine & "ENCOUNTER_TEXT=Froggit hops close." & vbNewLine & "NEXTWAVES=1" & vbNewLine & "WAVETIMER=6" & vbNewLine & "ARENASIZE=155;130" & vbNewLine & "ENEMIES=Froggit" & vbNewLine & "ENEMYPOSITIONS=0;0" & "EncounterStarting=" & vbNewLine & "EnemyDialogueStarting=" & vbNewLine & "EnemyDialogueEnding=" & vbNewLine & "DefenseEnding=" & vbNewLine & "HandleItem=" & vbNewLine & "HandleSpare=" & vbNewLine & "EnteringState=" & vbNewLine & "Update=" & vbNewLine & "}"
Dim File3 As String = vbNewLine & "waves{" & vbNewLine & "1=Do Nothing" & vbNewLine & "}" & vbNewLine & "end"
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\UnitaleMaker\Projects\" & PJNBox.Text & ".umproj", File1 & File2 & File3, False)
Yes, that is a lot of text. The problem is, that File1 always sets its value to "False" when it is declared. I thought that is because the string is too long, so I split it to 3 parts, but it doesn't work.
Any help would be apprechiated!
~ Mika // OneByte_
Starting with VB 14 (Visual Studio 2015), you can span String literals across multiple lines. VB 14 also adds String interpolation, which makes for much cleaner code. You could write your code like the following which would have kept you from having made your mistake of & vbNewLine = "DEF=0" &and would overall make the code easier to read.
I am also assuming you forgot a newline in "ENEMYPOSITIONS=0;0" & "EncounterStarting=" and I have indented the parts between the {}. I combined File1, File2, and File3 back into a single string since you stated you broke them up in the question, I assumed you'd rather have it all in one string.
Dim File1 As String = "monster{
COMMENTS = Ribbit, ribbit.;Croak, croak.;Hop, hop.;Meow.
COMMANDS=Compliment;Threaten
DEFAULT_SPRITE=None
NAME=Froggit
HP=10
ATK=1
DEF=0
CHECK_MESSAGE=Life Is difficult For this enemy.
HandleAttack=
OnDeath=
HandleCustomCommand=
}
encounter{
DEFAULT_MUSIC = Fight
ENCOUNTER_TEXT =Froggit hops close.
NEXTWAVES=1
WAVETIMER=6
ARENASIZE=155;130
ENEMIES=Froggit
ENEMYPOSITIONS=0;0
EncounterStarting=
EnemyDialogueStarting=
EnemyDialogueEnding=
DefenseEnding=
HandleItem=
HandleSpare=
EnteringState=
Update=
}
waves{
1 =Do Nothing
}
End"
My.Computer.FileSystem.WriteAllText($"{My.Computer.FileSystem.SpecialDirectories.MyDocuments}\UnitaleMaker\Projects\{PJNBox.Text}.umproj", File1, False)
Please learn to use string.format.
Also I changed & to new line in file2:
"ENEMYPOSITIONS=0;0" & "EncounterStarting="
I just assumed you forgot to add new line there.
Alss Environment.NewLine is the best option for new lines as it is universal.
Dim File1 As String = String.Format("monster{{{0}COMMENTS=Ribbit, ribbit.;Croak, croak.;Hop, hop.;Meow.{0}COMMANDS=Compliment;Threaten{0}DEFAULT_SPRITE=None{0}NAME=Froggit{0}HP=10{0}ATK=1{0}DEF=0{0}CHECK_MESSAGE=Life is difficult for this enemy.{0}HandleAttack={0}OnDeath={0}HandleCustomCommand={0}}}", Environment.NewLine)
Dim File2 As String = String.Format("{0}encounter{{{0}DEFAULT_MUSIC=Fight{0}ENCOUNTER_TEXT=Froggit hops close.{0}NEXTWAVES=1{0}WAVETIMER=6{0}ARENASIZE=155;130{0}ENEMIES=Froggit{0}ENEMYPOSITIONS=0;0{0}EncounterStarting={0}EnemyDialogueStarting={0}EnemyDialogueEnding={0}DefenseEnding={0}HandleItem={0}HandleSpare={0}EnteringState={0}Update={0}}}", Environment.NewLine)
Dim File3 As String = String.Format("{0}waves{{{0}1=Do Nothing{0}}}{0}end", Environment.NewLine)
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\UnitaleMaker\Projects\" & PJNBox.Text & ".umproj", File1 & File2 & File3, False)

Visual Basic string syntax error while trying to automate WinSCP

I wish to use thing string useing Shell() function to automate an upload of an excel file to an ftp server whenever a save occurs:
strShell = "C:\Program Files\WinSCP\WinSCP.exe /console /command " & Chr(34) & "option batch on" & Chr(34) & " " & Chr(34) & "open user:pass#localhost" & Chr(34) & " " & Chr(34) "put " ThisWorkbook.Path & "/" & ThisWorkbook.Name & "/home/User/Directory" & Chr(34) & " " & Chr(34) "exit" & Chr(34)
For some reason I get syntax error for this string. My knowledge in VBA isn't wide but I going over MSDNfor the last couple of hours didn't seem to help at all.
I suspect that you need more quotes for file paths containing spaces. Something like
strShell = "'C:\Program Files\WinSCP\WinSCP.exe' /console /command " & Chr(34) &....
you also forgot some "&" like on the 3dr line:
Chr(34) & "put " & ThisWorkbook.Path &
Again on that line, you might need to surround filenames with quotes !
Your best help would be to include a Debug.Print strShell and watch the result in the VBE Immediate Window (^G)
According to the documentation for WinSCP, you need to add the double quotes around your commands. For Example:
WinSCP.exe /command "option batch abort"
So in VBA that would be: "WinSCP.exe /command ""option batch abort"""

Write multiple lines with quotes in a text file vb.net

Hi Is there any easier way to write multiple lines in a file which has things like quotes in and other things like that or is the only way to do it like this
Dim objwriter As New System.IO.StreamWriter(AppsDir & "EthIPChanger.bat")
objwriter.WriteLine("#echo off")
objwriter.WriteLine("netsh interface ip set address name=""" & "Local Area Connection""" & " static " & TB_EthIPAddress.Text & " " & TB_EthSubnetMask.Text & " " & TB_EthDefaultGateway.Text & " 1")
objwriter.WriteLine("netsh interface ip set dns """ & "Local Area Connection""" & " static " & TB_EthDNS1.Text)
objwriter.WriteLine("ipconfig /all > """ & AppsDir & "NetworkInfo.txt""")
objwriter.WriteLine("echo hi > """ & AppsDir & "CheckLen.txt""")
objwriter.Close()
I know if you are using python you can do """ and then do anything inside that and end it with """
Does anything like that exist in vb.net?
thanks
If you use objwriter.Write - then you can supply the vbcrlf yourself - and then you can put multiple 'lines' in one write statement.
For example:
Dim str2write As string
str2write = "firstline" and Chr(34) & Chr(34) & vbcrlf
str2write &= Chr(34) & "second line" and Chr(34) & vbcrlf & vbcrlf
objwriter.write(str2write)
objwriter.close()
You can try with StringBuilder:
Dim objwriter As New System.IO.StreamWriter(AppsDir & "EthIPChanger.bat")
Dim textToWrite As New System.Text.StringBuilder
With textToWrite
.Append("#echo off")
.AppendFormat("netsh interface ip set address name={0}Local Area Connection{0} static {1} {2} {3} 1", Chr(34), TB_EthIPAddress.Text, TB_EthSubnetMask.Text, TB_EthDefaultGateway.Text)
.AppendFormat("netsh interface ip set dns {0}Local Area Connection{0} static {1}", Chr(34), TB_EthDNS1.Text)
.AppendFormat("ipconfig /all > {0}{1}{2}{0}", Chr(34), AppsDir, TB_EthDNS1.Text)
.AppendFormat("echo hi > {0}{1}{2}{0}", Chr(34), AppsDir, CheckLen.Text)
End With
objwriter.WriteLine(textToWrite.ToString)
objwriter.Close()

problems with VBA code application or object error

I have coded some code in VBA my code breaks at this line raising Application defined or object defined error.
.Formula = "=IF(AND(chr(34) & ' & chr(34) & Criterion " & i & "'!" & cellAdress & ">=1;chr(34) & ' & chr(34) & Criterion " & i & "'!" & cellAdress & "<=4);chr(34) & ' & chr(34) & Criterion " & i & "'!" & cellAdress & ";0)"
I really tried to check what is wrong but it looks fine too me. Please let me know what could be wrong and how to fix it.
Thank you
I think you want
.Formula = "=IF(AND('Criterion " & i & "'!" & cellAdress & ">=1;'Criterion " & i & "'!" & cellAdress & "<=4);'Criterion " & i & "'!" & cellAdress & ";0)"
At least this produces a valid and sensible cell formula, your's does not.
With cellAdress set to "A1" and i set to 10, the result would be:
"=IF(AND('Criterion 10'!A1>=1;'Criterion 10'!A1<=4);'Criterion 10'!A1;0)"
Ok I understand it now. My VBA also doesn't raise any errors until I run. Maybe I'm looking on this code for too long and go crazy. My cell Address contains D18 and i contains 1. I do have a sheet called Criterion 1 and the cell in this sheet has a value of 2 (i also tried when it was empty). Still this error is raised and I don't know what is causing it.