|
-
Jan 22nd, 2008, 03:45 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] "myapp://"
Im writing a networked application and want to add some customize by adding a handler like myapp:// (http://, ftp://)
And be able to pass the arguments to my app like: myapp://IP:Port/Username&Password
I bet I could find some tutorial about it on the internet, but I really don't know what the name of it would be.
-
Jan 22nd, 2008, 06:27 PM
#2
Re: [2005] "myapp://"
Are you talking about passing arguments to your app on the command line, when you actually start it?
-
Jan 22nd, 2008, 06:45 PM
#3
Lively Member
Re: [2005] "myapp://"
im not sure 100% what you want but
vb.net Code:
Public Function App_Path() As String
Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function
would return the path of the application
-
Jan 22nd, 2008, 06:47 PM
#4
Thread Starter
Hyperactive Member
Re: [2005] "myapp://"
Kinda
Programs like Steam (Valve Software), Teamspeak, most games, etc allow you to pass arguments via your browser or Windows Explorer like:
myApp://Argument1:Argument2/Agrument3&Argument4
via the browser's address bar.
Another example:
Teamspeak, which is a network voice program lets you start the application and pass arguments like this:
teamspeak://127.0.0.1:8001/nickname=Test?loginname=Test1?password=Test2?channel=Test3?channelpassword=Test4
Basically its like http://, ftp://
-
Jan 22nd, 2008, 07:36 PM
#5
Lively Member
Re: [2005] "myapp://"
Hmmm, this is my solution.
Let's say it's a textbox and you click on a button to pass the command (or you can check the keycode in the KeyDown event for the [Enter] key if you want it to be more like a console app).
Let's say this is what a code could look like:
Code:
MyApp://127.0.0.1:8001/name=Test?password=Bob
I will split this into 3 sections with A = "MyApp", B = "127.0.0.1:8001", and C = "name=Test?password=Bob". Pretend that the maximum number of commands in part C is 5.
I added some sample code to demonstrate each step. You'll have to declare your own variables though.
1. Set a string variable to equal the entered text in the textbox. This will be called Cmd.
Cmd = TextBox1.Text
2. Set an integer variable to equal the index of "://" in Cmd. I'll call the variable i1.
i1 = Cmd.IndexOf("://")
3. Then set another string (called A) to equal the substring of Cmd with the starting character parameter as 0 and the length parameter equal to i1 (the fact that i1 is actually equal to the position of ":" cancels out the need to add 1 for zero-based indexing). A now equals "MyApp".
A = Cmd.Substring(0,i1)
4. Now use an If statement to make sure that A = "MyApp" (otherwise discontinue and report it as incorrect syntax).
If A = "MyApp" Then
'Do nothing, this is correct
Else
MsgBox("Incorrect Syntax!")
Return
End If
5. Now set Cmd to equal the substring of itself with the starting parameter as i1 + 3 (once again because i1 is the index of the colon in ://). Don't specify a length (automatically gets the whole length of the string).
Cmd = Cmd.Substring(i1+3)
6. Now set an integer called i2 to equal the index of "/" in Cmd.
i2 = Cmd.IndexOf("/")
7. Set a string called B to equal the substring of Cmd with starting parameter as 0 and the length parameter as i2. B now equals "127.0.0.1:8001".
B = Cmd.Substring(0,i2)
8. Set Cmd to equal the substring of itself with the starting parameter as i2 + 1 (because i2 is the index of the slash). Again, don't specify a length.
Cmd = Cmd.Substring(i2+1)
9. Set i3 to equal the index of "?" in command.
i3 = Cmd.IndexOf("?")
10. Check to make sure that i3 is not -1. (in case there is no question mark)
If i3 = -1 Then
username = Cmd
Return
End If
11. Set C equal to the substring of Cmd with the starting parameter as 0 and the length as i3. C is now equal to "name=Test"
C = Cmd.Substring(0,i3)
13. Make a counting variable to tell how many question marks are within the original command.
Dim count as Integer = 0
14. Now make a loop so that it keeps reading the text until there are no more question marks (followed by a command) to read.
vb Code:
Cmd = Cmd.Substring(i3 + 1) i3 = Cmd.IndexOf("?") While Not i3 = -1 Or count < 6 count = count + 1 C = Cmd.Substring(0,i3) 'Now make a case statement to check for which question mark this is '[Pseudocode] 'Case of count 'In the case: count = 2 'password = C 'In the case: count = 3 'servername = C 'In the case: count = 4 'serverip = C 'and so on... Cmd = Cmd.Substring(i3+1) i3 = Cmd.IndexOf("?") End While
15. Before all of this when you declare username, password, servername, serverip, etc, you should set default values for each of them in case they are not changed by this code.
I hope this helps,
~Divine
Last edited by Divine; Jan 22nd, 2008 at 07:42 PM.
"He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever."
-
Jan 22nd, 2008, 08:13 PM
#6
Thread Starter
Hyperactive Member
Re: [2005] "myapp://"
Okay, I found what it's called: UriParser
http://jasonkemp.ca/archive/2005/11/14/2758.aspx
Looks like Microsoft made it easy too
-
Jan 22nd, 2008, 08:21 PM
#7
Lively Member
Re: [2005] "myapp://"
 Originally Posted by tylerm
Well yeah, there are tons ActiveX controls for VB/VB.Net ranging from fixing vertical tabs to new color dialogs. Lots of the good ones aren't free though and can be as much as several hundreds of dollars.
I just wanted to show you the code . I think external add-ons can sometimes ruin the fun of programming. That's actually the reason I like programming so much: Coming by a hard challenge, devising an algorithm, optimizing it, then running what I wrote and enjoying it. If I use something I didn't write myself...well, it just doesn't give me the same feeling.
"He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|