PDA

View Full Version : VBasic help



Peegee
10-25-2004, 01:40 AM
I'm trying to use VBasic to make a simple gui for a command line program. The program takes a single parameter -- a filename (complete with directory and so forth). So the idea is eventually I'll run the command


Shell ("mplayer.exe """ + File + """")

Where File is the entire file path.

So I have my file window, my directory window, my drive window, a window showing the "File" variable. But a snag.

File = Directory + filename right? What happens when I encounter two distnction different directories:

C:\

and

C:\Dir1

?

I can't put Directory + "\" + filename because it would lead to C:\\filename, and I can't put Directory + filename because it would lead to c:\directoryfilename

I actually did this, but I was fiddling with the code and somehow undid my work. My original solution didn't need if's, so I think a very simple solution isn't presenting itself to me :p

Edit: oh, on a completely unrelated note, what is the difference in meaning if you swap the terms in "x no y" in japanese? For example what does "kawaii no chibi" mean as opposed to "chibi no kawaii"?

Samuraid
10-25-2004, 02:05 AM
Use right() to check to see if the rightmost char of the directory path is a "\". If there is no backslash, then append one and then add + File on the end, and there you have it.

crono_logical
10-25-2004, 03:44 AM
Doesn't the particular API you're using in VB provide something that will let you check if the given string is an existing path/file and if so, exactly which it is? Or you could use that strategy yourself to work it out from the string, although it will be slightly more complex and/or slower than just analysing the string and assuming that it exists on the file system.

Edit: neko no shippo - the cat's tail, or the tail of the cat. shippo no neko - the tail's cat, or the cat of the tail. Probably not the best example, but you can see the effect of reversing the words is like reversing the words around an of or 's in English :p

Dr Unne
10-25-2004, 05:28 AM
In Linux, /home/chester and /home//////chester are the same. Isn't it the same in Windoze?

The short answer of course is just use Perl, since parsing text is what Perl was designed for in the first place.

Peegee
10-25-2004, 06:08 AM
You guys are so silly xD

Samuraid, your advice helped to ensure the success of PG's 'first' application (as opposed to the stuff I did in class seven or eight years ago, which I don't count as applications, but more of an assignment). The thing was, when I used the right(string, stringlength as string) function, I didn't know what to do with the stringlength. So I just plugged 2 in there (c:\ = string of 0 1 2 chars I reasoned), and it didn't work. So I put a textbox to see what right (string, 2) was, and it was ":\" (!!)

So I just adjusted the if statement to look for ":\" and all was super! Yay

Dr Unne
10-25-2004, 03:30 PM
This is an example of something which someone else somewhere in the world already wrote, tested, debugged, and left lying around on the internet. Re-using other people's source code is a good thing, in almost every case. So long as the source code is good quality.

"Reinventing the wheel", you've probably heard that term before; a lot of programmers reinvent the wheel on a nearly hourly basis. Your code only handles one specific kind of path, which is an artificial and fairly severe limitation. If you found a standard library for parsing filenames, you could handle any sort of path you want. Perl, for example, has File::Basename, which can handle filenames from Unix, Windows, AIX, VMS, and AmigaOS.

Another good thing about code reuse is that you don't have to care about that code. If there's a bug in the filename parsing code, it's not your problem. You're doing fileparse($my_filename), and that's it. You update your File::Basename module (or whatever) and your one line of code still works without having to change anything at all.

Samuraid
10-25-2004, 10:40 PM
You guys are so silly xD

Samuraid, your advice helped to ensure the success of PG's 'first' application (as opposed to the stuff I did in class seven or eight years ago, which I don't count as applications, but more of an assignment). The thing was, when I used the right(string, stringlength as string) function, I didn't know what to do with the stringlength. So I just plugged 2 in there (c:\ = string of 0 1 2 chars I reasoned), and it didn't work. So I put a textbox to see what right (string, 2) was, and it was ":\" (!!)

So I just adjusted the if statement to look for ":\" and all was super! Yay

Cool. Actually I was suggesting:

If Right(pathstring, 1) <> "\" Then
pathstring = pathstring & "\"
End If

But it's good you got it figured out anyway.

Peegee
10-27-2004, 05:38 AM
This is an example of something which someone else somewhere in the world already wrote, tested, debugged, and left lying around on the internet. Re-using other people's source code is a good thing, in almost every case. So long as the source code is good quality.

"Reinventing the wheel", you've probably heard that term before; a lot of programmers reinvent the wheel on a nearly hourly basis. Your code only handles one specific kind of path, which is an artificial and fairly severe limitation. If you found a standard library for parsing filenames, you could handle any sort of path you want. Perl, for example, has File::Basename, which can handle filenames from Unix, Windows, AIX, VMS, and AmigaOS.

Another good thing about code reuse is that you don't have to care about that code. If there's a bug in the filename parsing code, it's not your problem. You're doing fileparse($my_filename), and that's it. You update your File::Basename module (or whatever) and your one line of code still works without having to change anything at all.

Agreed, but this isn't a case where I have the time to learn Perl. I just wanted a haphazardly created (quite literally...you should see the actual program) program. And you know what? You can drag and drop media files on the mplayer executable anyway, thus making my program completely pointless and excessive. :p

But I didn't know that to begin with, so etiher way even if I were to use Perl I would be making an excessive program :D


Cool. Actually I was suggesting:

If Right(pathstring, 1) <> "\" Then
pathstring = pathstring & "\"
End If

But it's good you got it figured out anyway.

See the thing was that I didn't know what the number parameter did. Now I do. :D