I'm looking for help to use multiple lines on a VBS input box.
I want it to look like this:
Please enter one of the listed letters!
a.
b.
c.
d.
I wasn't able to find any helpful information on how to do it. I've messed around a bit but nothing seems to work. I've seem some things about (Chr(13)) and stuff but have no idea how to use it in syntax.
result = InputBox("Please enter one of the listed letters!" & vbNewLine & "a." & vbNewline & "b." & vbNewLine & "c." & vbNewLine & "d.", "InputBoxTitle")
Related
I’ve been looking around for an auto-typer for some fun on Discord and I found a Virtual Basic code on Youtube that functions mostly to my needs but it has one problem. It’s supposed to type a phrase and then enter and then type and enter for a set amount of times but when I test it in notepad++ it does this:
test
testtest
testtesttest
testtesttesttest
And so on until it maxes out at 17. I’m not sure what could be wrong with it because I didn’t make it and I’m not very adept with coding at all. This is the code:
set shell = createobject(“wscript.shell”)
strtext = inputbox(“What would you like the message to be?”)
strtimes = inputbox(“How many times would you like to type it?”)
if not isnumeric(strtimes) then
lol=msgbox(“Please write a number next time”)
wscript.quit
end if
msgbox “After you click Ok the message will start in 2 seconds”
wscript.sleep(2000)
for i=1 to strtimes
shell.sendkeys (strtext & “”)
shell.sendkeys (“{Enter}”)
wscript.sleep(100)
next
I’ve tried adjusting spaces and such before and after parentheses but nothing seems to change the ‘pyramid’ outcome. Any suggestions on what I could try to change or if anyone actually sees what’s wrong would be much appreciated.
The Issue you are running into is with notepad++ specifically.
shell.sendkeys (“{Enter}”)
Is triggering the Word Auto Completion.
I ran this writing to standard Notepad without issue.
Edit:
This does work in Notepad++ if you do the Enter twice.
shell.sendkeys ("{Enter}")
shell.sendkeys ("{Enter}")
Or if you add a space after the string.
shell.sendkeys (strtext & " ")
Alright, so I have been trying to do this for a while, and I have come to the realization that this isn't really something that is often asked, and with vb6 getting phased out more and more, there seems to be less help than I would like regarding the language.
The title doesn't say it all actually, as I am looking to do something very specific. I need to execute a shell command (that I know how to do), however, after I execute it, I want to be able to save the return value of that command as a string. For example, if the command is ipconfig, I want the entire return value of that, all the text I would see in powershell after executing that command, saved to a string in my program.
As far as I know, I need to "import" a few things, because I have to use WshShell, which I don't know where to get. So that's part of the question, what classes do I have to add and how, or if there is a way to do it without adding classes then even better. In addition, I have heard a lot about the use of CreatePipe and such regarding similar problems, but I don't know how to use it.
Basically, what I'm saying is that I am quite uneducated regarding the subject, and any insight would be much appreciated, and thanks to all who reply.
There are many ways. Using VBScript's WSHShell.Exec is the easiest.
This is VBScript but VBScript can be pasted into VB (not vice versa though).
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("ipconfig")
Do While oExec.Status = 0
WScript.Sleep 100
Loop
MsgBox oExec.StdOut.ReadAll
Slightly modified from help.
This is how to ping from VBS/VB
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From win32_PingStatus where address='104.43.195.251'")
'msgbox colItems
For Each objItem in colItems
msgbox "Status" & objItem.statuscode & " Time " & objItem.ResponseTime
Next
I am working on packaging a script for the company that I work for that will allow field service techs to convert computers in a private workstation OU to a team workstation OU and vice versa.
That is a small part of this script for now and one that has had me puzzled for most of the day. I've tried different variations of this script and landed on one that I believe will get me on the right track.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select Name from Win32_ComputerSystem",,48)
For Each objItem in colItems
strPCName = objItem.Name
Next
Set objNewOU = GetObject("LDAP://OU=Computers,OU=Corporate,DC=xxxxx,DC=net")
Set objMoveComputer = objNewOU.MoveHere("LDAP://CN=" & strPCName & ",OU=Computers,OU=Corporate,DC=xxxxx,DC=net",vbnullstring)
I get an error, There is no such object on the server. When I put the computer manually in the OU in question, I don't get that error message. This is where I'm stuck at the moment.
The scripting is in my personal lab at the moment.
I was able to get a solution that did work, by using the following script.
Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName
Set objNewOU = GetObject("LDAP://OU=Private Workstations,OU=xxxx,OU=xxxx,DC=xxxx,DC=xxxx")
Set objMoveComputer = objNewOU.MoveHere _ ("LDAP://" & strComputerDN, vbNullString)
Judging by the script's behavior, it uses strComputerDN to determine where the computer is, and the objNewOU determines where the computer is going. The objmoveComputer consolidates this information as best as I can determine to move the computer to it's OU.
Is there way to find the PC user in visual basic (C:\User\"here").
After we get it, just save it as a string.
I know the answer might be a bit obvious, but I cannot find out how to do this
Fairly simple, from here ( http://blogs.msdn.com/b/alejacma/archive/2008/03/11/how-to-get-the-user-running-a-vbscript.aspx )
Dim networkInfo
Set networkInfo = CreateObject("WScript.NetWork")
Dim infoStr
infoStr = "User name is " & networkInfo.UserName & vbCRLF & _
"Computer name is " & networkInfo.ComputerName & vbCRLF & _
"Domain Name is " & networkInfo.UserDomain
MsgBox infoStr
The simplest way might be to query the environment.
There are USERDOMAIN, USERNAME, USERPROFILE and COMPUTERNAME environment variables containing the obvious values.
Querying those would depend solely on WScript.Shell instead of on WScript.Network as in the accepted (and correct) answer. If you already have a reference to the shell, this might be a slightly more comfortable way.
Sub GetALLEmailAddresses()
Dim objFolder As Folders
Set objFolder = Application.ActiveExplorer.Selection
Dim dic As New Dictionary
Dim strEmail As String
Dim strEmails As String
Dim objItem As MailItem
For Each objItem In objFolder.Items
strEmail = objItem.SenderEmailAddress
If Not dic.Exists(strEmail) Then
strEmails = strEmails + strEmail + ";"
dic.Add strEmail, ""
End If
Next
Debug.Print strEmails
End Sub
I use this code to get email address from message body. I'm not prefect in vb. is there any to help how to get email address from messages in outlook 2003?
In that case, I don't think there's anything built in, so I'd suggest that you don't bother with the SenderEmailAddress but instead just get out the Body and then search the text for email addresses. This will get somewhat complicated though since it might be difficult to be able to tell what's part of an email address and what isn't.
The easiest place to start with is to just look for any # in the text, and then search for the next whitespace on either side of the # and get everything between those whitespaces. But there are a lot of issues to think about. What if the user typed # for some other reason, or if the email contains something like The first email is xxx#test.com.The second email is xxx2#test.com (note the missing space between the . and the The), where your app might think that the email should be xxx#test.com.The.
Edited since my answer was based on a complete misunderstanding of the question.