Solved

Getting my executable name

Posted on 2004-08-25
14
358 Views
Last Modified: 2010-05-18
I used to do VB6.GetEXEName() but .NET says I shouldn't use a reference to VB6. Any ideas how to get it? I tried this:

Dim exe As String = System.Reflection.Assembly.GetExecutingAssembly.GetName

But got:

D:\Class1.vb(18): Value of type 'System.Reflection.AssemblyName' cannot be converted to 'String'.
0
Comment
Question by:drakkarnoir
  • 5
  • 4
  • 3
  • +2
14 Comments
 
LVL 3

Accepted Solution

by:
DJ_Back-Q earned 500 total points
ID: 11894803
Just you this.

Application.ExecutablePath

If you don't want the path, just use the string.substring to get your executable name.


You can also use Application.ProductName(), but you will first need to enter the product name into the AssemblyInfo.vb

Andre,
MCSD
0
 
LVL 7

Expert Comment

by:natloz
ID: 11894830
Maybe try

SystemReflection.Assembly.GetExecutingAssembly.GetName.toString()
0
 

Author Comment

by:drakkarnoir
ID: 11894892
Argh, I wanted to edit my question to also include:

How do I see if a value exists in array? Is there a bool return function or key return? So that I can do:

If CBOOL(inarray("test",my_array)) Then
MsgBox("Found it!")
End If
0
 
LVL 3

Expert Comment

by:DJ_Back-Q
ID: 11894947
I don't think there is such a thing in dot not for a normal array.

You should consider replacing your array by and ArrayList. The arraylist is much more efficient. It's collection based, and has a binary search with which you could locate you value.
0
 

Author Comment

by:drakkarnoir
ID: 11895123
Example code?
0
 
LVL 3

Expert Comment

by:imu79
ID: 11895506
You should use a hashtable for lookups or searches.

Dim ohash as new Hashtable

with ohash
  .add("item1", "item1")
  .add("item2", "item3")
  .add("item3", "item3")
end with

if ohash.Contains("item1") then
  MessageBox.Show("Found !")
end if

Imran.
0
 
LVL 3

Assisted Solution

by:DJ_Back-Q
DJ_Back-Q earned 500 total points
ID: 11895720
       Dim myArray As New System.Collections.ArrayList

        myArray.Add("item1")
        myArray.Add("item2")
        myArray.Add("item3")

        myArray.Sort()

        If myArray.BinarySearch("item1") >= 0 Then
            MessageBox.Show("Fount it")
        End If

' BinarySearch returns the index of the occurence... so if it's less then 0, it hasn't find it. Also, because it's a BinarySearch, you must sort the list first. If not it will not work properly.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:imu79
ID: 11896569
just for the record..
hashtables are much faster since it uses..well..hash tables for storing data. since a unique hashcode (for all practical purposes) is generate from the key for each item stored in the hashtable, searching for an element (the key) is very fast especially if the data structure is going to store a lot of elements.

while the worst case search time for a binary search is O(nLog(n)) that of a search operation in hashtable is O(n) where n is the number of elements in the data structure. In fact, for most practical purposes since the hashcode will be unique for each element in the hashtable, the search time is O(1) which is very fast compared to binary search.

Imran.
0
 
LVL 3

Expert Comment

by:imu79
ID: 11896581
Oh and yes - you don't even need to sort the elements in the hashtable to do a fast search unlike the binarysearch in an arraylist or any other data structure.

Imran.
0
 
LVL 3

Expert Comment

by:DJ_Back-Q
ID: 11896622
imy79 that is true until one point. The bigger the hash table gets, the less efficient it is. There is a point after X number of items that the ArrayList will become faster and more efficient.

Andre
0
 
LVL 3

Expert Comment

by:DJ_Back-Q
ID: 11896636
Forgot to mention, actually whats behing the ArrayList is a hash table.
0
 
LVL 3

Expert Comment

by:imu79
ID: 11896905
No - I believe its the opposite.

look at the bottom where speed of binary search is mentioned:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemCollectionsArrayListClassBinarySearchTopic3.asp

look at the remarks section here for speed of search for the Contains( ) method:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionshashtableclasscontainstopic.asp

The larger the number of elements, the higher the value of log(n) gets in which case O(log(n)) means its going to take longer to search for the binary search. On the other hand, the hashtable has an almost constant time for retrieving an element irrespective of the number of elements since it has a running time of O(1).

Imran.
0
 

Expert Comment

by:Spanxxx
ID: 11897936
Barring you are referring to your array as a whole and not just an item in the array, here is the easy .Net way to check.

If array.length > 0 then
 'array is not empty
Else
 'array is empty
End If


and repeating the first comment, with a little more info
dim exeName as string
exeName = Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf("\") + 1)
0
 

Author Comment

by:drakkarnoir
ID: 11906225
Thanks to all :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now