How can this MicroSoft Example to get short file names be made to

M

Mike1942

This is an example that is supposed to work in VB
http://support.microsoft.com/kb/175512/en-us
After spending a couple of hours downloading and installing VB Express 2008
after someone told me it was easy, the thing doesn't work any better.
These two instruction lines are not functional
3. Place a Common Dialog control on the form.
4. From the Insert menu, select Module to add a single code module to the
project.
There is no Common Dialog (or CommonDialog) control in the toolbox to put
on the form. There is no Insert menu, although Add Module appears on the
Project menu item.
I don't need this code to work and for VB to work (I hate the excessive
and inconvenient complexity and bad organization of VB) I just want a small
program that will work directly under windows, browse a file list and give
the exact, correct short (8.3 form) file name for that file.
 
S

Scott M.

Apparently, you didn't see the "Applies to" section of that article, which
clearly indicates that the article isn't related to any .NET version of
Visual Studio.

APPLIES TO
. Microsoft Visual Basic 5.0 Control Creation Edition
. Microsoft Visual Basic 5.0 Learning Edition
. Microsoft Visual Basic 5.0 Professional Edition
. Microsoft Visual Basic 5.0 Enterprise Edition
. Microsoft Visual Basic 4.0 Standard Edition
. Microsoft Visual Basic 4.0 Professional Edition
. Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
. Microsoft Visual Basic 6.0 Learning Edition
. Microsoft Visual Basic 6.0 Professional Edition
. Microsoft Visual Basic 6.0 Enterprise Edition
 
K

Ken Halter

Mike1942 said:
I don't need this code to work and for VB to work (I hate the excessive
and inconvenient complexity and bad organization of VB)

Actually, you're just a few years late. The code in that article is intended
to run in VB4 thru VB6. That's when the "product" became "something else"
and lost a lot of its RAD capabilities... not to mention losing its ability
to compile Win32 code and over 1/2 of its "VBcentric" debugging
capabilities..

I agree with your "inconvenient complexity and bad organization" statement.
Just more proof that "new" doesn't always mean "better"... just get used to
waiting long periods of time to start the IDE and any apps you create. They
start up faster once the flamework's in ram, but until then, it's a pig.

If you write programs for a hobby or just want to get some work done without
dealing with tons of extra *junk* that's good only for web apps (the .Net in
the products name is a dead give-a-way), try and find a copy of VB6 on the
web somewhere. It'll save you hours of development time and the apps will be
every bit as reliable as anything you create in dotNet... plus, they'll load
and run faster... especially if you don't have a 10ghz PC and 20gb of
ram.... it won't be free, though... MS didn't have to give that away free to
get people to use it, like they do with dotNet.

What ever the cost, it'll pay for itself quickly and save you a lot of
frustration.

If/when you find VB6, head over to the microsoft.public.vb groups for
help... and here's nearly 5,000,000 lines of code that's ready to "plug and
play" (and this is just one site!)

Code: 4,983,574. lines
http://www.planetsourcecode.com/vb/default.asp?lngWId=1

They /do/ have .Net code, with C#, B# and the rest all laid out in a pile,
but only 1/10th the samples they do with VB6... and who knows if any of it
works or not.

Code: 587,016. lines
http://www.planetsourcecode.com/vb/default.asp?lngWId=10
 
C

Cor Ligthert[MVP]

Mike,

It seems that people want to show you that the actual VB versions are
difficult. It is not. I have written the same with slightly changed code
based on VB 2008 from Tom, in the way as 99% does this. It seems that some
like Tom do this completely by hand, however be aware this is basicly the
code from Tom (I don't know as much about API's as him).

To do,

Open a new WindowsForm application
Drag from the toolbox a Button on the form
Drag an OpenFileDialog control on the form (it will show up at the bottom
of the surface).

Click on the button, the code will appear, fill in what is not yet in that
code

\\\
Public Class Form1
Private Declare Auto Function GetShortPathName Lib "kernel32" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As System.Text.StringBuilder, _
ByVal cchBuffer As Integer) As Integer


Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim longPath = OpenFileDialog1.FileName
Dim requiredSize = GetShortPathName(longPath, Nothing, 0)
Dim buffer As New System.Text.StringBuilder(requiredSize)
Dim result = GetShortPathName(longPath, buffer, buffer.Capacity)
Clipboard.SetData(DataFormats.Text, buffer.ToString)
End If
End Sub
End Class

///

You are ready, as you can see very much easier than the vintage VB sample
you was looking at before, while here is even checked if the OK button is
clicked in the OpenFileDialog.

Cor
 
K

kimiraikkonen

Mike,

It seems that people want to show you that the actual VB versions are
difficult. It is not. I have written the same with slightly changed code
based on VB 2008 from Tom, in the way as 99% does this. It seems that some
like Tom do this completely by hand, however be aware this is basicly the
code from Tom (I don't know as much about API's as him).

To do,

Open a new WindowsForm application
Drag from the toolbox a Button on the form
Drag  an OpenFileDialog control on the form (it will show up at the bottom
of the surface).

Click on the button, the code will appear, fill in what is not yet in that
code

\\\
Public Class Form1
    Private Declare Auto Function GetShortPathName Lib "kernel32" ( _
     ByVal lpszLongPath As String, _
     ByVal lpszShortPath As System.Text.StringBuilder, _
     ByVal cchBuffer As Integer) As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim longPath = OpenFileDialog1.FileName
            Dim requiredSize = GetShortPathName(longPath, Nothing, 0)
            Dim buffer As New System.Text.StringBuilder(requiredSize)
            Dim result = GetShortPathName(longPath, buffer,buffer.Capacity)
            Clipboard.SetData(DataFormats.Text, buffer.ToString)
        End If
    End Sub
End Class

///

You are ready, as you can see very much easier than the vintage VB sample
you was looking at before, while here is even checked if the OK button is
clicked in the OpenFileDialog.

Cor


It would be better to revise your code by declaring "requiredSize"
variable as Integer, because StringBuilder's contructor expects an
Integer, not to get an "Overload resolution failed because no
accessible 'New' can be called without a narrowing conversion" as
follows:

'-------------------------
Public Class Form1
Private Declare Auto Function GetShortPathName Lib "kernel32" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As System.Text.StringBuilder, _
ByVal cchBuffer As Integer) As Integer

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

Dim longPath = OpenFileDialog1.FileName
Dim requiredSize As Integer = GetShortPathName(longPath, Nothing, 0)
Dim buffer As New System.Text.StringBuilder(requiredSize)
Dim result = GetShortPathName(longPath, buffer, buffer.Capacity)
Clipboard.SetData(DataFormats.Text, buffer.ToString)

End If

End Sub

End Class
'---------------------------

Onur Güzel
 
C

Cor Ligthert [MVP]

Onur,

May I ask you what is your intention to add messages direct to mine, this is
simple code made by Tom, as is wrote in the message, however I tried to show
it in a more for the user applicable way to prevent that he would be afraid
from a message in this message thread.

So as you have comments, please point it to Toms message. As I wrote
already, he knows much more about API's than me.

By the way, I tried this code with VS 2008, as the OP is using, did you do
the same?

Cor

"kimiraikkonen" <[email protected]> schreef in bericht
Mike,

It seems that people want to show you that the actual VB versions are
difficult. It is not. I have written the same with slightly changed code
based on VB 2008 from Tom, in the way as 99% does this. It seems that some
like Tom do this completely by hand, however be aware this is basicly the
code from Tom (I don't know as much about API's as him).

To do,

Open a new WindowsForm application
Drag from the toolbox a Button on the form
Drag an OpenFileDialog control on the form (it will show up at the bottom
of the surface).

Click on the button, the code will appear, fill in what is not yet in that
code

\\\
Public Class Form1
Private Declare Auto Function GetShortPathName Lib "kernel32" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As System.Text.StringBuilder, _
ByVal cchBuffer As Integer) As Integer

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim longPath = OpenFileDialog1.FileName
Dim requiredSize = GetShortPathName(longPath, Nothing, 0)
Dim buffer As New System.Text.StringBuilder(requiredSize)
Dim result = GetShortPathName(longPath, buffer, buffer.Capacity)
Clipboard.SetData(DataFormats.Text, buffer.ToString)
End If
End Sub
End Class

///

You are ready, as you can see very much easier than the vintage VB sample
you was looking at before, while here is even checked if the OK button is
clicked in the OpenFileDialog.

Cor


It would be better to revise your code by declaring "requiredSize"
variable as Integer, because StringBuilder's contructor expects an
Integer, not to get an "Overload resolution failed because no
accessible 'New' can be called without a narrowing conversion" as
follows:

'-------------------------
Public Class Form1
Private Declare Auto Function GetShortPathName Lib "kernel32" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As System.Text.StringBuilder, _
ByVal cchBuffer As Integer) As Integer

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

Dim longPath = OpenFileDialog1.FileName
Dim requiredSize As Integer = GetShortPathName(longPath, Nothing, 0)
Dim buffer As New System.Text.StringBuilder(requiredSize)
Dim result = GetShortPathName(longPath, buffer, buffer.Capacity)
Clipboard.SetData(DataFormats.Text, buffer.ToString)

End If

End Sub

End Class
'---------------------------

Onur Güzel
 
K

kimiraikkonen

Onur,

May I ask you what is your intention to add messages direct to mine, thisis
simple code made by Tom, as is wrote in the message, however I tried to show
it in a more for the user applicable way to prevent that he would be afraid
from a message in this message thread.

So as you have comments, please point it to Toms message. As I wrote
already, he knows much more about API's than me.

By the way, I tried this code with VS 2008, as the OP is using, did you do
the same?

Cor

"kimiraikkonen" <[email protected]> schreef in bericht







It would be better to revise your code by declaring "requiredSize"
variable as Integer, because StringBuilder's contructor expects an
Integer, not to get an "Overload resolution failed because no
accessible 'New' can be called without a narrowing conversion" as
follows:

'-------------------------
Public Class Form1
Private Declare Auto Function GetShortPathName Lib "kernel32" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As System.Text.StringBuilder, _
ByVal cchBuffer As Integer) As Integer

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

Dim longPath = OpenFileDialog1.FileName
Dim requiredSize As Integer = GetShortPathName(longPath, Nothing, 0)
Dim buffer As New System.Text.StringBuilder(requiredSize)
Dim result  = GetShortPathName(longPath, buffer, buffer.Capacity)
Clipboard.SetData(DataFormats.Text, buffer.ToString)

End If

End Sub

End Class
'---------------------------

Onur Güzel

Cor,
There is no any kind of intention regarding to a person. And the
important thing is that the code above which wasn't working as i tried
on VB 2005 with .NET 2.0, and declaring "requiredSize" variable As
Integer solved the problem. That's why i needed to inform to provide a
little help if anyone else experiences that error:

"Overload resolution failed because no accessible 'New' can be called
without a narrowing conversion:
'Public Sub New(value As String)': Argument matching parameter 'value'
narrows from 'Object' to 'String'.
'Public Sub New(capacity As Integer)': Argument matching parameter
'capacity' narrows from 'Object' to 'Integer'."

You can try the previous version or the one that you posted to
reproduce error which i meant above.

BTW, thanks Tom posting that snippet.

Onur Güzel
 
C

Cor Ligthert [MVP]

The code should give an error in version 2005

Reread my first sententence of the first messages. I did not write that for
fun.

As you want to try that part, it is just copied from Tom's code so you
copied the code from that.

(In fact was the main change to remove the "as" clauses, as far as I
remember me Tom and I have an other opinion about that, I wrote that I
changed his code).

Cor


"kimiraikkonen" <[email protected]> schreef in bericht
Onur,

May I ask you what is your intention to add messages direct to mine, this
is
simple code made by Tom, as is wrote in the message, however I tried to
show
it in a more for the user applicable way to prevent that he would be
afraid
from a message in this message thread.

So as you have comments, please point it to Toms message. As I wrote
already, he knows much more about API's than me.

By the way, I tried this code with VS 2008, as the OP is using, did you do
the same?

Cor

"kimiraikkonen" <[email protected]> schreef in
bericht







It would be better to revise your code by declaring "requiredSize"
variable as Integer, because StringBuilder's contructor expects an
Integer, not to get an "Overload resolution failed because no
accessible 'New' can be called without a narrowing conversion" as
follows:

'-------------------------
Public Class Form1
Private Declare Auto Function GetShortPathName Lib "kernel32" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As System.Text.StringBuilder, _
ByVal cchBuffer As Integer) As Integer

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

Dim longPath = OpenFileDialog1.FileName
Dim requiredSize As Integer = GetShortPathName(longPath, Nothing, 0)
Dim buffer As New System.Text.StringBuilder(requiredSize)
Dim result = GetShortPathName(longPath, buffer, buffer.Capacity)
Clipboard.SetData(DataFormats.Text, buffer.ToString)

End If

End Sub

End Class
'---------------------------

Onur Güzel

Cor,
There is no any kind of intention regarding to a person. And the
important thing is that the code above which wasn't working as i tried
on VB 2005 with .NET 2.0, and declaring "requiredSize" variable As
Integer solved the problem. That's why i needed to inform to provide a
little help if anyone else experiences that error:

"Overload resolution failed because no accessible 'New' can be called
without a narrowing conversion:
'Public Sub New(value As String)': Argument matching parameter 'value'
narrows from 'Object' to 'String'.
'Public Sub New(capacity As Integer)': Argument matching parameter
'capacity' narrows from 'Object' to 'Integer'."

You can try the previous version or the one that you posted to
reproduce error which i meant above.

BTW, thanks Tom posting that snippet.

Onur Güzel
 
S

Scott M.

Wow! I'm not even going to begin to pick over what's wrong with this
post - - I don't have that kind of time.
 
C

Cor Ligthert[MVP]

Tom,

I thought so but had to write something. I hope you have no problem that I
tried to make your code more like the code in the sample?

:)

Cor
 
K

Ken Halter

Scott M. said:
Wow! I'm not even going to begin to pick over what's wrong with this
post - - I don't have that kind of time.

Yep... I agree... it would take days to find something wrong with that post.
 
K

Ken Halter

Scott M. said:
That's what I'd expect someone with your level of understanding of .NET to
say.

Well... correct it, then.... you know the saying... put up, or shut up.
 
K

Ken Halter

Scott M. said:
That's what I'd expect someone with your level of understanding of .NET to
say.

adding to that, how can you *possibly* know what my level of understanding
is? Just pick a topic, *any* topic and try to guess what my level of
understanding is (boy... I have to wonder sometimes, just who some of you
think you are)...and, just what *is* your level of understanding?

I can certainly see the questions asked here are just about the exact same
questions people were asking 10+ years ago. The difference is, it's rare to
find an unanswered question in the VB6 groups... Here, they're everywhere.
Which is no surprise, since your star trolls are hanging around the VB6
groups, leaving their dirty toilet paper where ever they can.

It might be beneficial to new users if MS would A) update their sample code,
B) release sample code for their new "products" as they're released and C)
stop adding bloat before fixing existing problems. (plenty more where those
came from)

But, like you say... I don't have the time.... I've said it before and I'll
say it again... B#'s top competitor is this "ancient toy language" that was
released in 1998. That says *volumes* about this "super duper VB". dotNet's
been available for what... nearly 9 years now? LOL
 
K

Ken Halter

Tom Shelton said:
Well, I think the assumptions come from some of the statements you make.
Some
of them, are grounded in reality - but, are major exagerations. I think
that
leads some to believe that maybe you do not know what you're talking
about -
especially those of us who have written large applications in a managed
language.

LOL... I notice there's no mention of VB.Net in that statement said:
Would you expect any different? There are people on different levels of
the
skill spectrum in .NET, just as there are in VB6. The reason you may not
be
seeing these questions in the classic groups is that most newbies are not
starting with VB6. So, by default you are left with most of the
old-timers
who have advanced beyond the newbie type questions.

Just think how many people would benefit from having a version of VB that
didn't break 50 million+ lines of code or make a few hundred thousand
newsgroup posts suddenly "obsolete"... btw, when it comes to VB6 being
obsolete, it's truly up to the development community to make that decision.
Not marketting geeks who are trying to keep their jobs.... but, if dotNet
was "all that", why isn't Office and the rest written in dotNet? or the OS
itself!

Every commercial app we've upgraded here who's authors switched to a dotNet
based environment, blow chunks to the point where we're buying downgrade
licenses. People want to get their work done... not deal with the exact same
bugs they dealt with 10 years ago... and we upgrade our PCs to gain more
speed, not so we can run bloated apps.
I think a major contributor to the problem over there is the extreme
anti-.net
anything attitude taken by some of the classic contributors. For
instance, I
don't see the problem in answering a .net question if the answer is
relatively short and then providing a redirect to the proper forums for
future
reference. Where is the harm? Yet, many act as if it is the end of the
world

The trolls cause the harm. The threads would end after the 2nd/3rd post, if
it weren't for the "Guardians.Net"
- or even reply to innocent queries with long diatribes on the dishonesty
and
immorality of MS (a subject I don't wholy disagree with, btw).

Well, I haven't been adding to those diatribes and I've done a fair share of
"gently prodding" people over here, but when some "legend in his own
mind.Net" keeps putting everyone down in some attempt to make himself feel
superior, I do add comments... When he tells someone they're worthless
because they took time off and persued another career (most likely, out of
curiousity), I take it personally, even if it's not directed at me.

Newsgroups, like it or not, are communities. Like all communities, there are
trouble makers. Since MS seems completely unable to do anything about it,
it's up to the community to make it uncomfortable for that trouble maker.

Bottom line is, he has no business there and knows it. The fact he's an
MS-MVP reflects badly on the entire program and is one (of many) reasons I
"resigned" last May, instead of waiting for the annual October review.

I'm sure he'll chime in here... I won't see it, but I doubt he'll be able to
resist... there *used* to be private groups where MVPs could get to know
each other. His basketball sized mouth (along with others), attached to a
keyboard, forced MS to close those groups down...
I would agree with that - it would be nice if some of those samples had
.net
versions.


Again, I can't disagree.


What things are you specifically refering to? What problems? What do YOU
consider bloat?

Just start up the IDE and sit there with a stop watch... besides the bloat,
the problems/bugs are throughout. Just take a peek at the questions here!

EWC is one area where dotNet falls short (an understatement)... btw, EWC is
Edit/Wait (and wait and wait) and Continue, vs the true E&C we have in VB6.
"B#'s" top competitor is now where near VB6. It's top competitor are OSS
languages, such as php, python, ruby, and the mother of them all Java.
AFICT,
VB6 isn't even on the radar.

See? Even you agree that dotNet's a "web based" technology.... and, if I
were to write a web app (or an app for windows mobile), dotNet's the first
thing I'd grab. For desktops and for controlling the machines we build, VB6
rules.... surely, people can't still be whining about DLL Hell. Anyone with
experience should know how to prevent that easily enough.
 
C

Cor Ligthert[MVP]

Tom,

IMHO this text schould seen correct for the problem in this message thread.
Short path names are only still used related to things as UNIX, MS-DOS and
more of these OS's from the previous millenium.

It has not my first preference to set this in a .Net sample. It is not even
anymore in the Path class.

In fact this fits perfectly to a VB6 sample as that is as well from the
previus millenium.

Cor
 
C

Cor Ligthert [MVP]

Tom,

Do you think it is wise to ring on the bell on another place for this?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top