I'm a newbie writing my first app. I need help with the following: I need to retrieve the logged in user which = GID, I then need to append it to a URL which will start our Help Desk chat client. I can retrieve the GID easy enough but can't figure out how to append it and pass it with the URL. I found a post which instructed to declare the url as a string also and concatenate it. The UserName would follow the ":" at the end of the Url.
Private Sub GID()
Dim GID As String
GID = System.Environment.UserName
' System.Diagnostics.Process.Start("http://www.myurl.com/eschat/arhome.html?login=m:uid~uid:")
We use javascript to do this from the HelpDesk site, but I need to adapt it to work from my app. Any help would be appreciated and I hope my question makes sense.
You can concatenate strings in VB.NET using '&' like this:
Dim GID as String
GID = System.Environment.UserName
Dim URL as String
URL = "http://www.myurl.com/eschat/arhome.html?login=m:uid~uid:"
System.Diagnostics.Process.Start(URL & GID)
You can also insert the variable into the string like this
URL = String.Format("http://www.myurl.com/eschat/arhome.html?login=m:uid~uid:{0}", GID)
and the GID will be placed wherever the "{0}" is, this can also be used for multiple parameters, you just increment the number inside the curly braces e.g. "{1}", "{2}".
MSDN article here.
Related
I'm sure if I knew the correct terminology I may have been able to search an answer... But my Visual Studio VB skills are somewhat n00bish.
My VB runs a dos batch, that dumps the DOMAIN\USERNAME of the current logged on user for a given IP address to a text file (GETUSER.txt)
What I need to do with this string (taken from the txt file created above), is create two strings, one that is the DOMAIN, one that is the USERNAME and to drop the \ entirely.
The problem is that my work environment consists of multiple domains, and varying username styles. The only constant is the \ separating the DOMAIN and USERNAME.
I've looked at the REPLACE and various STRING functions, but I'm struggling folks.
The below is the section of VB code that runs when you click OK on the dialogue box (after entering an IP). "MAIN" is the name of the parent window that has the Public VARs in it.
Public Shared IPADDRESS As String
Public Shared USERNAME As String
^ are the Public VARS used.
Dim GETUSER As New ProcessStartInfo("TOOLS\GETUSER.bat")
Dim fileReader As System.IO.StreamReader
Dim stringReader As String
MAIN.IPADDRESS = NEW_IP_ADD.Text
MAIN.IP_DISPLAY.Text = MAIN.IPADDRESS
GETUSER.WindowStyle = ProcessWindowStyle.Hidden
GETUSER.Arguments = MAIN.IPADDRESS
Process.Start(GETUSER)
fileReader =
My.Computer.FileSystem.OpenTextFileReader("TOOLS\GETUSER.txt")
stringReader = fileReader.ReadLine()
MAIN.USERNAME = stringReader
MAIN.USER_NAME.Text = MAIN.USERNAME
I hope this makes sense, and isn't too impossible to decipher... I look forward to your responses....
Please remember, I'm VERY new at VB, and Visual Studio... also... I'm more than happy if people post links to places that know I can get my answer, or help me with function names or anything designed to help me find the answer myself... it's the only way to learn... I just think I need a nudge in the right direction...
Cheers,
Tim.
It sounds like what you want to do is to split the string. And handily, there's a Split method:
Returns a string array that contains the substrings...
So you'd do something like:
Dim parts = MAIN.USERNAME.Split("\"C)
Dim domain = parts(0)
Dim userNameWithoutDOmain = parts(1)
I'm fairly new to programming in general. I'm working on a simple app that could combine a couple of functions to automate or simplify some of the things I do at work. One of the functions I'm trying to build is to be able to create a folder. Now I have found an article on that on Microsoft's msdn resource and it's child's play. But the instructions there only show how to create a folder with a predefined name in the code. What I'd rather want is to have a textbox where I input the folder's name and the directory is named with that input. The msdn code looks like this:
My.Computer.FileSystem.CreateDirectory _
("C:\vb\")
I understand I should now add:
Dim txt As String
txt = TextBox1.Text
But what next? How do I tell VB to use as directory name the input "txt"?
Try this:
Dim txt As String
txt = TextBox1.Text
My.Computer.FileSystem.CreateDirectory("C:\" & txt & "\")
Using & is simple and often fine for most purposes, but for your two (including what you've added as a comment) concatenation examples there are other methods:
For pathname manipulation look at System.IO.Path:
My.Computer.FileSystem.CreateDirectory(Path.Combine("C:\", txt))
For (complex) string "formatting", consider String.Format:
Dim menu As String = String.Format("Today's main dish is {0}.", TextBox2.Text)
I can retrieve the contents of a webpage into a variable like:
x = objIE.Document.body.outerHTML
But during development (data parse), I don’t want to keep pulling up a live site and instead just want to store some sample html in a format that can be placed in a variable. The issue is that trying to directly place a raw html sample into a variable creates errors and would require going through and escaping quotes etc. What’s an easy way to put place a large block of sample html in a variable?
You could read the html into a string variable using IO.StreamReader
Dim docStuff As String
Dim strReader As IO.StreamReader
Dim strWriter As IO.StreamWriter
strReader = New IO.StreamReader(Application.StartupPath & "/me.html")
docStuff = strReader.ReadToEnd
strReader.Close()
then write it back out using IO.StreamWriter
strWriter = New IO.StreamWriter(Application.StartupPath & "/changedCode.html")
strWriter.Write(docStuff)
strWriter.Close()
I have never had issues with this method with escape characters, etc. I pull it in, then I can look at the code, make changes, etc. Works like a charm.
I have a parameter query that looks up the tracking # for a given customer_order_ID and outputs the tracking# as a website link, as a single record. Please advise me how I can have the link run automatically when the user inputs the customer_order_ID into the parameter query , in order that the user can immediately track the package on the UPS Worldship website. I do not know VBA nor do I know SQL, but I can make macros.
Thank you very much in advance
SELECT T.order_ID, "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_us&InquiryNumber1=" & [T].[tracking_number] & "&track.x=0&track.y=0" AS link
FROM tblShipmentDataFromAllCarriers AS T
WHERE (((T.order_ID)=[Please enter customer order ID]));
If you don't need to parse the return data and just want to open the web page, you can use Application.FollowHyperlink. But you don't need to do the concatenation with the URL in the SQL:
SELECT T.order_ID, [T].[tracking_number]
FROM tblShipmentDataFromAllCarriers AS T
WHERE (((T.order_ID)=[Please enter customer order ID]));
Then you could store the rest of the URL as constants:
Const c_strURL1 = "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_us&InquiryNumber1="
Const c_strURL2 = "&track.x=0&track.y=0"
...and then execute it like this:
Public Sub DisplayTrackingNumber(ByVal strOrderID As String)
Dim strTrackingNumber As String
strTrackingNumber = DLookup("tracking_number", "tblShipmentDataFromAllCarriers", "[order_ID]=" & strOrderID)
Application.FollowHyperlink strUrl1 & strTrackingNumber & strUrl2
End Sub
You'd then have to have a UI to collect the OrderID from the user (I'd suggest a form with a combo box) and then call this sub.
Im writing a program in VB.net that consists of three main steps:
STEP 1: Display the source code of a webpage that is streaming a movie on it in textbox1.
STEP 2: highlight the URL to that movie in the source code, and then display just the URL in textbox3.
STEP 3: Download that movie using HttpWebRequest and HttpWebResponse to a user defined directory
The problem is that i dont know how i would go about extracting the URL from the source code effectively. maybe i could try searching the source code for the string ".mp4" or ".avi" or other video extensions, but that would only find the end of the link, how would i highlight the whole link?
For example: if i searched the source code for ".mp4" and there was a URL such as
"http://megavideo.com/g7987bfd0fg.mp4"
then i would only get
"http://megavideo.com/g7987bfd0fg
.mp4"
i know there is some way to start at a certain character in a document and go forward or backward a few characters, but the problem arises when you dont know how many characters to go back due to varying lengths of URLs... is there some way that you could search for http:// and then search for .mp4 and then highlight everything in between them?
#EDIT# I also need to be able to feed this URL into another process that will download the file using "httpwebrequest" and "httpwebresponse" so it would be ideal if i could do something like:
textbox3.text = extracted link
Thanks in advance!
Your best bet is Regular Expressions. Get the app called RegexBuddy. It will help you write the regular expression for your needs
Try this code
Dim input As String= "Your initial page source that you want to search through"
Dim pattern As String = "http\:\/\/[.]*\.mp4"
Dim rgx As New Regex(pattern, RegexOptions.IgnoreCase)
Dim matches As MatchCollection = rgx.Matches(input)
If matches.Count > 0 Then
For Each match As Match In matches
DownloadVideo(match.Value)
Next
End If
What I would do is do a regular expression match to find the string I was looking for.
here's an example for begins with Regex pattern for checking if a string starts with a certain substring?