It was just alternate solution but -
1) it was off the top of my head
2) as far as the rest of Mike said: he's probably right
I wasn't offended at all.
Announcement
Collapse
No announcement yet.
Open a URL in a web browser
Collapse
X
-
ShellExecute() is the Windows way. Shell(cmd) is the DOS way, where you let the command interpreter do the work, incurring more overhead and less control. It's also possible to use Shell(cmd) to delete and move files, or get a directory listing, but hardly anybody does because it is archaic, and there are better alternatives. What if M$ decide in their wisdom to remove or restrict the command interpreter [COMSPEC] in the future (a likely outcome)? Then any program calling it will be stuffed.
The API functions are available and at your disposal. Use them
Leave a comment:
-
I don't think I was being disrespectful, or at least that's certainly not what I intended. And there's nothing wrong with posting multiple solutions, just as there's nothing wrong pointing out that a particular solution has inherent problems or limitations. If the developer doesn't care about those particular issues with their implementation, that's fine, they have that choice.
I suppose that one could take umbrage at me commenting that showing a command prompt window is "ugly", but that's just my personal opinion, it wasn't meant to slight Shawn. I apologize if it was taken that way. Perhaps I also should have put a smiley face after my first sentence; in re-reading it, I could see how it could be taken as an accusation, when really I meant it as an "oops, you really didn't try that did ya?" kind of comment. I've done that plenty of times myself in the past.
Just as a personal observation, if anyone were to point out inefficiencies in code that I posted, I'd be happy for the criticism. I believe that having someone say "No, you really don't want to do it that way, this way is much better" is how we learn and perfect our craft as programmers. "Just getting the job done" shouldn't always be the final criteria with these sorts of things, from my perspective. It's important, of course, but so is elegance, efficiency and even cleverness in finding a solution to a problem (I'm saying that generally; I don't think that using ShellExecute is particularly clever). In any case, Brian has two solutions he can use, depending on whatever he prefers.
Leave a comment:
-
And while it's a single line of code, there's two reasons you don't want to do that....
Ok, if the code snippet "doesn't work as advertised", I can see posting a comment/correction to make it work. But let's remember that outside of the café, all posts here are freely offered in an attempt to be helpful. Lets show some respect and appreciation for those that take the time to help, ok?
Leave a comment:
-
Shawn, did you actually try that or just typing off the top of your head? It doesn't work, because "start" is a built-in shell command, not an executable command (this is mentioned in the help). So the code would have to be something like:
Code:SHELL ENVIRON$("COMSPEC") + " /C start http://www.catalyst.com"
EDIT: Just as a side note, over the years I've learned a basic lesson: never post code snippets unless you've actually run them through the compiler (or interpreter, as the case may be, depending on the language). I've been bitten enough by typos and simple mistakes in the past that I always do that, just to make sure that what I've posted is correct. Posting bad code, even when the idea is generally okay, just confuses new programmers because they often think that they're doing something wrong. Just my two cents there.Last edited by Mike Stefanik; 9 Mar 2008, 12:53 PM.
Leave a comment:
-
You can use the ShellExecute function:
Code:#COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" FUNCTION ShowURL(BYVAL strURL AS STRING) AS INTEGER LOCAL pszURL AS ASCIIZ PTR LOCAL nResult AS LONG pszURL = STRPTR(strURL) nResult = ShellExecute(%NULL, "open", @pszURL, "", "", %SW_SHOWDEFAULT) IF nResult > 32 THEN FUNCTION = %TRUE ELSE FUNCTION = %FALSE END IF END FUNCTION FUNCTION PBMAIN () AS LONG IF ShowURL("http://www.catalyst.com") = %FALSE THEN MSGBOX "Unable to open the default web browser", %MB_ICONERROR, "Error" END IF END FUNCTION
Leave a comment:
-
Open a URL in a web browser
Hi,
I want to load a URL in a web browser from my program
Is this possible in PowerBASIC?
Other programming languages I have used had a ShowURL command or functionTags: None
Leave a comment: